Ejemplo n.º 1
0
        private void StartSearch()
        {
            IConfigurationProxy cfgProxy = ProxyHome.Instance.RetrieveConfigurationProxy(EngineKeyKeeper.Instance.AccessKey);

            List <LinkFile2Language> bindedProj2LanguageFileType = null;

            // Retrieve project definitions from the Configuration component.
            Dictionary <int, IProjectDefinition> projects = cfgProxy.Projects();

            // Let's run through all the projects and do our thing.
            foreach (KeyValuePair <int, IProjectDefinition> pair in projects)
            {
                IProjectDefinition project = pair.Value;
                if (!project.Enabled)
                {
                    continue; // Project definition was disabled.
                }
                // Here we create the language file type containers for all the languages
                // that are in play for the current project.
                bindedProj2LanguageFileType = BindProjectLanguagesToFileTypes(project);


                // Find all files associated with the language file extension in
                // the current file container 'linkFile2Language'.
                foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
                {
                    foreach (IDirectoryDefinition dir in project.Directories)
                    {
                        if (!dir.Enabled)
                        {
                            continue;
                        }

                        if (!Directory.Exists(dir.Path))
                        {
                            string s = string.Format("No directory found ({0})", dir.Path);
                            throw new IOException(s);
                        }

                        IRootDirectoryStatistics rds = ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).CreateRootDirectory(project.Id);
                        rds.RootDirectory = dir.Path;

                        FileSearchEngine fileSearchEngine = new FileSearchEngine(dir, linkFile2Language.Language.Extension);
                        fileSearchEngine.ExcludeDirs            = project.ExcludedDirectories.Select(d => d).ToList();
                        fileSearchEngine.IncludeSubDirsInSearch = true;
                        fileSearchEngine.Search();

                        // Adding all the files found with the extention given by
                        // 'linkFile2Language.Language.Extension' to the file container 'linkFile2Language'.
                        linkFile2Language.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);

                        // Adding all the files found to the StatisticsComponentProxy.
                        ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.Files, fileSearchEngine.FileCount);
                        rds.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);
                    }
                }


                TimeTracker tt = new TimeTracker("Execution of regular expression on each file.");
                tt.Start();


                IMatchProxy matchProxy = ProxyHome.Instance.RetrieveMatchProxy(EngineKeyKeeper.Instance.AccessKey);

                // Let's execute each regular expression from each rule that are enabled
                // and should be applied to the current language.
                foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
                {
                    foreach (KeyValuePair <int, ICategoryDefinition> categoryDefinition in project.Categories)
                    {
                        if (!categoryDefinition.Value.Enabled)
                        {
                            continue;
                        }


                        foreach (KeyValuePair <int, IRuleDefinition> ruleDefinition in categoryDefinition.Value.Rules)
                        {
                            if (!ruleDefinition.Value.Enabled)
                            {
                                continue;
                            }


                            // Let's check whether or not the current 'rule' is associated with the current 'language'?
                            IRuleDeclaration ruleDeclaration = cfgProxy.RuleDeclarationFromCategoryIdAndRuleId(categoryDefinition.Value.CategoryDeclarationReferenceId, ruleDefinition.Value.RuleDeclarationReferenceId);
                            foreach (KeyValuePair <int, ILanguageDeclaration> languageRef in ruleDeclaration.Languages)
                            {
                                if (languageRef.Key == linkFile2Language.Language.Id)
                                {
                                    // The language reference on the current rule is identical to the current 'linkFile2Language'
                                    // meaning that we should execute the regular expression from the current rule on all the
                                    // files placed in the 'linkFile2Language':
                                    IMatchInfoReferences references = matchProxy.MatchesFactory <IMatchInfoReferences>(typeof(IMatchInfoReferences));

                                    references.ProjectDefinitionReference   = project;
                                    references.CategoryDeclarationReference = cfgProxy.CategoryDeclaration(categoryDefinition.Value.CategoryDeclarationReferenceId);
                                    references.CategoryDefinitionReference  = categoryDefinition.Value;
                                    references.RuleDeclarationReference     = ruleDeclaration;
                                    references.RuleDefinitionReference      = ruleDefinition.Value;
                                    references.LanguageDeclarationReference = languageRef.Value;

                                    Parallel.ForEach(linkFile2Language.Filenames, file => ExecuteRegularExpressionsOnBuffer(file, references, ruleDeclaration));
                                }
                            }
                        }
                    }
                }

                tt.Stop("We are done.");
                tt.ToLog(Log);
            }
        }
