XmlLogPublisher.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Publishers » 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 » XmlLogPublisher.cs
namespace ThoughtWorks.CruiseControl.Core.Publishers{
    using System.IO;
    using System.Xml;
    using Exortech.NetReflector;
    using ThoughtWorks.CruiseControl.Core.Util;
    using ThoughtWorks.CruiseControl.Remote;
    using ThoughtWorks.CruiseControl.Core.Tasks;

    /// <summary>
    /// <para>
    /// The Xml Log Publisher is used to create the log files used by the CruiseControl.NET Web Dashboard, so if you don't define an 
    /// &lt;xmllogger /&gt; section the Dashboard will not function correctly.
    /// </para>
    /// <para type="warning">
    /// You should place the &lt;xmllogger /&gt; in the &lt;publishers /&gt; section, after any <link>File Merge Task</link>s, in your 
    /// <link>Project Configuration Block</link>.
    /// </para>
    /// </summary>
    /// <title>XML Log Publisher</title>
    /// <version>1.0</version>
    /// <remarks>
    /// <para type="info">
    /// XML Log Publisher used to support the 'mergeFiles' option. This functionality is now removed and you should use <link>File Merge
    /// Task</link> instead.
    /// </para>
    /// </remarks>
    /// <example>
    /// <code title="Minimalist example">
    /// &lt;xmllogger /&gt;
    /// </code>
    /// <code title="Full example">
    /// &lt;xmllogger logDir="c:\myproject\buildlogs" /&gt;
    /// </code>
    /// </example>
    [ReflectorType("xmllogger")]
    public class XmlLogPublisher
        : TaskBase, IMergeTask
    {
    public static readonly string DEFAULT_LOG_SUBDIRECTORY = "buildlogs";

        /// <summary>
        /// The directory to save log files to. If relative, then relative to the Project Artifact Directory.
        /// </summary>
        /// <version>1.0</version>
        /// <default>buildlogs</default>
        [ReflectorProperty("logDir", Required = false)] 
    public string ConfiguredLogDirectory;

    // This is only public because of a nasty hack which I (MR) put in the code. To be made private later...
    public string LogDirectory(string artifactDirectory)
    {
            if (string.IsNullOrEmpty(ConfiguredLogDirectory))
      {
        return Path.Combine(artifactDirectory, DEFAULT_LOG_SUBDIRECTORY);
      }
      else if (Path.IsPathRooted(ConfiguredLogDirectory))
      {
        return ConfiguredLogDirectory;
      }
      else
      {
        return Path.Combine(artifactDirectory, ConfiguredLogDirectory);
      }
    }

        protected override bool Execute(IIntegrationResult result)
        {         
            // only deal with known integration status
            if (result.Status == IntegrationStatus.Unknown)
                return true;

            using (XmlIntegrationResultWriter integrationWriter = new XmlIntegrationResultWriter(CreateWriter(LogDirectory(result.ArtifactDirectory), GetFilename(result))))
            {
        integrationWriter.Formatting = Formatting.Indented;
        integrationWriter.Write(result);
            }

            result.BuildLogDirectory = LogDirectory(result.ArtifactDirectory);

            return true;
        }

        private TextWriter CreateWriter(string dirname, string filename)
        {
            // create directory if necessary
            if (!Directory.Exists(dirname))
                Directory.CreateDirectory(dirname);

            string path = Path.Combine(dirname, filename);

      // create XmlWriter using UTF8 encoding
      return new StreamWriter(path);
        }

        private string GetFilename(IIntegrationResult result)
        {
            return Util.StringUtil.RemoveInvalidCharactersFromFileName(new LogFile(result).Filename);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.