I'm building a tool based upon the Project Automation Tool which is installed with the SDK, and I have a problem with saving the analysis report.
As with the Project Automation Tool, this is a 3-step process:
- determine the analysis settings for the project
- run the analysis and obtain an ID for the report
- request that the project save the report (using the ID from step 2) to a specified path and in a specified format.
If I create a project based upon a template, all three steps run as expected and I obtain the analysis report as expected.
If I create a project without a template and manually assign a TM and/or termbase, the first two steps run as expected - I obtain an ID and I can see properties of the analysis such as Name and Description. However, when in step 3 I then call
project.SaveTaskReportAs(reportId, path, ReportFormat.Xml);
an exception is thrown, telling me that the report doesn't exist: "System.ArgumentException: Could not find report with ID [project-specific GUID]'
Here is the code I'm using (with logging elided):
For step 1...
private void FormulateAnalysisSettings(IProject project, Language targetLanguage)
{
ISettingsBundle settings = project.GetSettings(targetLanguage);
AnalysisTaskSettings analyzeSettings = settings.GetSettingsGroup<AnalysisTaskSettings>();
analyzeSettings.ReportCrossFileRepetitions.Value = true;
analyzeSettings.ReportInternalFuzzyMatchLeverage.Value = true;
project.UpdateSettings(targetLanguage, settings);
}
For step 2...
private Guid RunFileAnalysis(IProject project, Language targetLanguage)
{
try
{
ProjectFile[] targetFiles = project.GetTargetLanguageFiles(targetLanguage);
AutomaticTask analyzeTask = project.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.AnalyzeFiles);
return analyzeTask.Reports[0].Id;
}
catch (Exception exception)
{
throw new Exception("Failed to analyze the files.", exception);
}
}
For step 3...
private AnalysisStatistics CreateReports(Guid reportId, IProject project, string path)
{
try
{
project.SaveTaskReportAs(reportId, path + "AnalyzeTaskReport.xml", ReportFormat.Xml); // EXCEPTION THROWN HERE
ProjectStatistics projectStats = project.GetProjectStatistics();
TargetLanguageStatistics[] targetStats = projectStats.TargetLanguageStatistics;
return targetStats[0].AnalysisStatistics;
}
catch (Exception exception)
{
Log.Error("An exception occurred while reporting the results of the analysis: ", exception);
}
return null;
}