Ejemplo n.º 2
0
        private void StartSearch()
        {
            IConfigurationProxy cfgProxy = ProxyHome.Instance.RetrieveConfigurationProxy(EngineKeyKeeper.Instance.AccessKey);

              List<LinkFile2Language> bindedProj2LanguageFileType = null;

              // Retrieve project definitions from the Configuration component.
              Dictionary<int, IProjectDefinition> projects = cfgProxy.Projects();

              // Let's run through all the projects and do our thing.
              foreach (KeyValuePair<int, IProjectDefinition> pair in projects)
              {
            IProjectDefinition project = pair.Value;
            if (!project.Enabled)
              continue; // Project definition was disabled.

            // Here we create the language file type containers for all the languages
            // that are in play for the current project.
            bindedProj2LanguageFileType = BindProjectLanguagesToFileTypes(project);

            // Find all files associated with the language file extension in
            // the current file container 'linkFile2Language'.
            foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
            {
              foreach (IDirectoryDefinition dir in project.Directories)
              {
                        if (!dir.Enabled)
                            continue;

            if (!Directory.Exists(dir.Path))
            {
              string s = string.Format("No directory found ({0})", dir.Path);
              throw new IOException(s);
            }

            IRootDirectoryStatistics rds = ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).CreateRootDirectory(project.Id);
            rds.RootDirectory = dir.Path;

            FileSearchEngine fileSearchEngine = new FileSearchEngine(dir, linkFile2Language.Language.Extension);
            fileSearchEngine.ExcludeDirs = project.ExcludedDirectories.Select(d => d).ToList();
            fileSearchEngine.IncludeSubDirsInSearch = true;
            fileSearchEngine.Search();

            // Adding all the files found with the extention given by
            // 'linkFile2Language.Language.Extension' to the file container 'linkFile2Language'.
            linkFile2Language.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);

            // Adding all the files found to the StatisticsComponentProxy.
            ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.Files, fileSearchEngine.FileCount);
            rds.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);
              }
            }

            TimeTracker tt = new TimeTracker("Execution of regular expression on each file.");
            tt.Start();

              IMatchProxy matchProxy = ProxyHome.Instance.RetrieveMatchProxy(EngineKeyKeeper.Instance.AccessKey);

            // Let's execute each regular expression from each rule that are enabled
            // and should be applied to the current language.
            foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
            {
              foreach (KeyValuePair<int, ICategoryDefinition> categoryDefinition in project.Categories)
              {
            if (!categoryDefinition.Value.Enabled)
              continue;

            foreach (KeyValuePair<int, IRuleDefinition> ruleDefinition in categoryDefinition.Value.Rules)
            {
              if (!ruleDefinition.Value.Enabled)
                continue;

              // Let's check whether or not the current 'rule' is associated with the current 'language'?
              IRuleDeclaration ruleDeclaration = cfgProxy.RuleDeclarationFromCategoryIdAndRuleId(categoryDefinition.Value.CategoryDeclarationReferenceId, ruleDefinition.Value.RuleDeclarationReferenceId);
              foreach (KeyValuePair<int, ILanguageDeclaration> languageRef in ruleDeclaration.Languages)
              {
                if (languageRef.Key == linkFile2Language.Language.Id)
                {
                  // The language reference on the current rule is identical to the current 'linkFile2Language'
                  // meaning that we should execute the regular expression from the current rule on all the
                  // files placed in the 'linkFile2Language':
                    IMatchInfoReferences references = matchProxy.MatchesFactory<IMatchInfoReferences>(typeof(IMatchInfoReferences));

                  references.ProjectDefinitionReference   = project;
                  references.CategoryDeclarationReference = cfgProxy.CategoryDeclaration(categoryDefinition.Value.CategoryDeclarationReferenceId);
                                    references.CategoryDefinitionReference  = categoryDefinition.Value;
                    references.RuleDeclarationReference     = ruleDeclaration;
                                    references.RuleDefinitionReference      = ruleDefinition.Value;
                    references.LanguageDeclarationReference = languageRef.Value;

                  Parallel.ForEach(linkFile2Language.Filenames, file => ExecuteRegularExpressionsOnBuffer(file, references, ruleDeclaration));
                }
              }
            }
              }
            }

            tt.Stop("We are done.");
            tt.ToLog(Log);
              }
        }