예제 #1
0
        /// <summary>
        /// Loads results for the given source code document from the cache.
        /// </summary>
        /// <param name="sourceCode">The source code to load.</param>
        /// <param name="parser">The parser that created this document.</param>
        /// <param name="writeTime">The last write time of the document.</param>
        /// <param name="settingsTimeStamp">The time when the settings were last updated.</param>
        /// <returns>Returns true if the results were loaded from the cache.</returns>
        public bool LoadResults(SourceCode sourceCode, SourceParser parser, DateTime writeTime, DateTime settingsTimeStamp)
        {
            Param.AssertNotNull(sourceCode, "sourceCode");
            Param.AssertNotNull(parser, "parser");
            Param.Ignore(writeTime);
            Param.Ignore(settingsTimeStamp);

            bool success = false;

            lock (this)
            {
                XmlNode     item = null;
                XmlDocument doc  = this.OpenResultsCache(sourceCode, parser, out item);

                if (doc != null && item != null)
                {
                    try
                    {
                        // Check the settings file timestamp.
                        XmlElement settingsNode = item["settings"];
                        if (settingsNode != null && IsNodeUpToDate(settingsNode, settingsTimeStamp))
                        {
                            // Get the timestamp and make sure the file has not been changed
                            // since this cache was written.
                            if (IsNodeUpToDate(item, writeTime))
                            {
                                XmlNode violations = item.SelectSingleNode("violations");
                                if (violations != null)
                                {
                                    if (parser.ImportViolations(sourceCode, violations))
                                    {
                                        success = true;
                                    }
                                }
                            }
                        }
                    }
                    catch (XmlException)
                    {
                    }

                    if (!this.documentHash.ContainsKey(sourceCode.Project.Location))
                    {
                        this.documentHash.Add(sourceCode.Project.Location, doc);
                    }
                }
            }

            return(success);
        }
