public List <int> RetrieveLanguageIdsFromRules()
        {
            List <int> list = new List <int>();

            foreach (KeyValuePair <int, ICategoryDefinition> categoryDefinition in Categories)
            {
                if (!categoryDefinition.Value.Enabled)
                {
                    continue;
                }

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

                    IConfigurationProxy configProxy     = ProxyHome.Instance.RetrieveConfigurationProxy(ConfigKeyKeeper.Instance.AccessKey);
                    IRuleDeclaration    ruleDeclaration = configProxy.RuleDeclarationFromCategoryIdAndRuleId(categoryDefinition.Value.CategoryDeclarationReferenceId, ruleDefinition.Value.RuleDeclarationReferenceId);

                    foreach (KeyValuePair <int, ILanguageDeclaration> pair in ruleDeclaration.Languages)
                    {
                        ILanguageDeclaration languageReference = pair.Value;
                        if (!list.Contains(languageReference.Id))
                        {
                            list.Add(languageReference.Id);
                        }
                    }
                }
            }
            return(list);
        }
Esempio n. 2
0
        public IConfigurationProxy InitializeConfigurationComponentProxy(IApplicationManager appManager)
        {
            IConfigurationProxy proxy = ConfigurationComponentProxy.Instance;

            ((AbstractComponentProxy)proxy).InitializeComponentAccessPermissions(appManager);
            //((IComponentProxy)proxy).Start();
            return(proxy);
        }
Esempio n. 3
0
 public SessionLogic(
     IRepository <Session> sessionRepository,
     IMapper <Session, GetActiveSessionResponse> getActiveSessionResponseMapper,
     IMapper <Session, CreateSessionRequest> createSessionRequestMapper,
     IMapper <Session, CreateSessionResponse> createSessionResponseMapper,
     IValidator <CreateSessionRequest> createSessionRequestValidator,
     IConfigurationProxy configurationProxy)
 {
     _sessionRepository = sessionRepository;
     _getActiveSessionResponseMapper = getActiveSessionResponseMapper;
     _createSessionRequestMapper     = createSessionRequestMapper;
     _createSessionResponseMapper    = createSessionResponseMapper;
     _createSessionRequestValidator  = createSessionRequestValidator;
     _configurationProxy             = configurationProxy;
 }
Esempio n. 4
0
        private void CreateCategoryDeclarationFile()
        {
            IConfigurationProxy proxy = ProxyHome.Instance.RetrieveConfigurationProxy(OutputKeyKeeper.Instance.AccessKey);

            XmlNode     node;
            XmlDocument doc = XmlFactory.CreateXmlFile(Ids.XSLT_DIR, Ids.ALL_CATEGORY_DECLARATIONS_XSLT_FILE, "CategoryDeclarations", out node);

            // <CategoryDeclarations>
            //   <CategoryDeclaration />
            // </CategoryDeclarations>
            foreach (KeyValuePair <int, ICategoryDeclaration> pair in proxy.CategoryDeclarations())
            {
                node.AppendChild(XmlFactory.CreateCategoryDeclarationXmlNode(doc, pair.Value));
                doc.AppendChild(node);
            }

            XmlFactory.SaveXmlFile(Path.Combine(OutputRootDir, Ids.OUTPUT_DIR, Ids.ALL_CATEGORY_DECLARATIONS_XML_FILE), doc);
        }
