Skip to content

2. NuGet Support

Guy Acosta edited this page Jul 16, 2020 · 1 revision

In additional to releases on GitHub, Application Inspector is available through nuget.org, both as a library and a stand-alone command-line tool.

Available NuGet Packages

Installing and using the command line tool

  • dotnet tool install Microsoft.CST.ApplicationInspector.CLI or
  • dotnet tool install --global Microsoft.CST.ApplicationInspector.CLI (as global tool for use from any directory)

Then simply run the tool normally from a command prompt. See the README.md for more information.

Installing and using the Application Inspector library

  • Add the Microsoft.CST.ApplicationInspector.Commands package to your project as described above
  • Add the reference e.g. using Microsoft.ApplicationInspector.Commands;
  • Start using the available commands as shown below.

Analyze Command

try
{
    AnalyzeCommand command = new AnalyzeCommand(new AnalyzeOptions()
    {
         SourcePath = "/home/user/myproject"
    });
    AnalyzeResult result = command.GetResult();
    if (result.ResultCode == AnalyzeResult.ExitCode.Success)
    {
         //access result properties in result.Metadata e.g.
         foreach (string tag in result.Metadata.UniqueTags)
         {
              Console.WriteLine(tag);
         }

         foreach (MatchRecord matchRecord in result.Metadata.Matches)
         {
              Console.WriteLine($"File: {matchRecord.FileName}");
              Console.WriteLine($"Rule: {matchRecord.RuleName}");
              Console.WriteLine($"Matched Text: {matchRecord.Sample}");
              Console.WriteLine($"Confidence{matchRecord.Confidence}");           
         }
    }
}
catch (Exception e)
{

}

Tag Diff Command

try
{
    TagDiffCommand command = new TagDiffCommand(new TagDiffOptions()
    {
        SourcePath1 = "/home/user/myproject/v1",
        SourcePath2 = "/home/user/myproject/v2"
    });

    TagDiffResult result = command.GetResult();
    if (result.ResultCode == TagDiffResult.ExitCode.TestFailed)
    {
        foreach (TagDiff diff in result.TagDiffList)
        {
            Console.WriteLine(string.Format("tagname: {0}, only found in: {1}", diff.Tag, diff.Source));
        }
    }
}
catch (Exception e)
{
    //log error
}

Tag Test Command

try
{
    TagTestCommand command = new TagTestCommand(new TagTestOptions()
    {
        SourcePath = "/home/user/myproject/v1",
        CustomRulesPath = "/home/user/myrules/myrule.json"
    });

    TagTestResult result = command.GetResult();
    if (result.ResultCode == TagTestResult.ExitCode.TestFailed)
    {
        foreach (TagStatus tagStatus in result.TagsStatusList)
        {
            if (!tagStatus.Detected)
                Console.WriteLine(string.Format("Rule tag: {0} not detected", tagStatus.Tag));
        }
    }
}
catch (Exception e)
{
    //log error
}

Export Tags Command

try
{
    ExportTagsCommand command = new ExportTagsCommand(new ExportTagsOptions());
    ExportTagsResult result = command.GetResult();
    if (result.ResultCode == ExportTagsResult.ExitCode.Success)
    {
        foreach (string tag in result.TagsList)
        {
            Console.WriteLine(tag);
        }
    }
}
catch (Exception)
{
    //check for specific error if desired
}

Verify Rules Command

try
{
    VerifyRulesCommand command = new VerifyRulesCommand(new VerifyRulesOptions()
    {
        CustomRulesPath = "/home/user/myrules/myrule.json"
    });

    VerifyRulesResult result = command.GetResult();
    foreach (RuleStatus ruleStatus in result.RuleStatusList)
    {
        if (!ruleStatus.Verified)
            Console.WriteLine(string.Format("Rule {0} [1} not verfied", ruleStatus.RulesId, ruleStatus.RulesName));
    }
}
catch (Exception e)
{
    //log error
}

Pack Rules Command

The Pack Rules command requires a file for packing result and is only available via the CLI application.

Miscellaneous

Additional options exists for each command option type. See README.md for more information.