Esempio n. 1
0
        private void LoadDataFromDatabase(string dataFilePath)
        {
            var fileInfo = new FileInfo(dataFilePath);

            if (fileInfo.Exists)
            {
                //SetStatusBarItem(1, Properties.Resources.LoadingDataInDataInProgress);
                SetStatusBarItem(1, "Loading data from Configuration.xml");
                ConfiguratorApplication.Current.Database.ReadXml(dataFilePath);
                //SetStatusBarItem(1, Properties.Resources.LoadedData);
                SetStatusBarItem(1, "Loaded data from Configuration.xml");
            }
            else
            {
                //SetStatusBarItem(0, Properties.Resources.DataFileDoesNotExist);
                SetStatusBarItem(0, "Configuration data file cannot be located.");
                LoggerSAP.Error("Location of configuration data file is invalid: {0}", fileInfo.FullName);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Runs Asimo (a.k.a. OSLEBot) on the specified input files.
        /// </summary>
        /// <param name="fileSet">Set of files to run Asimo on.</param>
        /// <param name="languageFilter">Collection of languages to filter enlistment by. If empty, no filtering is applied.</param>
        /// <param name="projectFilter">Collection of projects to filter enlistment by. If empty, no filtering is applied.</param>
        public override void Run(IEnumerable <ConfigItem> fileSet, IEnumerable <string> languageFilter, IEnumerable <string> projectFilter)
        {
            if (fileSet == null)
            {
                throw new ArgumentNullException("fileSet");
            }
            if (languageFilter == null)
            {
                throw new ArgumentNullException("languageFilter");
            }
            if (projectFilter == null)
            {
                throw new ArgumentNullException("projectFilter");
            }

            var assemblyResolver = new AssemblyResolver(new[]
            {
                Enlistment.LSBuildToolsPath,
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
            });

            assemblyResolver.Init();

            //Apply language and project filters
            fileSet = ApplyFilters(fileSet, languageFilter, projectFilter);

            //Split executions per language per locgroup to allow finite time of execution
            var distinctLanguages = GetDistinctLanguages(fileSet);
            var distinctProjects  = GetDistinctProjects(fileSet);
            var distinctLocgroups = GetDistinctLocgroups(fileSet);

            //Additional validation for incorrect filter values (e.g. misspelled language or project name)
            ValidateFilterAgainstData(languageFilter, distinctLanguages, "language");
            ValidateFilterAgainstData(projectFilter, distinctProjects, "project");

            var checks = GetCheckFileLocations();

            LoggerSAP.Log("One OSLEBot instance will be run against each locgroup.");
            foreach (var language in distinctLanguages)
            {
                foreach (var project in distinctProjects)
                {
                    foreach (var locgroup in distinctLocgroups)
                    {
                        try
                        {
                            var inputCfg = CreateAsimoConfig(fileSet, checks, language, project, locgroup);
                            if (inputCfg.DataSourcePkgs == null || inputCfg.DataSourcePkgs.Count == 0)
                            {
                                //LoggerSAP.Log("No data sources for {0}, {1}, {2}. Skipping.", language, project, locgroup);
                                continue;
                            }

                            var engine    = new OSLEBotEngine(inputCfg);
                            var engineRan = engine.StartRun();
                            if (engineRan)
                            {
                                LoggerSAP.Trace("Cerberus is waiting for engine activity to complete...");
                                engine.WaitForJobFinish(); //Wait for complete stop of activity.
                                engine.Cleanup();
                            }
                            if (engine.EngineLoggedErrors)
                            {
                                LoggerSAP.Error("Engine reported some execution errors.");
                            }
                        }
                        catch (OperationCanceledException ex)
                        {
                            LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message);
                        }
                        catch (OSLEBotEngineInitializationException ex)
                        //Thrown when there are no rules to run on the input set.
                        {
                            LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Runs Asimo (a.k.a. OSLEBot) on the specified input files and database information to control which checks
        /// are enabled for which {languages, projects}
        /// </summary>
        /// <param name="fileSet">Set of files to run Asimo on.</param>
        /// <param name="languageFilter">Collection of languages to filter enlistment by. If empty, no filtering is applied.</param>
        /// <param name="projectFilter">Collection of projects to filter enlistment by. If empty, no filtering is applied.</param>
        public override void Run(IEnumerable <ConfigItem> fileSet, IEnumerable <string> languageFilter, IEnumerable <string> projectFilter)
        {
            var readOnlyDB = new CheckConfiguration();

            LoadDataFromDatabase(readOnlyDB);

            if (fileSet == null)
            {
                throw new ArgumentNullException("fileSet");
            }
            if (languageFilter == null)
            {
                throw new ArgumentNullException("languageFilter");
            }
            if (projectFilter == null)
            {
                throw new ArgumentNullException("projectFilter");
            }

            var assemblyResolver = new AssemblyResolver(new[]
            {
                Enlistment.LSBuildToolsPath,
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
            });

            assemblyResolver.Init();

            //Apply language and project filters
            fileSet = ApplyFilters(fileSet, languageFilter, projectFilter);

            //Split executions per language per locgroup to allow finite time of execution
            var distinctLanguages = GetDistinctLanguages(fileSet);
            var distinctProjects  = GetDistinctProjects(fileSet);

            //Additional validation for incorrect filter values (e.g. misspelled language or project name)
            ValidateFilterAgainstData(languageFilter, distinctLanguages, "language");
            ValidateFilterAgainstData(projectFilter, distinctProjects, "project");

            var physicalChecks = GetCheckFileLocations();

            LoggerSAP.Log("One OSLEBot instance will be run against each project.");
            foreach (var language in distinctLanguages)
            {
                foreach (var project in distinctProjects)
                {
                    try
                    {
                        var checksEnabledForThisLanguageProject = readOnlyDB.GetEnabledChecks(language, project);
                        var availableEnabledChecks = physicalChecks.Select(c => Path.GetFileNameWithoutExtension(c))
                                                     .Intersect(checksEnabledForThisLanguageProject);
                        var phycicalCheckPathsToRun = physicalChecks
                                                      .Where(c => availableEnabledChecks
                                                             .Any(cc => Path.GetFileNameWithoutExtension(c).Equals(cc)));
                        if (availableEnabledChecks.Count() == 0)
                        {
                            LoggerSAP.Trace(@"No checks are enabled for [{0}, {1}]. Skipping.", language, project);
                            continue;
                        }
                        var inputCfg = CreateAsimoConfig(fileSet, phycicalCheckPathsToRun, language, project);
                        if (inputCfg.DataSourcePkgs == null || inputCfg.DataSourcePkgs.Count == 0)
                        {
                            //Skip the execution when there is 0 file matches for the specified {language, project} pair.
                            continue;
                        }

                        var engine    = new OSLEBotEngine(inputCfg);
                        var engineRan = engine.StartRun();
                        if (engineRan)
                        {
                            LoggerSAP.Trace("Cerberus is waiting for engine activity to complete...");
                            engine.WaitForJobFinish(); //Wait for complete stop of activity.
                            engine.Cleanup();
                        }
                        if (engine.EngineLoggedErrors)
                        {
                            LoggerSAP.Error("Engine reported some execution errors.");
                        }
                    }
                    catch (OperationCanceledException ex)
                    {
                        LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message);
                    }
                    catch (OSLEBotEngineInitializationException ex)
                    //Thrown when there are no rules to run on the input set.
                    {
                        LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Program's entry point on a program instance. Useful for testing program behavior.
        /// </summary>
        /// <param name="args">Command line arguments</param>
        /// <returns>Success indicator</returns>
        public ProgramReturnValue RunProgram(string[] args)
        {
            Initialize();
            IntroduceYourself();

            var input = ArgumentParser.Parse(args);

            if (!input.Correct)
            {
                LoggerSAP.Error("Unexpected argument: {0}", input.InvalidArgument);
                LoggerSAP.Log();
                ShowUsage();
                return(ProgramReturnValue.ErrorInvalidCommandLine);
            }

            LoggerSAP.Log("{0} is starting.", ExeID);
            if (!_enlistment.IsDetected)
            {
                LoggerSAP.Error(
                    "Office 14 enlistment not detected. This program must be run from within Office14 development environment.");
                return(ProgramReturnValue.ErrorNoEnlistment);
            }
            LoggerSAP.Trace("Enlistment detected at {0}", _enlistment.Location);
            var unfilteredFiles = _enlistment.GetFiles("intl", LcxType.Lcl);

            switch (input.RunMode)
            {
            case ProgramRunMode.StandaloneLocGroups:
                _asimo = new StandAloneAsimoLocGroupBreakdown(_enlistment);
                break;

            case ProgramRunMode.StandaloneProjects:
                _asimo = new StandAloneAsimoProjectBreakdown(_enlistment);
                break;

            case ProgramRunMode.DatabaseCentralized:
                _asimo = new DatabaseAsimo(_enlistment);
                break;

            case ProgramRunMode.ShowHelpAndQuit:
                ShowUsage();
                return(ProgramReturnValue.Success);

            default:
                throw new ArgumentOutOfRangeException();
            }
            _asimo.CheckFolderPath = Path.Combine(_enlistment.Location, Settings.Default.ChecksRelativePath);
            try
            {
                if (TestMode)
                {
                    _asimo.Run(unfilteredFiles.Take(10), input.Languages, input.Projects);
                }
                else
                {
                    _asimo.Run(unfilteredFiles, input.Languages, input.Projects);
                }
            }
            catch (DirectoryNotFoundException e)
            {
                LoggerSAP.Error("OSLEBot execution unsuccessful, because: {0}", e.Message);
                return(ProgramReturnValue.ErrorMissingDirectory);
            }
            return(ProgramReturnValue.Success);
        }
Esempio n. 5
0
        /// <summary>
        /// Runs OSLEBot on a set of files. The set of files specified in response file is cross-joined with data in configuration file
        /// to produce an input configuration for OSLEBot engine.
        /// </summary>
        /// <param name="responseFilePath">A list of references to LCX files for OSLEBot processing. Includes additional metadata about project and locgroup.</param>
        /// <param name="cerberusConfigPath">A Cerberus configuration database which defines the checks that are to be applied by OSLEBot.</param>
        /// <param name="cerberusOutputPath">A path to be used by Cerberus to create merged output.</param>
        public OSLEBotResult Run(string responseFilePath, string cerberusConfigPath, string cerberusOutputPath, string oslebotEngineLogPath)
        {
            OSLEBotResult result = OSLEBotResult.Success;

            if (responseFilePath == null)
            {
                throw new ArgumentNullException("responseFilePath");
            }
            if (cerberusConfigPath == null)
            {
                throw new ArgumentNullException("cerberusConfigPath");
            }
            if (cerberusOutputPath == null)
            {
                throw new ArgumentNullException("ceberusOutputPath");
            }
            if (oslebotEngineLogPath == null)
            {
                throw new ArgumentNullException("oslebotEngineLogPath");
            }

            IList <InputFileItem> fileList = null;

            try
            {
                fileList = LoadResponseFile(responseFilePath);
            }
            catch (Exception e)
            {
                throw;
            }
            var readOnlyDB = new CheckConfiguration();

            LoadDataFromDatabase(readOnlyDB, cerberusConfigPath);

            //initialize configuration helper. WARNING: thread unsafe if multiple configurations are ever to be used.
            ConfigurationHelper.Initialize(readOnlyDB);

            var checkConfigs = ReadCheckConfigsFromDatabase(readOnlyDB);

            var inputCfg = CreateConfig(fileList, checkConfigs, cerberusOutputPath, oslebotEngineLogPath);

            try
            {
                if (inputCfg.DataSourcePkgs == null || inputCfg.DataSourcePkgs.Count == 0)
                {
                    //Skip the execution when there is 0 file matches for the specified {language, project} pair.
                }

                var engine    = new OSLEBotEngine(inputCfg);
                var engineRan = engine.StartRun();
                if (engineRan)
                {
                    LoggerSAP.Trace("Cerberus is waiting for engine activity to complete...");
                    engine.WaitForJobFinish(); //Wait for complete stop of activity.
                    engine.Cleanup();
                }
                if (engine.EngineLoggedErrors)
                {
                    LoggerSAP.Error("Engine reported some execution errors.");
                    result = OSLEBotResult.HandledExceptions;
                }
            }
            // catch and log any exception that was not handled by OSLEBot engine
            catch (Exception e)
            {
                LoggerSAP.Error("OSLEBot engine failed with the following exception:\n{0}", e.GetExceptionDetails(true));
                result = OSLEBotResult.HandledExceptions;
            }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Program's entry point on a program instance. Useful for testing program behavior.
        /// </summary>
        /// <param name="args">Command line arguments</param>
        /// <returns>Success indicator</returns>
        public ProgramReturnValue RunProgram(string[] args)
        {
            Initialize();
            IntroduceYourself();

            var arguments = new Arguments(args);

            foreach (var arg in new[] { "config", "response", "output", "enginelog" })
            {
                if (!arguments.Contains(arg))
                {
                    LoggerSAP.Error("Missing argument: {0}", arg);
                    LoggerSAP.Log();
                    ShowUsage();
                    return(ProgramReturnValue.ErrorInvalidCommandLine);
                }
            }
            // verify arguments are valid
            // check if input files exist
            foreach (var arg in new[] { "config", "response" })
            {
                if (!File.Exists(arguments[arg]))
                {
                    LoggerSAP.Error("Argument \"{0}\" points to a non-existing file:\n{1}", arg, arguments[arg]);
                    return(ProgramReturnValue.ErrorInvalidCommandLine);
                }
            }
            // check if output files are valid file names
            foreach (var arg in new[] { "output", "enginelog" })
            {
                FileInfo fileInfo      = null;
                string   fileNameError = null;
                try{
                    fileInfo = new FileInfo(arguments[arg]);
                }
                catch (ArgumentException)
                {
                    fileNameError = "Filename contains incorrect characters";
                }
                catch (PathTooLongException)
                {
                    fileNameError = "File path is too long";
                }
                catch (NotSupportedException)
                {
                    fileNameError = "Filename contains a colon (:)";
                }
                if (!String.IsNullOrEmpty(fileNameError))
                {
                    LoggerSAP.Error("Argument \"{0}\" contains invalid file name:\n{1}", arg, fileNameError);
                    return(ProgramReturnValue.ErrorInvalidCommandLine);
                }
            }
            LoggerSAP.Log("{0} is starting.", ExeID);

            //OSLEBot engine executes using ThreadPool - each rule is queued separately.
            //since OSLEBot code does block threads, many extra threads will be created by ThreadPool which may impair performance.
            //setting max threadpool threads will limit the number of threadpool threads
            ThreadPool.SetMaxThreads(Environment.ProcessorCount, Environment.ProcessorCount);

            var executor = new OSLEBotExecutor();

            try
            {
                var result = executor.Run(arguments["response"], arguments["config"], arguments["output"], arguments["enginelog"]);
                if (result != OSLEBotExecutor.OSLEBotResult.Success)
                {
                    throw new InvalidOperationException("OSLEBot failed.");
                }
            }
            catch (Exception e)
            {
                LoggerSAP.Critical("OSLEBot execution unsuccessful, because: {0}: {1}", e.ToString(), e.Message);
                return(ProgramReturnValue.InternalFailure);
            }
            return(ProgramReturnValue.Success);
        }