Esempio n. 5
0
        private List <LinkFile2Language> BindProjectLanguagesToFileTypes(IProjectDefinition project)
        {
            IConfigurationProxy configProxy = ProxyHome.Instance.RetrieveConfigurationProxy(EngineKeyKeeper.Instance.AccessKey);


            // Find all the language Id's that are referenced in the current projects
            // rule definitions.
            List <int> languagesInPlay = project.RetrieveLanguageIdsFromRules();


            // Create the list of link classes (LinkFile2Language) - linking 'Languages' and 'files'
            // When searching for different type of files the files found will have to be hold in
            // collections according to their language type; ex. all csharp files with the extension
            // *.cs will be added to the list of file names in an instance from the class
            // LinkFile2Language where the Language is set to 'C#' or 'csharp'.
            return(languagesInPlay.Select(id => new LinkFile2Language {
                Language = configProxy.LanguageDeclaration(id)
            }).ToList());
        }
        private static IConfigurationProxy ConfigurationComponentProxy()
        {
            IConfigurationProxy proxy = null;

            try
            {
                proxy = ProxyHome.Instance.RetrieveConfigurationProxy(DataAccessKeyKeeper.Instance.AccessKey);
            }
            catch (Exception e)
            {
                throw new DataAccessComponentException(null, -1, "Error: Something unexpected occurred while trying to get an instance of the configuration proxy, " + typeof(IConfigurationProxy) + "?", e);
            }

            if (proxy == null)
            {
                throw new DataAccessComponentException(null, -1, "Error: " + typeof(IConfigurationProxy) + " was null?");
            }

            return(proxy);
        }
Esempio n. 7
0
        private void CreateProjectDefinitionsFile()
        {
            IConfigurationProxy proxy = ProxyHome.Instance.RetrieveConfigurationProxy(OutputKeyKeeper.Instance.AccessKey);

            XmlNode     node;
            XmlDocument doc = XmlFactory.CreateXmlFile(Ids.XSLT_DIR, Ids.ALL_PROJECT_DEFINITIONS_XSLT_FILE, "ProjectDefinitions", out node);

            //<ProjectDefinitions>
            //  <ProjectDefinition />
            //</ProjectDefinitions>
            foreach (KeyValuePair <int, IProjectDefinition> pair in proxy.Projects())
            {
                IProjectDefinition project = pair.Value;

                node.AppendChild(XmlFactory.CreateProjectDefinitionXmlNode(doc, project));
                doc.AppendChild(node);
            }

            XmlFactory.SaveXmlFile(Path.Combine(OutputRootDir, Ids.OUTPUT_DIR, Ids.ALL_PROJECT_DEFINITIONS_XML_FILE), doc);
        }
Esempio n. 8
0
        private void CreateRuleDefinitionsFile()
        {
            IConfigurationProxy proxy = ProxyHome.Instance.RetrieveConfigurationProxy(OutputKeyKeeper.Instance.AccessKey);

            XmlNode     node;
            XmlDocument doc = XmlFactory.CreateXmlFile(Ids.XSLT_DIR, Ids.ALL_RULE_DEFINITIONS_XSLT_FILE, "RuleDefinitions", out node);

            //<RuleDefinitions>
            //  <RuleDefinition />
            //</RuleDefinitions>
            foreach (KeyValuePair <int, IProjectDefinition> projectDefinition in proxy.Projects())
            {
                foreach (KeyValuePair <int, IRuleDefinition> pair in proxy.ProjectRules(projectDefinition.Value.Id))
                {
                    IRuleDefinition ruleDefinition = pair.Value;

                    IRuleDeclaration ruleDeclaration = proxy.RuleDeclarationFromRuleId(ruleDefinition.RuleDeclarationReferenceId);
                    node.AppendChild(XmlFactory.CreateRuleDefinitionXmlNode(doc, ruleDeclaration, ruleDefinition));
                    doc.AppendChild(node);
                }
            }

            XmlFactory.SaveXmlFile(Path.Combine(OutputRootDir, Ids.OUTPUT_DIR, Ids.ALL_RULE_DEFINITIONS_XML_FILE), doc);
        }
Esempio n. 9
0
 public SaunaSensor(
     IConfigurationProxy configurationProxy)
 {
     _configurationProxy = configurationProxy;
 }
