ModificationReaderTask.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Tasks » 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 » Tasks » ModificationReaderTask.cs
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using Exortech.NetReflector;
using ThoughtWorks.CruiseControl.Core.Util;

namespace ThoughtWorks.CruiseControl.Core.Tasks{
    /// <summary>
    /// <para>
    /// This tasks makes it possible to read back modifications made by the <link>Modification Writer Task</link>.
    /// </para>
    /// </summary>
    /// <title>Modification Reader Task</title>
    /// <version>1.4</version>
    /// <example>
    /// <code title="Minimalist example">
    /// &lt;modificationReader /&gt;
    /// </code>
    /// <code title="Full example">
    /// &lt;modificationReader&gt;
    /// &lt;deleteAfterRead&gt;true&lt;/deleteAfterRead&gt;
    /// &lt;filename&gt;last-mods.xml&lt;/filename&gt;
    /// &lt;path&gt;mods-path&lt;/path&gt;
    /// &lt;/modificationReader&gt;
    /// </code>
    /// </example>
    /// <remarks>
    /// <para>
    /// 2 projects in CCNet
    /// </para>
    /// <para>
    /// 1) is a project that does the compile, test, ... stuff, and also writes the modifications using the ModificationWriterTask be sure to
    /// set the appendTimeStamp of the modificationWriter to true
    /// </para>
    /// <para>
    /// 2) is a project that deploys the result of project 1
    /// </para>
    /// <para>
    /// --&gt; copies it to other servers, updates source control (binary references like a framework), ...
    /// </para>
    /// <para>
    /// The reason for a second project is that this can be done on releases of milestones of project 1
    /// </para>
    /// <para>
    /// The ModificationReaderTask can now easily read the modification file(s) made by project one, into it's own integration, making it
    /// possible that these can be used by the existing tasks/publishers of ccnet for project 2
    /// </para>
    /// <para>
    /// It is best to place the modificationreader in the prebuild section, so all the other tasks / publisers know the read modifications
    /// also. 
    /// </para>
    /// <para>
    /// It is adivisable to keep these configuration elements of the modificationWriter and the modificationReader the same.  
    /// </para>
    /// </remarks>
    [ReflectorType("modificationReader")]
    public class ModificationReaderTask
        : TaskBase
    {
        private readonly IFileSystem fileSystem;
        private bool deleteAfterRead = false;

        public ModificationReaderTask()
            : this(new SystemIoFileSystem()){ }

        public ModificationReaderTask(IFileSystem fileSystem)
        {
            this.fileSystem = fileSystem;
        }

        /// <summary>
        /// Delete the files after they have been read. 
        /// </summary>
        /// <version>1.4</version>
        /// <default>false</default>
        [ReflectorProperty("deleteAfterRead", Required = false)]
        public bool DeleteAfterRead
        {
            get { return deleteAfterRead; }
            set { deleteAfterRead = value; }
        }

        protected override bool Execute(IIntegrationResult result)
        {
            List<string> filesToDelete = new List<string>();
            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Reading Modifications");                


      List<object> stuff = new List<object>();
          System.Collections.ArrayList AllModifications = new System.Collections.ArrayList();
            

            foreach (string file in GetModificationFiles(result))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Modification[]));
                StringReader reader = new StringReader(fileSystem.Load(file).ReadToEnd());
                object dummy = serializer.Deserialize(reader);
                reader.Close();
                System.Collections.ArrayList currentModification = new System.Collections.ArrayList((Modification[])dummy);

                AllModifications.AddRange(currentModification);

                if (deleteAfterRead) filesToDelete.Add(file);
            }
            
            Modification[] newMods = new Modification[result.Modifications.Length + AllModifications.Count];

            //copy existing modifications
            result.Modifications.CopyTo(newMods, 0);

            // copy modifications read from the file(s)
            int modificationCounter = result.Modifications.Length;
            foreach (Modification mod in AllModifications)
            {
                newMods[modificationCounter] = mod;
                modificationCounter++;
            }

            result.Modifications = newMods;

            // Delete all the files
            foreach (string file in filesToDelete)
            {
                try
                {
                    File.Delete(file);
                }
                catch (IOException error)
                {
                    Log.Warning(
                        string.Format(
                            "Unable to delete file '{0}' - {1}",
                            file,
                            error.Message));
                }
            }

            return true;
        }

        private string[] GetModificationFiles(IIntegrationResult result)
        {
            FileInfo fi = new FileInfo(Path.Combine(result.BaseFromArtifactsDirectory(OutputPath), Filename));
            string filespec = fi.Name.Remove(fi.Name.Length - fi.Extension.Length) + "*" + fi.Extension;
            return Directory.GetFiles(fi.DirectoryName,filespec);        
        }

        /// <summary>
        /// The filename pattern for the file containing the modifications. CCnet with search in the path for files starting with this
        /// filename, and having the same extention. For example when filename is set to modifications.xml, ccnet will search for files
        /// like so: modifications*.xml 
        /// </summary>
        /// <version>1.4</version>
        /// <default>modifications.xml</default>
        [ReflectorProperty("filename", Required = false)]
        public string Filename = "modifications.xml";

        /// <summary>
        /// The directory to search the xml file(s) in. 
        /// </summary>
        /// <version>1.4</version>
        /// <default>Project Artefact Directory</default>
        [ReflectorProperty("path", Required = false)]
        public string OutputPath;
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.