StatisticsResults.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 » StatisticsResults.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace ThoughtWorks.CruiseControl.Core.Publishers.Statistics{
    /// <summary>
    /// A collection of <see cref="StatisticResult"/>s, with the
    /// elements in the order of their creation.
    /// </summary>
    public class StatisticsResults : List<StatisticResult>
    {
        /// <summary>
        /// Write the values of the statistics to the specified output writer,
        /// in the order of their creation.
        /// </summary>
        /// <param name="writer">The writer.</param>
        internal void WriteStats(TextWriter writer)
        {            
            for (int i = 0; i < Count; i++)
            {
                StatisticResult statistic = this[i];
                if (i > 0) writer.Write(", ");
                writer.Write(statistic.Value);
            }
            writer.WriteLine();
        }

        /// <summary>
        /// Add the specified statistics to the specified CSV statistic file.
        /// </summary>
        /// <param name="fileName">The absolute fileid of the file.</param>
        /// <param name="statistics">The statistics.</param>
        /// <remarks>
        /// Note: This method does not reconcile the specified statistics against
        /// the existing content of the file.  If statistics are added or removed
        /// over time, the headings and values may not match up correctly.
        /// </remarks>
        internal void AppendCsv(string fileName, List<StatisticBase> statistics)
        {
            bool isNew = !File.Exists(fileName);
            StreamWriter text = null;
            try
            {
                if (isNew)
                {
                    text = File.CreateText(fileName);
                    WriteHeadings(text, statistics);
                }
                else
                {
                    text = File.AppendText(fileName);
                }
                WriteStats(text);
            }
            finally
            {
                if (text != null) text.Close();
            }
        }

        /// <summary>
        /// Write the column headings for the specified statistics to the specified
        /// output writer, in the order of their creation.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="statistics">The statistics.</param>
        internal static void WriteHeadings(TextWriter writer, List<StatisticBase> statistics)
        {
            for (int i = 0; i < statistics.Count; i++)
            {
                var statistic = statistics[i];
                if (i > 0) writer.Write(", ");
                writer.Write('"' + statistic.Name + '"');
            }
            writer.WriteLine();
        }

        /// <summary>
        /// Write the statistics in XML to the specified output writer.
        /// </summary>
        /// <param name="outStream">The output writer.</param>
        /// <remarks>
        /// The output is written in the following format:
        ///     &lt;statistics&gt;
        ///         &lt;statistic name="name"&gt;
        ///             value
        ///         &lt;/statistic&gt;
        ///     &lt;/statistics&gt;
        /// </remarks>
        internal void Save(TextWriter outStream)
        {
            XmlTextWriter writer = new XmlTextWriter(outStream);
            writer.Formatting = Formatting.Indented;
            writer.WriteStartElement("statistics");
            ForEach(delegate(StatisticResult statisticResult)
                        {
                            writer.WriteStartElement("statistic");
                            writer.WriteAttributeString("name", statisticResult.StatName);
                            writer.WriteString(Convert.ToString(statisticResult.Value));
                            writer.WriteEndElement();
                        });
            writer.WriteEndElement();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.