示例#1
0
        /// <summary>
        /// Main program entry.
        /// </summary>
        public static void Main(string[] args)
        {
            string projectPath = @"C:\Users\Public\GIT\GitHub\My\StyleCop\Shuruev.StyleCop\Shuruev.StyleCop.Run";
            string filePath = @"C:\Users\Public\GIT\GitHub\My\StyleCop\Shuruev.StyleCop\Shuruev.StyleCop.Run\Class1.cs";

            StyleCopConsole console = new StyleCopConsole(null, false, null, null, true);
            CodeProject project = new CodeProject(0, projectPath, new Configuration(null));

            console.Core.Environment.AddSourceCode(project, filePath, null);

            console.OutputGenerated += OnOutputGenerated;
            console.ViolationEncountered += OnViolationEncountered;
            console.Start(new[] { project }, true);

            foreach (SourceParser parser in console.Core.Parsers)
            {
                Console.WriteLine("Parser: {0}", parser.Name);
                foreach (SourceAnalyzer analyzer in parser.Analyzers)
                {
                    Console.WriteLine("Analyzer: {0}", analyzer.Name);
                }
            }

            console.OutputGenerated -= OnOutputGenerated;
            console.ViolationEncountered -= OnViolationEncountered;
            console.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
示例#2
0
        /// <summary>
        /// Main program entry.
        /// </summary>
        public static void Main(string[] args)
        {
            StyleCopConsole console = new StyleCopConsole(
                null,
                false,
                null,
                new List<string>(new[] { basePath }),
                true);

            Configuration configuration = new Configuration(null);
            CodeProject project = new CodeProject(0, basePath, configuration);

            console.Core.Environment.AddSourceCode(project, sourceFile, null);

            List<CodeProject> projects = new List<CodeProject>();
            projects.Add(project);

            console.OutputGenerated += OnOutputGenerated;
            console.ViolationEncountered += OnViolationEncountered;
            console.Start(projects, true);
            console.OutputGenerated -= OnOutputGenerated;
            console.ViolationEncountered -= OnViolationEncountered;
            console.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the SourceCode class.
        /// </summary>
        /// <param name="project">The project that contains this document.</param>
        /// <param name="parser">The parser that created this document.</param>
        protected SourceCode(CodeProject project, SourceParser parser)
        {
            Param.RequireNotNull(project, "project");
            Param.RequireNotNull(parser, "parser");

            this.project = project;
            this.parser = parser;
        }
示例#4
0
 protected SourceCode(CodeProject project, SourceParser parser)
 {
     this.violations = new Dictionary<string, Violation>();
     Param.RequireNotNull(project, "project");
     Param.RequireNotNull(parser, "parser");
     this.project = project;
     this.parser = parser;
 }
 /// <summary>
 /// Adds the source code files.
 /// </summary>
 /// <param name="files">The files.</param>
 /// <param name="console">The console.</param>
 /// <param name="project">The project.</param>
 private static void AddSourceCodeFiles(
     IEnumerable<string> files,
     StyleCopConsole console,
     CodeProject project)
 {
     foreach (var file in files)
     {
         console.Core.Environment.AddSourceCode(project, file, null);
     }
 }
        /// <summary>
        /// Give list of files and projects to be treated by Stylecop
        /// </summary>
        /// <param name="console">
        /// A <see cref="StyleCopConsole"/> which define the console which will treat the files
        /// </param>
        /// <returns>
        /// A <see cref="List<CodeProject>"/> which contains all the project to be treated by stylecop
        /// </returns>
        protected override List<CodeProject> GetCodeProjectList(StyleCopConsole console)
        {
            Configuration configuration = new Configuration(new string[] { "DEBUG" });
            List<CodeProject> projects = new List<CodeProject>();
            CodeProject project = new CodeProject(IdeApp.ProjectOperations.CurrentSelectedProject.BaseDirectory.GetHashCode(), IdeApp.ProjectOperations.CurrentSelectedProject.BaseDirectory, configuration);

            // Add each source file to this project.
            console.Core.Environment.AddSourceCode(project, IdeApp.Workbench.ActiveDocument.FileName, null);
            projects.Add(project);

            return projects;
        }
示例#7
0
 public CodeFile(string path, CodeProject project, SourceParser parser, IEnumerable<Configuration> configurations)
     : base(project, parser, configurations)
 {
     Param.RequireNotNull(path, "path");
     Param.RequireNotNull(project, "project");
     Param.RequireNotNull(parser, "parser");
     this.path = path;
     if ((!path.StartsWith(@"\\", StringComparison.Ordinal) && (path.Length >= 2)) && (path[1] != ':'))
     {
         string currentDirectory = Directory.GetCurrentDirectory();
         if (currentDirectory.EndsWith(@"\", StringComparison.Ordinal))
         {
             currentDirectory = currentDirectory.Substring(0, currentDirectory.Length - 1);
         }
         if (path.StartsWith(@"\", StringComparison.Ordinal))
         {
             path = currentDirectory.Substring(0, 2) + path;
         }
         else
         {
             path = currentDirectory + @"\" + path;
         }
     }
     int length = path.LastIndexOf(@"\", StringComparison.Ordinal);
     if (-1 == length)
     {
         this.name = this.path;
     }
     else
     {
         this.name = path.Substring(length + 1, (path.Length - length) - 1);
         this.folder = path.Substring(0, length);
         if (this.folder != null)
         {
             this.folder = StyleCopCore.CleanPath(this.folder);
         }
     }
     length = this.name.LastIndexOf(".", StringComparison.Ordinal);
     if (-1 == length)
     {
         this.fileType = string.Empty;
     }
     else
     {
         this.fileType = this.name.Substring(length + 1, (this.name.Length - length) - 1).ToUpperInvariant();
     }
 }
        /// <summary>
        /// Mains entry point.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            if (ValidateCommandLineParameters(args))
            {
                return;
            }

            string projectPath = args[0];
            IEnumerable<string> files = GetAllFileNames(projectPath);
            var console = new StyleCopConsole(null, false, null, null, true);
            var project = new CodeProject(0, projectPath, new Configuration(null));

            AddSourceCodeFiles(files, console, project);
            SubscribeStyleCopConsoleEvents(console);
            StartStyleCopAnalysis(console, project);
            UnsubscribeStyleCopConsoleEvents(console);
            DisposeStyleCopConsole(console);
        }
示例#9
0
        /// <summary>
        /// Main program entry.
        /// </summary>
        public static void Main(string[] args)
        {
            string projectPath = @"C:\Users\Public\GIT\GitHub\My\StyleCop\Source\4.4.0.14\ConsoleApplication1";
            string filePath = @"C:\Users\Public\GIT\GitHub\My\StyleCop\Source\4.4.0.14\ConsoleApplication1\Class1.cs";

            StyleCopConsole console = new StyleCopConsole(null, false, null, null, true);
            CodeProject project = new CodeProject(0, projectPath, new Configuration(null));

            console.Core.Environment.AddSourceCode(project, filePath, null);

            console.OutputGenerated += OnOutputGenerated;
            console.ViolationEncountered += OnViolationEncountered;
            console.Start(new[] { project }, true);
            console.OutputGenerated -= OnOutputGenerated;
            console.ViolationEncountered -= OnViolationEncountered;
            console.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
 public override bool AddSourceCode(CodeProject project, string path, object context)
 {
     Param.RequireNotNull(project, "project");
     Param.RequireValidString(path, "path");
     bool flag = false;
     string extension = Path.GetExtension(path);
     if ((extension != null) && (extension.Length > 0))
     {
         extension = extension.Substring(1).ToUpperInvariant();
         ICollection<SourceParser> parsersForFileType = this.GetParsersForFileType(extension);
         if (parsersForFileType == null)
         {
             return flag;
         }
         foreach (SourceParser parser in parsersForFileType)
         {
             SourceCode sourceCode = this.CreateCodeFile(path, project, parser, context);
             project.AddSourceCode(sourceCode);
             flag = true;
         }
     }
     return flag;
 }
        /// <summary>
        /// Runs StyleCop+ for specified file.
        /// </summary>
        public void Run(string sourceFile, SpecialRunningParameters specialRunningParameters)
        {
            Violations.Clear();
            Output.Length = 0;

            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            StyleCopConsole console = new StyleCopConsole(
                null,
                false,
                null,
                new List<string>(new[] { basePath }),
                true);

            StyleCopPlus styleCopPlus = ExtractStyleCopPlus(console);
            if (styleCopPlus == null)
            {
                throw new InvalidOperationException("StyleCopPlus was not found.");
            }

            styleCopPlus.SpecialRunningParameters = specialRunningParameters;

            CodeProject project = new CodeProject(
                0,
                basePath,
                new Configuration(null));

            console.Core.Environment.AddSourceCode(project, sourceFile, null);

            console.ViolationEncountered += OnViolationEncountered;
            console.OutputGenerated += OnOutputGenerated;
            console.Start(new[] { project }, true);

            console.OutputGenerated -= OnOutputGenerated;
            console.ViolationEncountered -= OnViolationEncountered;
            console.Dispose();
        }
示例#12
0
 public string LoadProject(CodeProject project)
 {
     string innerText = null;
     lock (this)
     {
         XmlNode projectNode = null;
         XmlDocument document = this.OpenCacheProject(project, out projectNode);
         if ((document == null) || (projectNode == null))
         {
             goto Label_0060;
         }
         try
         {
             XmlElement element = projectNode["configuration"];
             if (element == null)
             {
                 goto Label_003B;
             }
             innerText = element.InnerText;
         }
         catch (XmlException)
         {
         }
         catch (NullReferenceException)
         {
         }
         return innerText;
     Label_003B:
         if (!this.documentHash.ContainsKey(project.Location))
         {
             this.documentHash.Add(project.Location, document);
         }
     Label_0060:
         innerText = null;
     }
     return innerText;
 }
示例#13
0
 public Settings GetSettings(CodeProject project)
 {
     int key = project.Key;
     if (this.settingsPath != null)
     {
         key = this.settingsPath.GetHashCode();
     }
     Settings projectSettings = null;
     if (this.settings != null)
     {
         this.settings.TryGetValue(key, out projectSettings);
     }
     if (projectSettings == null)
     {
         if (this.settingsPath != null)
         {
             projectSettings = this.core.Environment.GetSettings(this.settingsPath, true);
         }
         else
         {
             projectSettings = this.core.Environment.GetProjectSettings(project, true);
         }
         if (projectSettings == null)
         {
             return projectSettings;
         }
         if (this.settings == null)
         {
             this.settings = new Dictionary<int, Settings>();
         }
         this.settings.Add(key, projectSettings);
     }
     return projectSettings;
 }
示例#14
0
 public ProjectStatus GetProjectStatus(CodeProject project)
 {
     ProjectStatus status;
     if (!this.projectStatus.TryGetValue(project, out status))
     {
         status = new ProjectStatus();
         this.projectStatus.Add(project, status);
     }
     return status;
 }
示例#15
0
 private ICollection<SourceAnalyzer> GetAnalyzersForProjectFile(CodeProject project, SourceCode sourceCode, ICollection<SourceParser> parsers)
 {
     if (!string.IsNullOrEmpty(sourceCode.Type))
     {
         ProjectStatus projectStatus = this.data.GetProjectStatus(project);
         lock (projectStatus.AnalyzerLists)
         {
             ICollection<SourceAnalyzer> is2 = null;
             if (!projectStatus.AnalyzerLists.TryGetValue(sourceCode.Type, out is2))
             {
                 is2 = DiscoverAnalyzerList(this.data.Core, project, parsers);
                 projectStatus.AnalyzerLists.Add(sourceCode.Type, is2);
                 foreach (SourceAnalyzer analyzer in is2)
                 {
                     this.data.Core.SignalOutput(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Loaded Analyzer: {0}...", new object[] { analyzer.Name }));
                 }
             }
             return is2;
         }
     }
     return null;
 }
示例#16
0
 private static ICollection<SourceAnalyzer> DiscoverAnalyzerList(StyleCopCore core, CodeProject project, ICollection<SourceParser> parsers)
 {
     List<SourceAnalyzer> list = new List<SourceAnalyzer>();
     foreach (SourceParser parser in parsers)
     {
         foreach (SourceAnalyzer analyzer in parser.Analyzers)
         {
             Dictionary<string, Rule> dictionary = new Dictionary<string, Rule>();
             AddInPropertyCollection propertys = (project.Settings == null) ? null : project.Settings.GetAddInSettings(analyzer);
             foreach (Rule rule in analyzer.AddInRules)
             {
                 bool flag = !core.AddinsDisabledByDefault && rule.EnabledByDefault;
                 if ((propertys != null) && (!flag || rule.CanDisable))
                 {
                     BooleanProperty property = propertys[rule.Name + "#Enabled"] as BooleanProperty;
                     if (property != null)
                     {
                         flag = property.Value;
                     }
                 }
                 if (flag)
                 {
                     dictionary.Add(rule.Name, rule);
                 }
             }
             if (dictionary.Count > 0)
             {
                 list.Add(analyzer);
                 analyzer.EnabledRules.Add(project, dictionary);
             }
         }
     }
     return list;
 }
 /// <summary>
 /// Starts the style cop analysis.
 /// </summary>
 /// <param name="console">The console.</param>
 /// <param name="project">The project.</param>
 private static void StartStyleCopAnalysis(StyleCopConsole console, CodeProject project)
 {
     console.Start(new[] { project }, true);
 }
示例#18
0
 public CodeFile(string path, CodeProject project, SourceParser parser)
     : this(path, project, parser, null)
 {
 }
 public Settings GetProjectSettings(CodeProject project, bool merge)
 {
     Exception exception;
     return this.GetProjectSettings(project, merge, out exception);
 }
示例#20
0
        /// <summary>
        /// Main program entry.
        /// </summary>
        public static void Main(string[] args)
        {
            StyleCopConsole console = new StyleCopConsole(
                null,
                false,
                null,
                new List<string>(new[] { s_basePath }),
                true);

            /*xxxStyleCopPlus styleCopPlus = null;
            foreach (SourceParser parser in console.Core.Parsers)
            {
                List<SourceAnalyzer> analyzersToRemove = new List<SourceAnalyzer>();
                foreach (SourceAnalyzer analyzer in parser.Analyzers)
                {
                    if (analyzer.GetType() == typeof(StyleCopPlus))
                    {
                        styleCopPlus = (StyleCopPlus)analyzer;
                        break;
                    }

                    analyzersToRemove.Add(analyzer);
                }

                foreach (SourceAnalyzer analyzer in analyzersToRemove)
                {
                    parser.Analyzers.Remove(analyzer);
                }
            }

            if (styleCopPlus == null)
            {
                throw new InvalidOperationException("StyleCopPlus was not found.");
            }*/

            /*xxxstyleCopPlus.DisableAllRulesExcept.Clear();
            styleCopPlus.DisableAllRulesExcept.Add("AdvancedNamingRules");*/

            CodeProject project = new CodeProject(
                0,
                s_basePath,
                new Configuration(null));

            console.Core.Environment.AddSourceCode(project, s_sourceFile, null);

            console.OutputGenerated += OnOutputGenerated;
            console.ViolationEncountered += OnViolationEncountered;
            console.Start(new[] { project }, true);

            foreach (SourceParser parser in console.Core.Parsers)
            {
                Console.WriteLine("Parser: {0}", parser.Name);
                foreach (SourceAnalyzer analyzer in parser.Analyzers)
                {
                    Console.WriteLine("Analyzer: {0}", analyzer.Name);
                }
            }

            console.OutputGenerated -= OnOutputGenerated;
            console.ViolationEncountered -= OnViolationEncountered;
            console.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
 public abstract bool AddSourceCode(CodeProject project, string path, object context);
示例#22
0
 public bool SaveProject(CodeProject project)
 {
     bool flag = false;
     lock (this)
     {
         XmlDocument document = null;
         try
         {
             if (!this.documentHash.TryGetValue(project.Location, out document))
             {
                 XmlNode node;
                 document = this.OpenCacheProject(project, out node);
                 if (document != null)
                 {
                     this.documentHash.Add(project.Location, document);
                 }
             }
             if (document != null)
             {
                 XmlNode oldChild = document.DocumentElement.SelectSingleNode(string.Format(CultureInfo.InvariantCulture, "project[@key=\"{0}\"]", new object[] { project.Key }));
                 if (oldChild != null)
                 {
                     document.DocumentElement.RemoveChild(oldChild);
                 }
             }
             else
             {
                 document = new XmlDocument();
                 document.AppendChild(document.CreateElement("stylecopresultscache"));
                 XmlNode node3 = document.CreateElement("version");
                 document.DocumentElement.AppendChild(node3);
                 node3.InnerText = "10";
                 if (this.documentHash.ContainsKey(project.Location))
                 {
                     this.documentHash.Remove(project.Location);
                 }
                 this.documentHash.Add(project.Location, document);
             }
             XmlNode newChild = document.CreateElement("project");
             XmlAttribute attribute = document.CreateAttribute("key");
             attribute.Value = project.Key.ToString(CultureInfo.InvariantCulture);
             newChild.Attributes.Append(attribute);
             document.DocumentElement.AppendChild(newChild);
             StringBuilder builder = new StringBuilder();
             if (project.Configuration != null)
             {
                 bool flag2 = true;
                 foreach (string str in project.Configuration.Flags)
                 {
                     if (flag2)
                     {
                         flag2 = false;
                         builder.Append(str);
                     }
                     else
                     {
                         builder.AppendFormat(";{0}", str);
                     }
                 }
             }
             XmlNode node5 = document.CreateElement("configuration");
             newChild.AppendChild(node5);
             node5.InnerText = builder.ToString();
             flag = true;
         }
         catch (XmlException)
         {
         }
         return flag;
     }
 }
        /// <summary>
        /// Gets the settings for the given project.
        /// </summary>
        /// <param name="project">The project containing the settings.</param>
        /// <param name="merge">Indicates whether to merge the settings with parent settings before returning them.</param>
        /// <param name="exception">Returns an exception if one occured while loading the settings.</param>
        /// <returns>Returns the settings.</returns>
        public override Settings GetProjectSettings(CodeProject project, bool merge, out Exception exception)
        {
            Param.RequireNotNull(project, "project");
            Param.Ignore(merge);
            Param.Ignore(merge);

            // Create the full string to the local settings file.
            string path = Path.Combine(project.Location, Settings.DefaultFileName);

            if (!File.Exists(path))
            {
                string deprecatedSettingsFilePath = Path.Combine(project.Location, Settings.AlternateFileName);
                if (File.Exists(deprecatedSettingsFilePath))
                {
                    path = deprecatedSettingsFilePath;
                }
                else
                {
                    deprecatedSettingsFilePath = Path.Combine(project.Location, V40Settings.DefaultFileName);
                    if (File.Exists(deprecatedSettingsFilePath))
                    {
                        path = deprecatedSettingsFilePath;
                    }
                }
            }

            return this.GetSettings(path, merge, out exception);
        }
示例#24
0
        /// <summary>
        /// Initializes the project to prepare it for analysis.
        /// </summary>
        /// <param name="project">The project to initialize.</param>
        /// <param name="data">The analysis data object.</param>
        /// <param name="cache">The file cache.</param>
        private static void InitializeProjectForAnalysis(CodeProject project, StyleCopThread.Data data, ResultsCache cache)
        {
            Param.AssertNotNull(project, "project");
            Param.AssertNotNull(data, "data");
            Param.Ignore(cache);

            // Get the status object for the project.
            ProjectStatus projectStatus = data.GetProjectStatus(project);
            Debug.Assert(projectStatus != null, "There is no status for the given project.");

            // Load the settings for the project. If the project already contains settings, use those.
            // Otherwise, load them from scratch.
            if (!project.SettingsLoaded)
            {
                project.Settings = data.GetSettings(project);
                project.SettingsLoaded = true;
            }

            // Load the project configuration from the cache and compare it to the
            // current project configuration.
            string configuration = cache == null ? null : cache.LoadProject(project);
            if (configuration == null)
            {
                projectStatus.IgnoreResultsCache = true;
            }
            else
            {
                projectStatus.IgnoreResultsCache = !StyleCopCore.CompareCachedConfiguration(
                    project.Configuration, configuration);
            }

            if (cache != null && project.WriteCache)
            {
                cache.SaveProject(project);
            }
        }
示例#25
0
        /// <summary>
        /// Executes this MSBuild task, based on the input values passed in by the MSBuild engine.
        /// </summary>
        /// <returns>Returns true if there were no errors, false otherwise.</returns>
        public override bool Execute()
        {
            // Clear the violation count and set the violation limit for the project.
            this.violationCount = 0;
            this.violationLimit = 0;

            if (this.maxViolationCount != null)
            {
                if (!int.TryParse(this.maxViolationCount.ItemSpec, out this.violationLimit))
                {
                    this.violationLimit = 0;
                }
            }

            if (this.violationLimit == 0)
            {
                this.violationLimit = DefaultViolationLimit;
            }

            // Get settings files (if null or empty use null filename so it uses right default).
            string overrideSettingsFileName = null;
            if (this.inputOverrideSettingsFile != null && this.inputOverrideSettingsFile.ItemSpec.Length > 0)
            {
                overrideSettingsFileName = this.inputOverrideSettingsFile.ItemSpec;
            }

            // Get addin paths.
            List<string> addinPaths = new List<string>();
            foreach (ITaskItem addinPath in this.inputAdditionalAddinPaths)
            {
                addinPaths.Add(addinPath.GetMetadata("FullPath"));
            }

            // Create the StyleCop console.
            using (StyleCopConsole console = new StyleCopConsole(
                overrideSettingsFileName,
                this.inputCacheResults,
                this.outputFile == null ? null : this.outputFile.ItemSpec,
                addinPaths,
                true))
            {
                // Create the configuration.
                Configuration configuration = new Configuration(this.inputDefineConstants);

                string projectFullPath = null;
                if (this.inputProjectFullPath != null)
                {
                    projectFullPath = this.inputProjectFullPath.GetMetadata("FullPath");
                }

                if (!string.IsNullOrEmpty(projectFullPath))
                {
                    // Create a CodeProject object for these files.
                    CodeProject project = new CodeProject(
                        projectFullPath.GetHashCode(),
                        projectFullPath,
                        configuration);

                    // Add each source file to this project.
                    foreach (ITaskItem inputSourceFile in this.inputSourceFiles)
                    {
                        console.Core.Environment.AddSourceCode(project, inputSourceFile.ItemSpec, null);
                    }

                    try
                    {
                        // Subscribe to events
                        console.OutputGenerated += this.OnOutputGenerated;
                        console.ViolationEncountered += this.OnViolationEncountered;

                        // Analyze the source files
                        CodeProject[] projects = new CodeProject[] { project };
                        console.Start(projects, this.inputForceFullAnalysis);
                    }
                    finally
                    {
                        // Unsubscribe from events
                        console.OutputGenerated -= this.OnOutputGenerated;
                        console.ViolationEncountered -= this.OnViolationEncountered;
                    }
                }
            }

            return this.succeeded;
        }
 public abstract Settings GetProjectSettings(CodeProject project, bool merge, out Exception exception);
        /// <summary>
        /// Adds a source code document to the given project.
        /// </summary>
        /// <param name="project">The project which should contain the source code instance.</param>
        /// <param name="path">The path to the source code document to add.</param>
        /// <param name="context">Optional context information.</param>
        /// <returns>Returns true if any source code documents were added to the project.</returns>
        public override bool AddSourceCode(CodeProject project, string path, object context)
        {
            Param.RequireNotNull(project, "project");
            Param.RequireValidString(path, "path");
            Param.Ignore(context);

            bool added = false;

            // Get the parsers for this file based on its extension.
            string extension = Path.GetExtension(path);
            if (extension != null && extension.Length > 0)
            {
                // Remove the leading dot and convert the extension to lower-case.
                extension = extension.Substring(1).ToUpperInvariant();

                ICollection<SourceParser> parserList = this.GetParsersForFileType(extension);
                if (parserList != null)
                {
                    // Create SourceCode objects representing this file, for each parser.
                    foreach (SourceParser parser in parserList)
                    {
                        // Create and return a SourceCode for this file.
                        SourceCode source = this.CreateCodeFile(path, project, parser, context);
                        project.AddSourceCode(source);
                        added = true;
                    }
                }
            }

            return added;
        }
示例#28
0
 private XmlDocument OpenCacheProject(CodeProject project, out XmlNode projectNode)
 {
     projectNode = null;
     XmlDocument document = null;
     try
     {
         lock (this)
         {
             if (this.documentHash.TryGetValue(project.Location, out document))
             {
                 projectNode = document.DocumentElement.SelectSingleNode(string.Format(CultureInfo.InvariantCulture, "project[@key=\"{0}\"]", new object[] { project.Key.ToString(CultureInfo.InvariantCulture) }));
                 return document;
             }
             document = this.core.Environment.LoadResultsCache(project.Location);
             if (document == null)
             {
                 return document;
             }
             XmlElement element = document["stylecopresultscache"]["version"];
             if (element.InnerText == "10")
             {
                 projectNode = document.DocumentElement.SelectSingleNode(string.Format(CultureInfo.InvariantCulture, "project[@key=\"{0}\"]", new object[] { project.Key.ToString(CultureInfo.InvariantCulture) }));
                 return document;
             }
             return null;
         }
     }
     catch (XmlException)
     {
         document = null;
     }
     catch (NullReferenceException)
     {
         document = null;
     }
     return document;
 }
 /// <summary>
 /// Creates a new <see cref="CodeFile"/> instance with the given values.
 /// </summary>
 /// <param name="path">The path to the code file.</param>
 /// <param name="project">The project that contains this file.</param>
 /// <param name="parser">The parser that created this file object.</param>
 /// <param name="context">Optional context information.</param>
 /// <returns>Returns the newly created <see cref="CodeFile"/>.</returns>
 protected virtual CodeFile CreateCodeFile(string path, CodeProject project, SourceParser parser, object context)
 {
     Param.Ignore(path, project, parser, context);
     return new CodeFile(path, project, parser);
 }
示例#30
0
 /// <summary>
 /// Initializes a new instance of the SourceCode class.
 /// </summary>
 /// <param name="project">The project that contains this document.</param>
 /// <param name="parser">The parser that created this document.</param>
 /// <param name="configurations">The list of configurations for the document.</param>
 protected SourceCode(CodeProject project, SourceParser parser, IEnumerable<Configuration> configurations)
     : this(project, parser)
 {
     Param.Ignore(project, parser, configurations);
     this.configurations = configurations;
 }