Ejemplo n.º 1
0
        /// <summary>
        /// Load co objects.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="maxOutputPerObject"></param>
        /// <returns></returns>
        private ICollection <ClassificationObject> LoadClassificationObjects(DataSourcePackage package, int maxOutputPerObject)
        {
            Type coType;
            IList <ClassificationObjectAdapter> adaptersList;

            if (!_coTypes.TryGetValue(package.ClassificationObjectTypeName, out coType))
            {
                throw new ResourceStaticAnalysisException(String.Format(CultureInfo.CurrentCulture, "Unknown Classification Object type {0}. Make sure CO types are properly registered with engine.",
                                                                        package.ClassificationObjectTypeName
                                                                        ));
            }
            if (!this._coAdapters.TryGetValue(coType, out adaptersList))
            {
                throw new ResourceStaticAnalysisException(String.Format(CultureInfo.CurrentCulture, "No adapters registered for Classification Object type {0}.",
                                                                        package.ClassificationObjectTypeName
                                                                        ));
            }

            foreach (var coAdapter in adaptersList)
            {
                if (coAdapter.PackageIsSupported(package))
                {
                    return(coAdapter.InitializeObjects(package) ?? new ClassificationObject[0]);
                }
            }

            throw new ResourceStaticAnalysisException(String.Format(CultureInfo.CurrentCulture, "No adapters registered for Classification Object type {0} that support the current data source package:\n"
                                                                    + "Primary data source: {1}, secondary data sources: {2}",
                                                                    package.ClassificationObjectTypeName,
                                                                    package.PrimaryDataSource.SourceInstanceType.FullName,
                                                                    String.Join(",", package.SecondaryDataSources.Select(ds => ds.SourceInstanceType.FullName).ToArray())
                                                                    ));
        }
Ejemplo n.º 2
0
        public void TestDataSourcePackageToStringMethod()
        {
            try
            {
                var dsp  = new DataSourcePackage();
                var info = new DataSourceInfo();
                info.SetSourceLocation("TestPath");
                info.SetSourceType <MatchCollection>(); // Should be possible to specify an arbitrary type.
                dsp.AddDataSource(info);

                info = new DataSourceInfo();
                var dictionary = new ConfigDictionary {
                    { "Key 1", "Value 1" }, { "Key 2", "Value 2" }
                };

                info.SetSourceLocation(dictionary);
                info.SetSourceType <ResourceFileDataSource>();
                dsp.AddDataSource(info);

                TestContext.WriteLine(dsp.ToString());
            }
            catch (Exception ex)
            {
                Assert.Fail("Method Failed:{0}", ex.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks that CO type, Primary Data Source Type and Secondary Data Source types match between the DataSourcePackage
        /// and the DataAdapter. Throws exceptions if one of the types doesn't match. Returns true if everythings fine.
        /// </summary>
        protected bool ValidateTypes(DataSourcePackage package)
        {
            if (!package.ClassificationObjectTypeName.Equals(this.ClassificationObjectType.FullName))
            {
                throw new ResourceStaticAnalysisException(String.Format(CultureInfo.CurrentCulture,
                                                                        "DataSource Package CO type {0} does not match DataAdapter CO type {1}",
                                                                        package.ClassificationObjectTypeName,
                                                                        this.ClassificationObjectType.FullName
                                                                        ));
            }
            if (!this.PrimaryDataSource.IsAssignableFrom(package.PrimaryDataSource.SourceInstanceType))
            {
                throw new ResourceStaticAnalysisException(String.Format(CultureInfo.CurrentCulture,
                                                                        "DataSource Package primary data source type {0} does not match DataAdapter primary data source type {1}",
                                                                        package.PrimaryDataSource,
                                                                        this.PrimaryDataSource
                                                                        ));
            }
            if (package.SecondaryDataSources.Any())
            {
                if (!(package.SecondaryDataSources.Count() == this.SecondaryDataSources.Count() &&
                      this.SecondaryDataSources.All(ds => ds.IsAssignableFrom(package.SecondaryDataSources.ElementAt(this.SecondaryDataSources.IndexOf(ds)).SourceInstanceType))))
                {
                    throw new ResourceStaticAnalysisException(String.Format(CultureInfo.CurrentCulture,
                                                                            "DataSource Package secondary data source types {0} do not match DataAdapter secondary data source types {1}",
                                                                            String.Join(",", package.SecondaryDataSources.Select(ds => ds.SourceInstanceType.FullName).ToArray()),
                                                                            String.Join(",", this.SecondaryDataSources.Select(ds => ds.FullName).ToArray())
                                                                            ));
                }
            }

            return(true);
        }
 /// <summary>
 /// Adds new data package definition to <see cref="DataSourcePkgs"/> list.
 /// <param name="newPackage">New package of data to be added</param>
 /// </summary>
 public void AddDataSourcePackage(DataSourcePackage newPackage)
 {
     if (DataSourcePkgs == null)
     {
         DataSourcePkgs = new List <DataSourcePackage>();
     }
     DataSourcePkgs.Add(newPackage);
 }
        /// <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);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Checks if the adapter can initialize classification objects from the provided data source package.
 /// </summary>
 public bool PackageIsSupported(DataSourcePackage package)
 {
     try
     {
         ValidateTypes(package);
     }
     catch (Exception e)
     {
         Trace.TraceWarning("PackageIsSupported(): {0}", e.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 7
0
        public override ICollection <ClassificationObject> InitializeObjects(DataSourcePackage dsp)
        {
            if (dsp.SecondaryDataSources.FirstOrDefault() == null)
            {
                // There is only a Primary DataSource. Create an empty ConfigDictionary as second Data Source.
                return(this.LoadObjects((ResourceFile)dsp.PrimaryDataSource.SourceInstance, null));
            }

            // Load objects using ResourceFile as primary source and Config dictionary as secondary source.
            return(this.LoadObjects(
                       (ResourceFile)dsp.PrimaryDataSource.SourceInstance,
                       (ConfigDictionary)dsp.SecondaryDataSources.FirstOrDefault().SourceInstance
                       ));
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public override ICollection <ClassificationObject> InitializeObjects(DataSourcePackage dsp)
 {
     // Load objects using SampleResourceCollection as primary source
     return(this.LoadObjects(
                (SampleResourceCollection)dsp.PrimaryDataSource.SourceInstance));
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes Classification Objects based on the content of the data source package
 /// </summary>
 /// <param name="dsp">Data source package to use</param>
 /// <returns></returns>
 public abstract ICollection <ClassificationObject> InitializeObjects(DataSourcePackage dsp);