예제 #2
0
        /// <summary>
        /// Loads results for the given source code document from the cache.
        /// </summary>
        /// <param name="sourceCode">
        /// The source code to load.
        /// </param>
        /// <param name="parser">
        /// The parser that created this document.
        /// </param>
        /// <param name="writeTime">
        /// The last write time of the document.
        /// </param>
        /// <param name="settingsTimestamp">
        /// The time when the settings were last updated.
        /// </param>
        /// <returns>
        /// Returns true if the results were loaded from the cache.
        /// </returns>
        public bool LoadResults(SourceCode sourceCode, SourceParser parser, DateTime writeTime, DateTime settingsTimestamp)
        {
            Param.AssertNotNull(sourceCode, "sourceCode");
            Param.AssertNotNull(parser, "parser");
            Param.Ignore(writeTime);
            Param.Ignore(settingsTimestamp);

            lock (this)
            {
                XmlNode     item = null;
                XmlDocument doc  = this.OpenResultsCache(sourceCode, parser, out item);

                if (doc != null && item != null)
                {
                    if (!this.documentHash.ContainsKey(sourceCode.Project.Location))
                    {
                        this.documentHash.Add(sourceCode.Project.Location, doc);
                    }

                    try
                    {
                        // Check the timestamps of all the files.
                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/styleCop"), this.core.TimeStamp))
                        {
                            return(false);
                        }

                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/settingsFile"), settingsTimestamp))
                        {
                            return(false);
                        }

                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/sourceFile"), writeTime))
                        {
                            return(false);
                        }

                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/parser"), parser.TimeStamp))
                        {
                            return(false);
                        }

                        foreach (SourceAnalyzer analyzer in parser.Analyzers)
                        {
                            if (!IsNodeUpToDate(item.SelectSingleNode(string.Concat("timestamps/", analyzer.Id)), analyzer.TimeStamp))
                            {
                                return(false);
                            }

                            if (
                                !IsNodeUpToDate(
                                    item.SelectSingleNode(string.Concat("timestamps/", analyzer.Id + ".FilesHashCode")),
                                    analyzer.GetDependantFilesHashCode(sourceCode.Project.Culture)))
                            {
                                return(false);
                            }
                        }

                        XmlNode violations = item.SelectSingleNode("violations");
                        if (violations != null)
                        {
                            if (parser.ImportViolations(sourceCode, violations))
                            {
                                return(true);
                            }
                        }
                    }
                    catch (XmlException)
                    {
                    }
                }
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Loads results for the given source code document from the cache.
        /// </summary>
        /// <param name="sourceCode">
        /// The source code to load.
        /// </param>
        /// <param name="parser">
        /// The parser that created this document.
        /// </param>
        /// <param name="writeTime">
        /// The last write time of the document.
        /// </param>
        /// <param name="settingsTimestamp">
        /// The time when the settings were last updated.
        /// </param>
        /// <returns>
        /// Returns true if the results were loaded from the cache.
        /// </returns>
        public bool LoadResults(SourceCode sourceCode, SourceParser parser, DateTime writeTime, DateTime settingsTimestamp)
        {
            Param.AssertNotNull(sourceCode, "sourceCode");
            Param.AssertNotNull(parser, "parser");
            Param.Ignore(writeTime);
            Param.Ignore(settingsTimestamp);

            lock (this)
            {
                XmlNode item = null;
                XmlDocument doc = this.OpenResultsCache(sourceCode, parser, out item);

                if (doc != null && item != null)
                {
                    if (!this.documentHash.ContainsKey(sourceCode.Project.Location))
                    {
                        this.documentHash.Add(sourceCode.Project.Location, doc);
                    }

                    try
                    {
                        // Check the timestamps of all the files.
                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/styleCop"), this.core.TimeStamp))
                        {
                            return false;
                        }

                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/settingsFile"), settingsTimestamp))
                        {
                            return false;
                        }

                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/sourceFile"), writeTime))
                        {
                            return false;
                        }

                        if (!IsNodeUpToDate(item.SelectSingleNode("timestamps/parser"), parser.TimeStamp))
                        {
                            return false;
                        }

                        foreach (SourceAnalyzer analyzer in parser.Analyzers)
                        {
                            if (!IsNodeUpToDate(item.SelectSingleNode(string.Concat("timestamps/", analyzer.Id)), analyzer.TimeStamp))
                            {
                                return false;
                            }

                            if (
                                !IsNodeUpToDate(
                                    item.SelectSingleNode(string.Concat("timestamps/", analyzer.Id + ".FilesHashCode")), 
                                    analyzer.GetDependantFilesHashCode(sourceCode.Project.Culture)))
                            {
                                return false;
                            }
                        }

                        XmlNode violations = item.SelectSingleNode("violations");
                        if (violations != null)
                        {
                            if (parser.ImportViolations(sourceCode, violations))
                            {
                                return true;
                            }
                        }
                    }
                    catch (XmlException)
                    {
                    }
                }
            }

            return false;
        }
예제 #4
0
        /// <summary>
        /// Loads results for the given source code document from the cache.
        /// </summary>
        /// <param name="sourceCode">The source code to load.</param>
        /// <param name="parser">The parser that created this document.</param>
        /// <param name="writeTime">The last write time of the document.</param>
        /// <param name="settingsTimeStamp">The time when the settings were last updated.</param>
        /// <returns>Returns true if the results were loaded from the cache.</returns>
        public bool LoadResults(SourceCode sourceCode, SourceParser parser, DateTime writeTime, DateTime settingsTimeStamp)
        {
            Param.AssertNotNull(sourceCode, "sourceCode");
            Param.AssertNotNull(parser, "parser");
            Param.Ignore(writeTime);
            Param.Ignore(settingsTimeStamp);

            bool success = false;

            lock (this)
            {
                XmlNode item = null;
                XmlDocument doc = this.OpenResultsCache(sourceCode, parser, out item);

                if (doc != null && item != null)
                {
                    try
                    {
                        // Check the settings file timestamp.
                        XmlElement settingsNode = item["settings"];
                        if (settingsNode != null && IsNodeUpToDate(settingsNode, settingsTimeStamp))
                        {
                            // Get the timestamp and make sure the file has not been changed
                            // since this cache was written.
                            if (IsNodeUpToDate(item, writeTime))
                            {
                                XmlNode violations = item.SelectSingleNode("violations");
                                if (violations != null)
                                {
                                    if (parser.ImportViolations(sourceCode, violations))
                                    {
                                        success = true;
                                    }
                                }
                            }
                        }
                    }
                    catch (XmlException)
                    {
                    }

                    if (!this.documentHash.ContainsKey(sourceCode.Project.Location))
                    {
                        this.documentHash.Add(sourceCode.Project.Location, doc);
                    }
                }
            }

            return success;
        }