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

namespace ThoughtWorks.CruiseControl.Core.Sourcecontrol{
    /// <summary>
    /// Use the 'Filesystem' Source Control plugin to check for modifications on a directory accessible by the build server. A file is
    /// considered modified if the file's modified time stamp is more recent than the last time CruiseControl.Net checked for modifications.
    /// You can use either directories on 'mapped' drives (local or remote), or UNC paths (remote).
    /// </summary>
    /// <title>Filesystem Source Control Block</title>
    /// <version>1.0</version>
    /// <key name="type">
    /// <description>The type of source control block.</description>
    /// <value>filesystem</value>
    /// </key>
    /// <example>
    /// <code title="Minimalist example">
    /// &lt;sourcecontrol type="filesystem"&gt;
    /// &lt;repositoryRoot&gt;c:\mycode&lt;/repositoryRoot&gt;
    /// &lt;/sourcecontrol&gt;
    /// </code>
    /// <code title="Full example">
    /// &lt;sourcecontrol type="filesystem"&gt;
    /// &lt;repositoryRoot&gt;c:\mycode&lt;/repositoryRoot&gt;
    /// &lt;autoGetSource&gt;true&lt;/autoGetSource&gt;
    /// &lt;ignoreMissingRoot&gt;false&lt;/ignoreMissingRoot&gt;
    /// &lt;/sourcecontrol&gt;
    /// </code>
    /// </example>
    [ReflectorType("filesystem")]
    public class FileSourceControl 
        : SourceControlBase
    {
        private readonly IFileSystem fileSystem;

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

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

        /// <summary>
        /// The directory to check for changes. This directory will be checked recursively. 
        /// </summary>
        /// <version>1.0</version>
        /// <default>n/a</default>
        [ReflectorProperty("repositoryRoot")]
        public string RepositoryRoot;

        /// <summary>
        /// Whether to automatically (recursively) copy the contents of the repositoryRoot directory to the Project Working Directory.
        /// </summary>
        /// <version>1.0</version>
        /// <default>false</default>
        [ReflectorProperty("ignoreMissingRoot", Required = false)]
        public bool IgnoreMissingRoot;

        /// <summary>
        /// Whether to not fail if the repository doesn't exist.
        /// </summary>
        /// <version>1.0</version>
        /// <default>false</default>
        [ReflectorProperty("autoGetSource", Required = false)]
        public bool AutoGetSource = false;

        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            DirectoryInfo root = new DirectoryInfo(from.BaseFromWorkingDirectory(RepositoryRoot));
            var modifications = GetMods(root, from.StartTime);
            return modifications.ToArray();
        }

        private List<Modification> GetMods(DirectoryInfo dir, DateTime from)
        {
            var mods = new List<Modification>();
            try
            {
                foreach (FileInfo file in dir.GetFiles())
                {
                    if (IsLocalFileChanged(file, from))
                    {
                        mods.Add(CreateModification(file));
                    }
                }

                foreach (DirectoryInfo sub in dir.GetDirectories())
                {
                    mods.AddRange(GetMods(sub, from));
                }
            }
            catch (DirectoryNotFoundException)
            {
                if (!IgnoreMissingRoot)
                {
                    throw;
                }
            }

            return mods;
        }

        private Modification CreateModification(FileInfo info)
        {
            Modification modification = new Modification();
            modification.FileName = info.Name;
            modification.FolderName = info.DirectoryName;

            if (info.CreationTime > info.LastWriteTime)
            {
                modification.ModifiedTime = info.CreationTime;
            }
            else
            {
                modification.ModifiedTime = info.LastWriteTime;
            }

            return modification;
        }

        private bool IsLocalFileChanged(FileInfo reposFile, DateTime date)
        {
            bool result = false;

            if (reposFile.LastWriteTime > date) result = true;
            if (reposFile.CreationTime > date) result = true;

            return result;
        }

        public override void LabelSourceControl(IIntegrationResult result)
        { }

        public override void GetSource(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask("Getting source from FileSourceControl");

            if (AutoGetSource)
                fileSystem.Copy(RepositoryRoot, result.WorkingDirectory);
        }

        public override void Initialize(IProject project)
        { }

        public override void Purge(IProject project)
        { }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.