public static XmlNode CreateFileDefinitionsXmlNode(XmlDocument doc, IProjectDefinition definition) { // <Files> // <Include> // <File /> // </Include> // <Exclude> // <File /> // </Exclude> // </Files> XmlNode filesNode = doc.CreateNode(XmlNodeType.Element, "Files", null); XmlNode includeNode = doc.CreateNode(XmlNodeType.Element, "Include", null); XmlNode excludeNode = doc.CreateNode(XmlNodeType.Element, "Exclude", null); foreach (IFileDefinition fileDefinition in definition.Files) { includeNode.AppendChild(CreateFileDefinitionXmlNode(doc, fileDefinition)); } foreach (IFileDefinition fileDefinition in definition.ExcludedFiles) { excludeNode.AppendChild(CreateFileDefinitionXmlNode(doc, fileDefinition)); } filesNode.AppendChild(includeNode); filesNode.AppendChild(excludeNode); return(filesNode); }
public static XmlNode CreateProjectDefinitionXmlNode(XmlDocument doc, IProjectDefinition definition) { // <ProjectDefinition Enabled="false" Name="Fundamental Building Blocks" Id="{D2A54030-4F7E-421D-BD0C-CC80896FE4D2}"> // <Directories /> // <Files /> // <CategoryDefinitions /> // </Project> XmlNode projectDefinitionNode = doc.CreateNode(XmlNodeType.Element, "ProjectDefinition", null); XmlAttribute enabledAttrib = doc.CreateAttribute("Enabled"); XmlAttribute nameAttrib = doc.CreateAttribute("Name"); XmlAttribute idAttrib = doc.CreateAttribute("Id"); enabledAttrib.Value = definition.Enabled.ToString(); nameAttrib.Value = definition.Name; idAttrib.Value = definition.Id.ToString(); projectDefinitionNode.Attributes.Append(enabledAttrib); projectDefinitionNode.Attributes.Append(nameAttrib); projectDefinitionNode.Attributes.Append(idAttrib); projectDefinitionNode.AppendChild(CreateDirectoriesDefinitionXmlNode(doc, definition)); projectDefinitionNode.AppendChild(CreateFileDefinitionsXmlNode(doc, definition)); projectDefinitionNode.AppendChild(CreateCategoryDefinitionsXmlNode(doc, definition)); return(projectDefinitionNode); }
public static ICategoryDefinition CategoryDefinitionMapper(IProjectDefinition parentProjectDefinition, Model.CategoryDefinition categoryDefinition) { ICategoryDefinition category = null; try { category = ConfigurationComponentFactory().ConfigurationFactory <ICategoryDefinition>(typeof(ICategoryDefinition)); } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Configuration proxy factory failure - unable to create an instance of " + typeof(ICategoryDefinition) + "?", e); } try { category.Id = categoryDefinition.Id; category.Enabled = categoryDefinition.Enabled; category.ParentDefinition = parentProjectDefinition; category.CategoryDeclarationReferenceId = categoryDefinition.CategoryDeclaration.Id; category.CategoryDeclarationReferenceName = categoryDefinition.CategoryDeclaration.Name; foreach (var ruleDef in categoryDefinition.RuleDefinitions) { category.Rules.Add(ruleDef.Id, RuleDefinitionMapper(category, ruleDef)); } } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Mapping process failure?", e); } return(category); }
public static XmlNode CreateDirectoriesDefinitionXmlNode(XmlDocument doc, IProjectDefinition definition) { // <Directories> // <Include> // <Directory /> // </Include> // <Exclude> // <Directory /> // </Exclude> // </Directories> XmlNode directoriesNode = doc.CreateNode(XmlNodeType.Element, "Directories", null); XmlNode includeNode = doc.CreateNode(XmlNodeType.Element, "Include", null); XmlNode excludeNode = doc.CreateNode(XmlNodeType.Element, "Exclude", null); foreach (IDirectoryDefinition directoryDefinition in definition.Directories) { includeNode.AppendChild(CreateDirectoryDefinitionXmlNode(doc, directoryDefinition)); } foreach (IDirectoryDefinition directoryDefinition in definition.ExcludedDirectories) { excludeNode.AppendChild(CreateDirectoryDefinitionXmlNode(doc, directoryDefinition)); } directoriesNode.AppendChild(includeNode); directoriesNode.AppendChild(excludeNode); return(directoriesNode); }
public static ICategoryDefinition CategoryDefinitionMapper(IProjectDefinition parentProjectDefinition, Model.CategoryDefinition categoryDefinition) { ICategoryDefinition category = null; try { category = ConfigurationComponentFactory().ConfigurationFactory<ICategoryDefinition>(typeof (ICategoryDefinition)); } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Configuration proxy factory failure - unable to create an instance of " + typeof(ICategoryDefinition) + "?", e); } try { category.Id = categoryDefinition.Id; category.Enabled = categoryDefinition.Enabled; category.ParentDefinition = parentProjectDefinition; category.CategoryDeclarationReferenceId = categoryDefinition.CategoryDeclaration.Id; category.CategoryDeclarationReferenceName = categoryDefinition.CategoryDeclaration.Name; foreach (var ruleDef in categoryDefinition.RuleDefinitions) { category.Rules.Add(ruleDef.Id, RuleDefinitionMapper(category, ruleDef)); } } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Mapping process failure?", e); } return category; }
public List <IDirectoryDefinition> ProjectExcludedDirectories(int projectId) { lock (ManagerLock) { IProjectDefinition project = Project(projectId); return(project.ExcludedDirectories); } }
public List <IFileDefinition> ProjectExcludedFiles(int projectId) { lock (ManagerLock) { IProjectDefinition project = Project(projectId); return(project.ExcludedFiles); } }
public Dictionary <int, ICategoryDefinition> ProjectCategories(int projectId) { lock (ManagerLock) { IProjectDefinition project = Project(projectId); return(project.Categories); } }
public Dictionary <int, IRuleDefinition> ProjectRules(int projectId) { lock (ManagerLock) { IProjectDefinition project = Project(projectId); return(project.AllRulesInProject()); } }
public static XmlNode CreateCategoryDefinitionsXmlNode(XmlDocument doc, IProjectDefinition definition) { // <CategoryDefinitions> // <CategoryDefinition /> // </CategoryDefinitions> XmlNode categoryDefinitionsNode = doc.CreateNode(XmlNodeType.Element, "CategoryDefinitions", null); foreach (KeyValuePair <int, ICategoryDefinition> pair in definition.Categories) { ICategoryDefinition categoryDefinition = pair.Value; categoryDefinitionsNode.AppendChild(CreateCategoryDefinitionXmlNode(doc, categoryDefinition)); } return(categoryDefinitionsNode); }
public static XmlNode CreateCategoryDefinitionsXmlNode(XmlDocument doc, IProjectDefinition definition) { // <CategoryDefinitions> // <CategoryDefinition /> // </CategoryDefinitions> XmlNode categoryDefinitionsNode = doc.CreateNode(XmlNodeType.Element, "CategoryDefinitions", null); foreach (KeyValuePair<int, ICategoryDefinition> pair in definition.Categories) { ICategoryDefinition categoryDefinition = pair.Value; categoryDefinitionsNode.AppendChild(CreateCategoryDefinitionXmlNode(doc, categoryDefinition)); } return categoryDefinitionsNode; }
public IEnumerable <IProjectDefinition> LoadProjectDefinitions() { using (CodeAnalyzerContainer context = new CodeAnalyzerContainer()) { //var result = from projectDefinitions in context.ProjectDefinition // select projectDefinitions; var result = context.ProjectDefinition.Select(p => p); List <IProjectDefinition> domainProjectDefinitions = new List <IProjectDefinition>(); foreach (ProjectDefinition projectDefinition in result) { IProjectDefinition p = ToDomainModelMapper.ProjectDefinitionMapper(projectDefinition); domainProjectDefinitions.Add(p); } return(domainProjectDefinitions); } }
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 bool ValidateProject(IProjectDefinition projectDefinition) { #region Check the existence of files and directories // Check for whether or not the directories actually exists on desk // if they don't exist then move the non existing directories to the list // invalid directories. CheckDirectories(projectDefinition.Directories, projectDefinition.InvalidDirectories); CheckDirectories(projectDefinition.ExcludedDirectories, projectDefinition.InvalidDirectories); // Let's check the files the same way as we just did with the directories above. CheckFiles(projectDefinition.Files, projectDefinition.InvalidFiles); CheckFiles(projectDefinition.ExcludedFiles, projectDefinition.InvalidFiles); if (projectDefinition.Directories.Count == 0) { Log.Warning("No valid 'Directories' was defined in project '{0}' with ID='{1}'.", projectDefinition.Name, projectDefinition.Id); return(false); } #endregion #region Cross check reference ID's for both categories and rules if (projectDefinition.Categories.Count == 0) { Log.Error(string.Format("No 'CategoryDeclarations' was defined project '{0}' with ID='{1}'.", projectDefinition.Name, projectDefinition.Id)); return(false); } bool validationResult = true; foreach (KeyValuePair <int, ICategoryDefinition> keyValuePair in projectDefinition.Categories) { validationResult = Declarations.IsCategoryDeclared(keyValuePair.Value.CategoryDeclarationReferenceName, keyValuePair.Value.CategoryDeclarationReferenceId); if (!validationResult) { Log.Error(string.Format("The cross references for project with refName='{0}' and with refId='{1}' are invalid.", keyValuePair.Value.CategoryDeclarationReferenceName, keyValuePair.Value.CategoryDeclarationReferenceId)); return(false); } } #endregion return(true); }
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); }
public void ConfigurationFactory_AllSupportedTypes_ReturnsValidObject() { ConfigurationComponentFactory factory = ConfigurationComponentFactory.Instance; factory.InitializeComponentAccessPermissions(AppManager); Debug.Assert(factory != null, "proxy != null"); ILanguageDeclaration languageDeclaration = factory.ConfigurationFactory <ILanguageDeclaration>(typeof(ILanguageDeclaration)); IRuleDeclaration ruleDeclaration = factory.ConfigurationFactory <IRuleDeclaration>(typeof(IRuleDeclaration)); IProjectDefinition projectDefinition = factory.ConfigurationFactory <IProjectDefinition>(typeof(IProjectDefinition)); ICategoryDefinition categoryDefinition = factory.ConfigurationFactory <ICategoryDefinition>(typeof(ICategoryDefinition)); IRuleDefinition ruleDefinition = factory.ConfigurationFactory <IRuleDefinition>(typeof(IRuleDefinition)); IDirectoryDefinition directoryDefinition = factory.ConfigurationFactory <IDirectoryDefinition>(typeof(IDirectoryDefinition)); IFileDefinition fileDefinition = factory.ConfigurationFactory <IFileDefinition>(typeof(IFileDefinition)); Assert.IsNotNull(languageDeclaration); Assert.IsNotNull(ruleDeclaration); Assert.IsNotNull(projectDefinition); Assert.IsNotNull(categoryDefinition); Assert.IsNotNull(ruleDefinition); Assert.IsNotNull(directoryDefinition); Assert.IsNotNull(fileDefinition); }
public static Model.ProjectDefinition ProjectDefinitionMapper(IProjectDefinition projectDefinition) { Model.ProjectDefinition p = new Model.ProjectDefinition() { Id = (projectDefinition.Id != int.MinValue) ? projectDefinition.Id : int.MinValue, Enabled = projectDefinition.Enabled, Name = projectDefinition.Name, }; // Category definitions... foreach (KeyValuePair <int, ICategoryDefinition> pair in projectDefinition.Categories) { p.CategoryDefinitions.Add(CategoryDefinitionMapper(pair.Value)); } // Directories... foreach (IDirectoryDefinition directoryDefinition in projectDefinition.Directories) { p.Directories.Add(new Model.Directory() { Id = (directoryDefinition.Id != int.MinValue) ? directoryDefinition.Id : int.MinValue, Enabled = directoryDefinition.Enabled, Path = directoryDefinition.Path, ProjectDefinition = p, }); } // Excluded directories... foreach (IDirectoryDefinition directoryDefinition in projectDefinition.ExcludedDirectories) { p.ExcludedDirectories.Add(new Model.ExcludedDirectory() { Id = (directoryDefinition.Id != int.MinValue) ? directoryDefinition.Id : int.MinValue, Enabled = directoryDefinition.Enabled, Path = directoryDefinition.Path, ProjectDefinition = p, }); } // Files... foreach (IFileDefinition fileDefinition in projectDefinition.Files) { p.Files.Add(new Model.File() { Id = (fileDefinition.Id != int.MinValue) ? fileDefinition.Id : int.MinValue, Enabled = fileDefinition.Enabled, Path = fileDefinition.Path, ProjectDefinition = p, }); } // Excluded files... foreach (var fileDefinition in projectDefinition.ExcludedFiles) { p.ExcludedFiles.Add(new Model.ExcludedFile() { Id = (fileDefinition.Id != int.MinValue) ? fileDefinition.Id : int.MinValue, Enabled = fileDefinition.Enabled, Path = fileDefinition.Path, ProjectDefinition = p, }); } // Owner... p.Owner = new Model.User() { FirstName = "Claes", MiddleName = "", LastName = "Ryom", Email = "*****@*****.**", Password = "******" }; // Contributers... p.Contributers = new Model.User() { FirstName = "Kim", MiddleName = "Stig", LastName = "Ryom", Email = "*****@*****.**", Password = "******" }; // Followers... p.Contributers = new Model.User() { FirstName = "Marianne", MiddleName = "", LastName = "Ryom", Email = "*****@*****.**", Password = "******" }; return(p); }
public static XmlNode CreateDirectoriesDefinitionXmlNode(XmlDocument doc, IProjectDefinition definition) { // <Directories> // <Include> // <Directory /> // </Include> // <Exclude> // <Directory /> // </Exclude> // </Directories> XmlNode directoriesNode = doc.CreateNode(XmlNodeType.Element, "Directories", null); XmlNode includeNode = doc.CreateNode(XmlNodeType.Element, "Include", null); XmlNode excludeNode = doc.CreateNode(XmlNodeType.Element, "Exclude", null); foreach (IDirectoryDefinition directoryDefinition in definition.Directories) { includeNode.AppendChild(CreateDirectoryDefinitionXmlNode(doc, directoryDefinition)); } foreach (IDirectoryDefinition directoryDefinition in definition.ExcludedDirectories) { excludeNode.AppendChild(CreateDirectoryDefinitionXmlNode(doc, directoryDefinition)); } directoriesNode.AppendChild(includeNode); directoriesNode.AppendChild(excludeNode); return directoriesNode; }
public static XmlNode CreateFileDefinitionsXmlNode(XmlDocument doc, IProjectDefinition definition) { // <Files> // <Include> // <File /> // </Include> // <Exclude> // <File /> // </Exclude> // </Files> XmlNode filesNode = doc.CreateNode(XmlNodeType.Element, "Files", null); XmlNode includeNode = doc.CreateNode(XmlNodeType.Element, "Include", null); XmlNode excludeNode = doc.CreateNode(XmlNodeType.Element, "Exclude", null); foreach (IFileDefinition fileDefinition in definition.Files) { includeNode.AppendChild(CreateFileDefinitionXmlNode(doc, fileDefinition)); } foreach (IFileDefinition fileDefinition in definition.ExcludedFiles) { excludeNode.AppendChild(CreateFileDefinitionXmlNode(doc, fileDefinition)); } filesNode.AppendChild(includeNode); filesNode.AppendChild(excludeNode); return filesNode; }
public static XmlNode CreateProjectDefinitionXmlNode(XmlDocument doc, IProjectDefinition definition) { // <ProjectDefinition Enabled="false" Name="Fundamental Building Blocks" Id="{D2A54030-4F7E-421D-BD0C-CC80896FE4D2}"> // <Directories /> // <Files /> // <CategoryDefinitions /> // </Project> XmlNode projectDefinitionNode = doc.CreateNode(XmlNodeType.Element, "ProjectDefinition", null); XmlAttribute enabledAttrib = doc.CreateAttribute("Enabled"); XmlAttribute nameAttrib = doc.CreateAttribute("Name"); XmlAttribute idAttrib = doc.CreateAttribute("Id"); enabledAttrib.Value = definition.Enabled.ToString(); nameAttrib.Value = definition.Name; idAttrib.Value = definition.Id.ToString(); projectDefinitionNode.Attributes.Append(enabledAttrib); projectDefinitionNode.Attributes.Append(nameAttrib); projectDefinitionNode.Attributes.Append(idAttrib); projectDefinitionNode.AppendChild(CreateDirectoriesDefinitionXmlNode(doc, definition)); projectDefinitionNode.AppendChild(CreateFileDefinitionsXmlNode(doc, definition)); projectDefinitionNode.AppendChild(CreateCategoryDefinitionsXmlNode(doc, definition)); return projectDefinitionNode; }
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(); }
public static IProjectDefinition ProjectDefinitionMapper(Model.ProjectDefinition projectDefinition) { if (projectDefinition == null) { throw new ArgumentNullException("projectDefinition"); } // Check if the project definition is already loaded... IProjectDefinition project = ConfigurationComponentProxy().Project(projectDefinition.Id); if (project == null) { try { project = ConfigurationComponentFactory().ConfigurationFactory <IProjectDefinition>(typeof(IProjectDefinition)); project.Id = projectDefinition.Id; project.Name = projectDefinition.Name; project.Enabled = projectDefinition.Enabled; // Let's add the project to the configuration component... //ConfigurationComponentProxy().CreateProject(project.Id, project.Name, project.Enabled); } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Configuration proxy factory failure - unable to create an instance of " + typeof(IProjectDefinition) + "?", e); } } try { foreach (var catDef in projectDefinition.CategoryDefinitions) { project.Categories.Add(catDef.Id, CategoryDefinitionMapper(project, catDef)); } // Category definitions... foreach (var dir in projectDefinition.Directories) { project.Directories.Add(DirectoryDefinitionMapper(dir)); } // Included directories... foreach (var exDir in projectDefinition.ExcludedDirectories) { project.ExcludedDirectories.Add(ExcludedDirectoryDefinitionMapper(exDir)); } // Excluded directories... foreach (var file in projectDefinition.Files) { project.Files.Add(FileDefinitionMapper(file)); } // Files... foreach (var exFile in projectDefinition.ExcludedFiles) { project.ExcludedFiles.Add(ExcludedFileDefinitionMapper(exFile)); } // Excluded files... } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Mapping process failure?", e); } return(project); }
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); }
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); } }
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)); }
public static Model.ProjectDefinition ProjectDefinitionMapper(IProjectDefinition projectDefinition) { Model.ProjectDefinition p = new Model.ProjectDefinition() { Id = (projectDefinition.Id != int.MinValue) ? projectDefinition.Id : int.MinValue, Enabled = projectDefinition.Enabled, Name = projectDefinition.Name, }; // Category definitions... foreach (KeyValuePair<int, ICategoryDefinition> pair in projectDefinition.Categories) { p.CategoryDefinitions.Add(CategoryDefinitionMapper(pair.Value)); } // Directories... foreach (IDirectoryDefinition directoryDefinition in projectDefinition.Directories) { p.Directories.Add(new Model.Directory() { Id = (directoryDefinition.Id != int.MinValue) ? directoryDefinition.Id : int.MinValue, Enabled = directoryDefinition.Enabled, Path = directoryDefinition.Path, ProjectDefinition = p, }); } // Excluded directories... foreach (IDirectoryDefinition directoryDefinition in projectDefinition.ExcludedDirectories) { p.ExcludedDirectories.Add(new Model.ExcludedDirectory() { Id = (directoryDefinition.Id != int.MinValue) ? directoryDefinition.Id : int.MinValue, Enabled = directoryDefinition.Enabled, Path = directoryDefinition.Path, ProjectDefinition = p, }); } // Files... foreach (IFileDefinition fileDefinition in projectDefinition.Files) { p.Files.Add(new Model.File() { Id = (fileDefinition.Id != int.MinValue) ? fileDefinition.Id : int.MinValue, Enabled = fileDefinition.Enabled, Path = fileDefinition.Path, ProjectDefinition = p, }); } // Excluded files... foreach (var fileDefinition in projectDefinition.ExcludedFiles) { p.ExcludedFiles.Add(new Model.ExcludedFile() { Id = (fileDefinition.Id != int.MinValue) ? fileDefinition.Id : int.MinValue, Enabled = fileDefinition.Enabled, Path = fileDefinition.Path, ProjectDefinition = p, }); } // Owner... p.Owner = new Model.User() { FirstName = "Claes", MiddleName = "", LastName = "Ryom", Email = "*****@*****.**", Password = "******" }; // Contributers... p.Contributers = new Model.User() { FirstName = "Kim", MiddleName = "Stig", LastName = "Ryom", Email = "*****@*****.**", Password = "******" }; // Followers... p.Contributers = new Model.User() { FirstName = "Marianne", MiddleName = "", LastName = "Ryom", Email = "*****@*****.**", Password = "******" }; return p; }
private bool ValidateProject(IProjectDefinition projectDefinition) { #region Check the existence of files and directories // Check for whether or not the directories actually exists on desk // if they don't exist then move the non existing directories to the list // invalid directories. CheckDirectories(projectDefinition.Directories, projectDefinition.InvalidDirectories); CheckDirectories(projectDefinition.ExcludedDirectories, projectDefinition.InvalidDirectories); // Let's check the files the same way as we just did with the directories above. CheckFiles(projectDefinition.Files, projectDefinition.InvalidFiles); CheckFiles(projectDefinition.ExcludedFiles, projectDefinition.InvalidFiles); if (projectDefinition.Directories.Count == 0) { Log.Warning("No valid 'Directories' was defined in project '{0}' with ID='{1}'.", projectDefinition.Name, projectDefinition.Id); return false; } #endregion #region Cross check reference ID's for both categories and rules if (projectDefinition.Categories.Count == 0) { Log.Error(string.Format("No 'CategoryDeclarations' was defined project '{0}' with ID='{1}'.", projectDefinition.Name, projectDefinition.Id)); return false; } bool validationResult = true; foreach (KeyValuePair<int, ICategoryDefinition> keyValuePair in projectDefinition.Categories) { validationResult = Declarations.IsCategoryDeclared(keyValuePair.Value.CategoryDeclarationReferenceName, keyValuePair.Value.CategoryDeclarationReferenceId); if (!validationResult) { Log.Error(string.Format("The cross references for project with refName='{0}' and with refId='{1}' are invalid.", keyValuePair.Value.CategoryDeclarationReferenceName, keyValuePair.Value.CategoryDeclarationReferenceId)); return false; } } #endregion return true; }