Esempio n. 10
0
        public static XmlNode CreateMatchXmlNode(XmlDocument doc, int id, IMatch match)
        {
            //throw new NotImplementedException();

            // <Match Id="" Name="" Open="">
            //   <File />
            //   <LineNumber />
            //   <RegExpName><CDATA ELEMENT></RegExpName>
            //   <RegExpDescription><CDATA ELEMENT></RegExpDescription>
            //   <RegExpExpression><CDATA ELEMENT></RegExpExpression>
            //   <RegExpSummary><CDATA ELEMENT></RegExpSummary>
            //   <Severity Value="">Fatal|Critical|Warning|Info</Severity>
            // </Match>

            XmlNode matchNode           = doc.CreateNode(XmlNodeType.Element, "Match", null);
            XmlNode projectNode         = doc.CreateNode(XmlNodeType.Element, "Project", null);
            XmlNode categoryNode        = doc.CreateNode(XmlNodeType.Element, "Category", null);
            XmlNode rootDirectoryNode   = doc.CreateNode(XmlNodeType.Element, "RootDirectory", null);
            XmlNode filenameNode        = doc.CreateNode(XmlNodeType.Element, "FileName", null);
            XmlNode lineNumberNode      = doc.CreateNode(XmlNodeType.Element, "LineNumber", null);
            XmlNode ruleNameNode        = doc.CreateNode(XmlNodeType.Element, "RuleName", null);
            XmlNode ruleDescriptionNode = doc.CreateNode(XmlNodeType.Element, "RuleDescription", null);
            XmlNode ruleExpressionNode  = doc.CreateNode(XmlNodeType.Element, "RuleExpression", null);
            XmlNode codeExtractNode     = doc.CreateNode(XmlNodeType.Element, "CodeExtract", null);
            XmlNode severityNode        = doc.CreateNode(XmlNodeType.Element, "Severity", null);

            IConfigurationProxy cfgProxy = ProxyHome.Instance.RetrieveConfigurationProxy(OutputKeyKeeper.Instance.AccessKey);

            // Match node...
            XmlAttribute idAttrib   = doc.CreateAttribute("Id");
            XmlAttribute nameAttrib = doc.CreateAttribute("Name");
            XmlAttribute openAttrib = doc.CreateAttribute("Open");

            idAttrib.Value   = id + "";
            nameAttrib.Value = match.Filename;
            openAttrib.Value = "false";

            matchNode.Attributes.Append(idAttrib);
            matchNode.Attributes.Append(nameAttrib);
            matchNode.Attributes.Append(openAttrib);


            IProjectDefinition   projectDefinition   = cfgProxy.Project(match.ProjectDefinitionRef.Id);
            ICategoryDeclaration categoryDeclaration = cfgProxy.CategoryDeclaration(match.RuleDeclarationRef.ParentDeclaration.Id);
            IRuleDeclaration     ruleDeclaration     = cfgProxy.RuleDeclarationFromRuleId(match.RuleDeclarationRef.Id);


            // File node and Line number node...
            projectNode.InnerText       = projectDefinition.Name;
            categoryNode.InnerText      = categoryDeclaration.Name;
            rootDirectoryNode.InnerText = match.RootDirectoryPath;
            filenameNode.InnerText      = match.Filename;
            lineNumberNode.InnerText    = match.LineNumber + "";


            // RegExpName node...
            XmlCDataSection cdataRegExpNameNode = doc.CreateCDataSection(ruleDeclaration.Name);

            ruleNameNode.AppendChild(cdataRegExpNameNode);

            // RegExpDescription node...
            XmlCDataSection cdataRegExpDescriptionNode = doc.CreateCDataSection(ruleDeclaration.Description);

            ruleDescriptionNode.AppendChild(cdataRegExpDescriptionNode);

            // RegExpExpression node...
            XmlCDataSection cdataRegExpExpression = doc.CreateCDataSection(ruleDeclaration.Expression);

            ruleExpressionNode.AppendChild(cdataRegExpExpression);

            // RegExpSummary node...
            XmlCDataSection cdataRegExpSummary = doc.CreateCDataSection(match.CodeExtract);

            codeExtractNode.AppendChild(cdataRegExpSummary);

            // Severity node...
            XmlAttribute severityValueAttrib = doc.CreateAttribute("Value");

            severityValueAttrib.Value = (int)match.Severity + "";
            severityNode.InnerText    = match.Severity.ToString();
            severityNode.Attributes.Append(severityValueAttrib);

            // Add all nodes to the 'node' given in the arguments.
            matchNode.AppendChild(projectNode);
            matchNode.AppendChild(categoryNode);
            matchNode.AppendChild(ruleNameNode);
            matchNode.AppendChild(ruleDescriptionNode);
            matchNode.AppendChild(ruleExpressionNode);
            matchNode.AppendChild(rootDirectoryNode);
            matchNode.AppendChild(filenameNode);
            matchNode.AppendChild(lineNumberNode);
            matchNode.AppendChild(codeExtractNode);
            matchNode.AppendChild(severityNode);
            return(matchNode);
        }
