/// <summary>
        /// Creates the configuration to be used by the ResourceStaticAnalysis.
        /// </summary>
        /// <returns>EngineConfig.</returns>
        protected override EngineConfig CreateEngineConfig(IEnumerable <RuleContainer> ruleContainers)
        {
            EngineConfig configuration = new EngineConfig();

            //DataSourceProviderTypes
            configuration.AddDataSourceProvider(typeof(ResourceFileDataSource));
            configuration.AddDataSourceProvider <ConfigDictionaryDataSource>();

            //PropertyAdapterTypes
            configuration.AddPropertyAdapter(typeof(ResourceFileEntryPropertyAdapter));
            configuration.AddPropertyAdapter <ConfigDictPropertyAdapter>();
            configuration.AddPropertyAdapter <LocResourceSelfPropertyAdapter>();

            //COAdatpers
            configuration.AddCOAdapter(typeof(ResourceFileDataAdapter));

            //COTypes
            configuration.AddClassificationObject <LocResource>();

            // Create a package
            var package = new DataSourcePackage();

            // Set the type of CO that the package provides
            package.SetCOType <LocResource>();
            // Create a data source to be part of the package
            var dataSource = new DataSourceInfo();

            // Set the type of data source
            dataSource.SetSourceType(typeof(ResourceFile));
            // Add data source to the package
            package.AddDataSource(dataSource);
            // Create another data source
            dataSource = new DataSourceInfo();
            // Set type to be a ConfigDictionary - some custom object
            dataSource.SetSourceType <ConfigDictionary>();
            // Create an instance of the ConfigDictionary object
            var staticProperties = new ConfigDictionary
            {
                { "Project", projectName }
            };

            // Set the location. in this case the loaction is the object itself
            dataSource.SetSourceLocation(staticProperties);
            // Add data source to package
            package.AddDataSource(dataSource);
            // Add the package to the configuration
            configuration.AddDataSourcePackage(package);

            // Add the rules
            if (ruleContainers != null)
            {
                ruleContainers.ToList().ForEach(r => configuration.AddRule(r));
            }

            return(configuration);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        /// <summary>
        /// Builds OSLEBot configuration based on file list and Cerberus check configuration.
        /// </summary>
        /// <param name="fileList">List of files to be converted into OSLEBot data sources.</param>
        /// <param name="checkConfigs">List of checks that will be executed against the data sources.</param>
        /// <param name="cerberusOutputPath">Full path to Cerberus output XML file.</param>
        /// <returns>Configuration data that can be passed into OSLEBot for execution.</returns>
        internal static EngineConfig CreateConfig(IEnumerable <InputFileItem> fileList, IEnumerable <CheckConfig> checkConfigs, string cerberusOutputPath, string oslebotEngineLogPath)
        {
            var configuration = new EngineConfig {
                EngineLog = oslebotEngineLogPath
            };


            #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
            foreach (var file in fileList)
            {
                var package = new DataSourcePackage(); //This package will contain 2 data sources
                package.SetCOType <LocResource>();
                var dataSource = new DataSourceInfo();
                dataSource.SetSourceType <LocDocument>();
                dataSource.SetSourceLocation(file.File);
                package.AddDataSource(dataSource);

                dataSource = new DataSourceInfo();
                dataSource.SetSourceType <ConfigDictionary>();

                var staticProperties = new ConfigDictionary
                {
                    { "BuildNumber", file.BuildNumber },
                    { "Project", file.Project },
                    { "Locgroup", file.LocGroup }
                };
                dataSource.SetSourceLocation(staticProperties);
                package.AddDataSource(dataSource);
                configuration.AddDataSourcePackage(package);
            }
            #endregion

            #region Add checks
            // only add checks that are not globally disabled (could never execute)
            foreach (var check in checkConfigs.Where(ch => !ch.IsGloballyDisabled))
            {
                configuration.AddRule(check.PhysicalFile, check.GetOSLEBotFilteringExpression(), check.ContainerType);
            }
            #region And some configuration for dynamic compiler
            var executingAssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            // figure out the directory where LocStudio libs are located
            var locstudioLibsPath = Path.GetDirectoryName(typeof(LocDocument).Assembly.Location);
            // figure out the directory where OSLEBot libs are located
            var oslebotLibsPath = Path.GetDirectoryName(typeof(OSLEBotEngine).Assembly.Location);
            configuration.AddBinaryReference("System.Core.dll");
            configuration.AddBinaryReference("mscorlib.dll");
            configuration.AddBinaryReference("System.dll");
            configuration.AddBinaryReference("System.Xml.dll");
            configuration.AddBinaryReference("System.Xml.Linq.dll");
            configuration.AddBinaryReference(Path.Combine(locstudioLibsPath, "Microsoft.Localization.dll"));
            configuration.AddBinaryReference(Path.Combine(oslebotLibsPath, "OSLEBotCore.dll"));
            configuration.AddBinaryReference(Path.Combine(oslebotLibsPath, "LocResource.dll"));
            configuration.AddBinaryReference(Path.Combine(oslebotLibsPath, "OSLEBot.LCXDataAdapter.dll"));
            configuration.AddBinaryReference(Path.Combine(executingAssemblyPath, "Cerberus.Core.dll"));

            #endregion

            #endregion

            #region Configure output behavior
            // define all properties here to be consistent for all output writers
            string[] propertiesToInclude =
            {
                "LSResID",
                "SourceString",
                "TargetString",
                "Comments",
                "TargetCulture",
                "Locgroup",
                "Project",
                "LcxFileName"
            };
            Microsoft.Localization.OSLEBot.Core.Output.OutputWriterConfig outputCfg;
            // set up output writer that creates one merged output for all files
            outputCfg = new OSLEBot.Core.Output.OutputWriterConfig();
            outputCfg.SetDataSourceProvider <Microsoft.Localization.OSLEBot.Core.Output.Specialized.XMLDOMOutputWriter>();
            outputCfg.Schema = "OSLEBotOutput.xsd";
            outputCfg.Path   = cerberusOutputPath;
            Array.ForEach(propertiesToInclude, outputCfg.AddPropertyToIncludeInOutput);
            configuration.OutputConfigs.Add(outputCfg);
            // set up output writer that creates one output file per LCX processed.
            outputCfg = new OSLEBot.Core.Output.OutputWriterConfig();
            outputCfg.SetDataSourceProvider <LocResourcePerLCLOutputWriter>();
            outputCfg.Schema = "OSLEBotOutput.xsd";
            outputCfg.Path   = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            Array.ForEach(propertiesToInclude, outputCfg.AddPropertyToIncludeInOutput);
            configuration.OutputConfigs.Add(outputCfg);
            #endregion

            #region Because we don't store LSBuild enviornment, point compiler to that of Office14 source depot
            configuration.AddAssemblyResolverPaths(locstudioLibsPath);
            #endregion

            return(configuration);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        /// <summary>
        /// Creates a sample Engine configuration
        /// </summary>
        /// <param name="testContext">VS Test Context</param>
        /// <param name="testRuleFileName">Rule to be used (.dll or .cs)</param>
        /// <param name="numberOfResources">Number of Resources to generate (in increments of 6)</param>
        /// <returns></returns>
        internal static EngineConfig CreateSampleConfig(TestContext testContext, string testRuleFileName, int numberOfResources)
        {
            testRuleFileName = Path.Combine(testContext.DeploymentDirectory, testRuleFileName);

            var configuration = new EngineConfig();

            #region DataSourceProviderTypes
            configuration.AddDataSourceProvider(typeof(SampleDataSource));
            #endregion

            #region PropertyAdapterTypes
            configuration.AddPropertyAdapter <SamplePropertyAdapter>();
            configuration.AddPropertyAdapter <SampleClassificationObjectSelfPropertyAdapter>();
            #endregion

            #region COAdatpers
            configuration.AddCOAdapter(typeof(SampleDataAdapter));
            #endregion

            #region COTypes
            configuration.AddClassificationObject <SampleClassificationObjectType>();
            #endregion

            #region DataSourcePackages
            var package = new DataSourcePackage(); // This package will contain 2 data sources
            package.SetCOType <SampleClassificationObjectType>();

            var dataSource = new DataSourceInfo();
            dataSource.SetSourceType <SampleResourceCollection>();

            List <Tuple <string, string, string> > sampleResources = GenerateLargeNumberOfResources(numberOfResources);
            dataSource.SetSourceLocation(sampleResources);
            package.AddDataSource(dataSource);

            configuration.AddDataSourcePackage(package);
            #endregion

            #region Add rules
            RuleContainerType rct = new RuleContainerType();
            if (testRuleFileName.EndsWith(".cs"))
            {
                rct = RuleContainerType.Source;
            }
            else
            {
                rct = RuleContainerType.Module;
            }

            configuration.AddRule(new RuleContainer(testRuleFileName, rct));
            #endregion

            #region And some configuration for dynamic compiler
            configuration.AddBinaryReference("System.Core.dll");
            configuration.AddBinaryReference("mscorlib.dll");
            configuration.AddBinaryReference("System.dll");
            configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.Core.dll");
            configuration.AddBinaryReference("UnitTests.dll");
            #endregion

            #region Configure output behavior
            var outputCfg = new OutputWriterConfig();
            outputCfg.SetDataSourceProvider <XMLDOMOutputWriter>();
            outputCfg.Schema = "ResourceStaticAnalysisOutput.xsd";
            outputCfg.Path   = testContext.TestRunDirectory;
            outputCfg.AddPropertyToIncludeInOutput("ResourceId");
            outputCfg.AddPropertyToIncludeInOutput("SourceString");
            outputCfg.AddPropertyToIncludeInOutput("Comments");
            configuration.OutputConfigs.Add(outputCfg);
            #endregion

            return(configuration);
        }
Exemple #6
0
        /// <summary>
        /// Creates an engine configuration with two Data Sources.
        /// </summary>
        /// <param name="testContext">Used to store information that is provided to unit tests.</param>
        /// <param name="testRuleFileName">Name of the C# file that contains the Rule implementaiton.</param>
        /// <param name="testResourceFile">Resource File used to run the engine.</param>
        /// <returns>The configuration of the engine with two DataSources.</returns>
        internal static EngineConfig CreateSampleConfigWithTwoDataSources(TestContext testContext,
                                                                          string testRuleFileName, string testResourceFile)
        {
            testRuleFileName = Path.Combine(testContext.DeploymentDirectory, testRuleFileName);
            testResourceFile = Path.Combine(testContext.DeploymentDirectory, testResourceFile);
            var configuration = new EngineConfig();

            #region DataSourceProviderTypes

            configuration.AddDataSourceProvider <ResourceFileDataSource>();
            configuration.AddDataSourceProvider <ConfigDictionaryDataSource>();

            #endregion

            #region PropertyAdapterTypes

            configuration.AddPropertyAdapter <ResourceFileEntryPropertyAdapter>();
            configuration.AddPropertyAdapter <ConfigDictPropertyAdapter>();
            configuration.AddPropertyAdapter <LocResourceSelfPropertyAdapter>();

            #endregion

            #region COAdatpers

            configuration.AddCOAdapter <ResourceFileDataAdapter>();

            #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(typeof(ResourceFile));
            dataSource.SetSourceLocation(Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                                      testResourceFile));
            package.AddDataSource(dataSource);

            dataSource = new DataSourceInfo();
            dataSource.SetSourceType <ConfigDictionary>();
            var configDictionary = new ConfigDictionary
            {
                { "Project", "test RSA" },
            };
            dataSource.SetSourceLocation(configDictionary);
            package.AddDataSource(dataSource);

            configuration.AddDataSourcePackage(package);

            #endregion

            #region Add rules

            RuleContainerType rct = new RuleContainerType();
            if (testRuleFileName.EndsWith(".cs"))
            {
                rct = RuleContainerType.Source;
            }
            else
            {
                rct = RuleContainerType.Module;
            }

            configuration.AddRule(new RuleContainer(testRuleFileName, rct));

            #endregion

            #region And some configuration for dynamic compiler

            configuration.AddBinaryReference("System.Core.dll");
            configuration.AddBinaryReference("mscorlib.dll");
            configuration.AddBinaryReference("System.dll");
            configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.Core.dll");
            configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.LocResource.dll");
            configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.DataAdapter.dll");

            #endregion

            return(configuration);
        }