/// <summary> /// Builds OSLEBot configuration based on input data /// </summary> /// <param name="candidateFiles">Physical files to filter for checks. For global checks, all candidate files will be processed.</param> /// <param name="checkPaths">List of paths to C# files containing source code of checks to be compiled.</param> /// <param name="language">Language to filter the input file set on.</param> /// <param name="project">Project to filter the input file set on.</param> /// <returns>Configuration for OSLEBot that can be simply passed into OSLEBotEngine.Execute().</returns> internal EngineConfig CreateAsimoConfig(IEnumerable <ConfigItem> candidateFiles, IEnumerable <string> checkPaths, string language, string project) { //Currently only process global checks (should be 1 for proof of concept). var configuration = new EngineConfig { EngineLog = "Asimo log for Cerberus.txt" }; #region DataSourceProviderTypes configuration.AddDataSourceProvider <LcxDataSource>(); configuration.AddDataSourceProvider <ConfigDictionaryDataSource>(); #endregion #region PropertyAdapterTypes configuration.AddPropertyAdapter <LocItemPropertyAdapter>(); configuration.AddPropertyAdapter <ConfigDictPropertyAdapter>(); configuration.AddPropertyAdapter <LocResourceSelfPropertyAdapter>(); //Although we don't use it explicitly, LCXLocResourceDataAdapter.LoadObjects() will crash when starting OSLEBot because it expects this property adapter to be available.??? #endregion #region COAdatpers configuration.AddCOAdapter <LCXLocResourceDataAdapter>(); #endregion #region COTypes configuration.AddClassificationObject <LocResource>(); #endregion #region DataSourcePackages var inputForGlobalChecks = from file in candidateFiles where file.Language.Equals(language) where file.Project.Equals(project) select file; foreach (var file in inputForGlobalChecks) { var package = new DataSourcePackage(); //This package will contain 2 data sources package.SetCOType <LocResource>(); var dataSource = new DataSourceInfo(); dataSource.SetSourceType <LocDocument>(); dataSource.SetSourceLocation(file.PhysicalPath); package.AddDataSource(dataSource); dataSource = new DataSourceInfo(); dataSource.SetSourceType <ConfigDictionary>(); var staticProperties = new ConfigDictionary { { "BuildNumber", "1" }, { "Project", file.Project }, { "Locgroup", file.LocGroup } }; dataSource.SetSourceLocation(staticProperties); package.AddDataSource(dataSource); configuration.AddDataSourcePackage(package); } #endregion #region Add a sample rule foreach (var check in checkPaths) //For test should be 1. { configuration.AddRule(check, string.Empty, RuleContainerType.Source); } #region And some configuration for dynamic compiler configuration.AddBinaryReference("System.Core.dll"); configuration.AddBinaryReference("mscorlib.dll"); configuration.AddBinaryReference("System.dll"); configuration.AddBinaryReference("Microsoft.Localization.dll"); configuration.AddBinaryReference("OSLEBotCore.dll"); configuration.AddBinaryReference("LocResource.dll"); configuration.AddBinaryReference("OSLEBot.LCXDataAdapter.dll"); #endregion #endregion #region Configure output behavior var outputCfg = new OSLEBot.Core.Output.OutputWriterConfig(); outputCfg.SetDataSourceProvider <LocResourcePerLCLOutputWriter>(); outputCfg.Schema = "OSLEBotOutput.xsd"; outputCfg.Path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); outputCfg.AddPropertyToIncludeInOutput("LSResID"); outputCfg.AddPropertyToIncludeInOutput("SourceString"); outputCfg.AddPropertyToIncludeInOutput("TargetString"); outputCfg.AddPropertyToIncludeInOutput("Comments"); outputCfg.AddPropertyToIncludeInOutput("TargetCulture"); outputCfg.AddPropertyToIncludeInOutput("Locgroup"); outputCfg.AddPropertyToIncludeInOutput("Project"); configuration.OutputConfigs.Add(outputCfg); #endregion #region Because we don't store LSBuild enviornment, point compiler to that of Office14 source depot configuration.AddAssemblyResolverPaths(Enlistment.LSBuildToolsPath); #endregion return(configuration); }
internal static EngineConfig CreateTestConfig(TestContext testContext, string testDataFile, params string[] testRuleFileNames) { var configuration = new EngineConfig { EngineLog = string.Format("Engine log for {0}.txt", testContext.TestName) }; #region DataSourceProviderTypes configuration.AddDataSourceProvider <LcxDataSource>(); configuration.AddDataSourceProvider <ConfigDictionaryDataSource>(); #endregion #region PropertyAdapterTypes configuration.AddPropertyAdapter <LocItemPropertyAdapter>(); configuration.AddPropertyAdapter <ConfigDictPropertyAdapter>(); configuration.AddPropertyAdapter <LocResourceSelfPropertyAdapter>(); //Although we don't use it explicitly, LCXLocResourceDataAdapter.LoadObjects() will crash when starting OSLEBot because it expects this property adapter to be available.??? #endregion #region COAdatpers configuration.AddCOAdapter <LCXLocResourceDataAdapter>(); #endregion #region COTypes configuration.AddClassificationObject <LocResource>(); #endregion #region DataSourcePackages var package = new DataSourcePackage(); //This package will contain 2 data sources package.SetCOType <LocResource>(); var dataSource = new DataSourceInfo(); dataSource.SetSourceType <LocDocument>(); dataSource.SetSourceLocation(testDataFile); package.AddDataSource(dataSource); dataSource = new DataSourceInfo(); dataSource.SetSourceType <ConfigDictionary>(); var configDictionary = new ConfigDictionary { { "BuildNumber", "1" }, { "Project", "test Romka" }, { "Locgroup", "MacBU" } }; dataSource.SetSourceLocation(configDictionary); package.AddDataSource(dataSource); configuration.AddDataSourcePackage(package); #endregion #region Add rules to be tested foreach (var ruleFileName in testRuleFileNames) { configuration.AddRule( ruleFileName, string.Empty, Path.GetExtension(ruleFileName).Equals(".cs", StringComparison.OrdinalIgnoreCase) ? RuleContainerType.Source : RuleContainerType.Module); } #endregion #region And some configuration for dynamic compiler configuration.AddBinaryReference("System.Core.dll"); configuration.AddBinaryReference("mscorlib.dll"); configuration.AddBinaryReference("System.dll"); configuration.AddBinaryReference("Microsoft.Localization.dll"); configuration.AddBinaryReference("OSLEBotCore.dll"); configuration.AddBinaryReference("LocResource.dll"); configuration.AddBinaryReference("OSLEBot.LCXDataAdapter.dll"); configuration.AddBinaryReference("Logger.dll"); configuration.AddBinaryReference("Cerberus.Core.dll"); configuration.AddBinaryReference("System.Xml.dll"); configuration.AddBinaryReference("System.Xml.Linq.dll"); #endregion #region Configure output behavior var outputCfg = new OSLEBot.Core.Output.OutputWriterConfig(); outputCfg.SetDataSourceProvider <LocResourcePerLCLOutputWriter>(); outputCfg.Schema = "OSLEBotOutput.xsd"; outputCfg.Path = testContext.TestDeploymentDir; outputCfg.AddPropertyToIncludeInOutput("LSResID"); outputCfg.AddPropertyToIncludeInOutput("SourceString"); outputCfg.AddPropertyToIncludeInOutput("Comments"); outputCfg.AddPropertyToIncludeInOutput("TargetString"); outputCfg.AddPropertyToIncludeInOutput("TargetCulture"); outputCfg.AddPropertyToIncludeInOutput("Locgroup"); outputCfg.AddPropertyToIncludeInOutput("Project"); configuration.OutputConfigs.Add(outputCfg); #endregion return(configuration); }