Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET

Secrets for Setting Up Continuous Integration

Rate me:
Please Sign up or sign in to vote.
2.88/5 (7 votes)
23 Feb 2009CPOL5 min read 65.4K   54   41  
A few simple tips that should help when you are considering setting up CI
using System;
using System.Configuration;
using System.IO;
using Agile.Common;
using Agile.Common.Loggers;
using Agile.Genie.Generators;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using System.Diagnostics;

namespace NantGenie
{

    class Program
    {
        public static UnityContainer container = new UnityContainer();
        
        static void Main(string[] args)
        {
            SetupUnityContainer();

            BuildFileCreator creator = new BuildFileCreator();
            container.BuildUp(creator);

            DirectoryInfo rootWorkingDirectory = new DirectoryInfo(@"C:\Dev\AltNet");
            creator.GenerateBuildFiles(rootWorkingDirectory);
            creator.GenerateMasterBuild(rootWorkingDirectory);
        }

        private static void SetupUnityContainer()
        {
            container = new UnityContainer();
            UnityConfigurationSection section
                = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers.Default.Configure(container);
            Console.WriteLine("Unity container successfully configured.");
        }
    }

    public class BuildFileCreator
    {
        /// <summary>
        /// Search through the directory and all subdirectories and find all project files
        /// and generate a .build file for them.
        /// </summary>
        public void GenerateBuildFiles(DirectoryInfo rootWorkingDirectory)
        {
            Files.LoopThroughSubDirectories(rootWorkingDirectory, GoThroughFiles);
        }

        /// <summary>
        /// Go through all of the files in the directory.
        /// </summary>
        /// <param name="directory"></param>
        private void GoThroughFiles(DirectoryInfo directory)
        {
            Files.GoThroughFilesIn(directory, GenerateCodeForFile);
        }

        /// <summary>
        /// Generate the code for the file.
        /// </summary>
        /// <param name="fileInfo">The file to generate code for.</param>
        private void GenerateCodeForFile(FileInfo fileInfo)
        {
            // only generate for project files.
            if (!Files.IsTheRightFileType(fileInfo, "csproj", "vbproj"))
                return;

            var generator = BuildFileGenerator.Build(fileInfo);

            if (generator != null)
            {
                logger.Write(string.Format("{0} begin generate for {1}", DateTime.Now.ToString("mm:ss:fff"), fileInfo.Name));
                generator.SaveToFile();
                Program.container.BuildUp(generator);
                logger.Write(string.Format("{0} end generate", DateTime.Now.ToString("mm:ss:fff")));
            }
        }

        // set the default logger
        private ILogger logger = new DebugLogger();

        [Dependency]
        public ILogger Logger
        {
            get { return logger; }
            set { logger = value; }
        }

        internal void GenerateMasterBuild(DirectoryInfo rootWorkingDirectory)
        {
            MasterBuildFileGenerator master = MasterBuildFileGenerator.Build(rootWorkingDirectory, false, false);
            Program.container.BuildUp(master);
            master.SaveToFile();
        }
    }
        
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Peer Placements Pty Ltd
Australia Australia
I live in Sydney and have been a developer for almost a decade now. I have a passion for technology and a strong interest in discovering 'better, cleaner, faster' ways to get systems out the door because I believe software development takes too long. If I have an idea I want to realise it as quickly as possible...plus writing systems for someone else I want to deliver quickly so I can move onto the next interesting project!

Comments and Discussions