Exemple #1
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 #2
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);
        }