Esempio n. 11
0
 public SmappeeSensor(
     IConfigurationProxy configurationProxy)
 {
     _configurationProxy = configurationProxy;
 }
Esempio n. 12
0
        private void GenerateAllFilesFoundDuringSearch()
        {
            IConfigurationProxy cfgProxy  = ProxyHome.Instance.RetrieveConfigurationProxy(OutputKeyKeeper.Instance.AccessKey);
            IStatisticsProxy    statProxy = ProxyHome.Instance.RetrieveStatisticsProxy(OutputKeyKeeper.Instance.AccessKey);


            XmlDocument    doc         = new XmlDocument();
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

            doc.AppendChild(declaration);

            var pi = doc.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"" + Ids.XSLT_DIR + "/" + Ids.FILES_SEARCHED_XSLT_FILE + "\"");

            doc.AppendChild(pi);


            // <Projects>
            //   <Project Name="string" Id="guid">
            //     <RootDirectory Path="string">
            //       <File Path="string" />
            //       <File Path="string" />
            //       <File Path="string" />
            //     </RootDirectory>
            //   </Project>
            // </Projects>
            XmlNode projects = doc.CreateNode(XmlNodeType.Element, "Projects", null);

            foreach (KeyValuePair <int, IProjectDefinition> pair in cfgProxy.Projects())
            {
                IProjectDefinition projectDefinition = pair.Value;
                if (!pair.Value.Enabled)
                {
                    continue;
                }

                XmlNode      project    = doc.CreateNode(XmlNodeType.Element, "Project", null);
                XmlAttribute nameAttrib = doc.CreateAttribute("Name");
                XmlAttribute idAttrib   = doc.CreateAttribute("Id");

                nameAttrib.Value = projectDefinition.Name;
                idAttrib.Value   = projectDefinition.Id.ToString();

                project.Attributes.Append(nameAttrib);
                project.Attributes.Append(idAttrib);


                foreach (IRootDirectoryStatistics rootDirectoryStats in statProxy.GetRootDirectoriesFromId(projectDefinition.Id))
                {
                    XmlNode      rootDir = doc.CreateNode(XmlNodeType.Element, "RootDirectory", null);
                    XmlAttribute dirPath = doc.CreateAttribute("Path");
                    dirPath.Value = rootDirectoryStats.RootDirectory;
                    rootDir.Attributes.Append(dirPath);

                    foreach (string filename in rootDirectoryStats.Filenames)
                    {
                        XmlNode      file     = doc.CreateNode(XmlNodeType.Element, "File", null);
                        XmlAttribute filePath = doc.CreateAttribute("Path");
                        filePath.Value = filename;
                        file.Attributes.Append(filePath);

                        rootDir.AppendChild(file);
                    }

                    project.AppendChild(rootDir);
                }

                projects.AppendChild(project);
            }

            doc.AppendChild(projects);
            doc.Save(Path.Combine(OutputRootDir, Ids.OUTPUT_DIR, Ids.FILES_SEARCHED_XML_FILE));
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
 public ShellySensor(
     IConfigurationProxy configurationProxy)
 {
     _configurationProxy = configurationProxy;
 }
Esempio n. 15
0
 public OpenWeatherMapSensor(
     IConfigurationProxy configurationProxy)
 {
     _configurationProxy = configurationProxy;
 }