StatisticsBuilder.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Publishers » Statistics » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Publishers » Statistics » StatisticsBuilder.cs
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.XPath;

namespace ThoughtWorks.CruiseControl.Core.Publishers.Statistics{
    public class StatisticsBuilder
    {
        /// <summary>
        /// The statistics this builder works with.
        /// </summary>
        private readonly List<StatisticBase> logStatistics = new List<StatisticBase>();

        /// <summary>
        /// Create a StatisticsBuilder with the default set of statistics, all included.
        /// </summary>
        public StatisticsBuilder()
        {
            Add(new FirstMatch("StartTime", "/cruisecontrol/build/@date"));
            Add(new FirstMatch("Duration", "/cruisecontrol/build/@buildtime"));

            Add(new Statistic("TestCount", "sum(//test-results/@total)"));
            Add(new Statistic("TestFailures", "sum(//test-results/@failures)"));
            Add(new Statistic("TestIgnored", "sum(//test-results/@not-run)"));

      Add(new Statistic("GendarmeDefects", "count(//gendarme-output//rule/target/defect)"));

      Add(new Statistic("FxCop Warnings", "count(//FxCopReport//Message[Issue/@Level='Warning' or Issue/@Level='CriticalWarning'])"));
      Add(new Statistic("FxCop Errors", "count(//FxCopReport//Message[Issue/@Level='Error' or Issue/@Level='CriticalError'])"));

            Add(new FirstMatch("BuildErrorType", "//failure/builderror/type"));
            Add(new FirstMatch("BuildErrorMessage", "//failure/builderror/message"));

        }

        /// <summary>
        /// Extract all the statistics from the specified build results.
        /// </summary>
        /// <param name="result">The results of the build.</param>
        /// <returns>The set of statistic values.</returns>
        internal StatisticsResults ProcessBuildResults(IIntegrationResult result)
        {
            return ProcessBuildResults(ToXml(result));
        }

        /// <summary>
        /// Convert the build results into XML.
        /// </summary>
        /// <param name="result">The build results.</param>
        /// <returns>The XML results.</returns>
        private static string ToXml(IIntegrationResult result)
        {
            StringWriter xmlResultString = new StringWriter();
            XmlIntegrationResultWriter writer = new XmlIntegrationResultWriter(xmlResultString);
            writer.Write(result);
            return xmlResultString.ToString();
        }

        /// <summary>
        /// Extract all the statistics from the specified XML build results.
        /// </summary>
        /// <param name="xmlString"></param>
        /// <returns></returns>
        internal StatisticsResults ProcessBuildResults(string xmlString)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(new StringReader(xmlString));
            return ProcessLog(doc);
        }

        /// <summary>
        /// Add a statistic to the build if its Include property is true.
        /// </summary>
        /// <param name="statistic">The name of the statistic.</param>
        /// <remarks>
        /// If the statistic's <see cref="StatisticBase.Include"/> property
        /// is false, this method may actually remove it from the list!
        /// </remarks>
        internal void Add(StatisticBase statistic)
        {
            if (!logStatistics.Contains(statistic))
            {
                logStatistics.Add(statistic);
            }
            else
            {
                int indexOf = logStatistics.IndexOf(statistic);
                logStatistics.Remove(statistic);
                if (statistic.Include)
                {
                    logStatistics.Insert(indexOf, statistic);
                }
            }
        }

        /// <summary>
        /// Extract all the statistics from the specified XML build results document.
        /// </summary>
        /// <param name="doc">The build results.</param>
        /// <returns>The set of statistics.</returns>
        private StatisticsResults ProcessLog(IXPathNavigable doc)
        {
            XPathNavigator nav = doc.CreateNavigator();
            StatisticsResults statisticResults = new StatisticsResults();
            foreach (StatisticBase s in logStatistics)
            {
                statisticResults.Add(s.Apply(nav));
            }
            return statisticResults;
        }

        /// <summary>
        /// The statistics this builder works with.
        /// </summary>
        public List<StatisticBase> Statistics
        {
            get { return logStatistics; }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.