ConsoleMain.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Console » 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 » Console » ConsoleMain.cs
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Runtime.Remoting;
using System.Configuration;

namespace ThoughtWorks.CruiseControl.Console{
  public class ConsoleMain
  {
        private static object lockObject = new object();

    [STAThread]
    internal static int Main(string[] args)
    {
            bool restart = true;
            int result = 0;
            DateTime restartTime = DateTime.MinValue;
            using (FileSystemWatcher watcher = new FileSystemWatcher(AppDomain.CurrentDomain.BaseDirectory, "*.dll"))
            {
                AppRunner runner = null;

                // Start monitoring file changes
                watcher.Changed += delegate(object sender, FileSystemEventArgs e)
                {
                    if (!restart)
                    {
                        lock (lockObject)
                        {
                            try
                            {
                                runner.Stop("One or more DLLs have changed");
                            }
                            catch (RemotingException)
                            {
                                // Sometimes this exception occurs - the lock statement should catch it, but...
                            }
                        }
                    }
                    restart = true;
                    restartTime = DateTime.Now.AddSeconds(10);
                };
                watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.Size;
                watcher.EnableRaisingEvents = true;

                // Begin the main application loop
                while (restart)
                {
                    restart = false;

                    // Load the domain and start the runner
                    // Allow the user to turn shadow-copying off
                    var setting = ConfigurationManager.AppSettings["ShadowCopy"] ?? string.Empty;
                    var useShadowCopying = !(string.Equals(setting, "off", StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(setting, "false", StringComparison.InvariantCultureIgnoreCase));
                    AppDomain runnerDomain;
                    try
                    {
                        runnerDomain = CreateNewDomain(useShadowCopying);
                    }
                    catch (FileLoadException)
                    {
                        // Unable to use shadow-copying (no user profile?), therefore turn off shadow-copying
                        useShadowCopying = false;
                        runnerDomain = CreateNewDomain(useShadowCopying);
                    }
                    runner = runnerDomain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location,
                        typeof(AppRunner).FullName) as AppRunner;
                    result = runner.Run(args, useShadowCopying);
                    AppDomain.Unload(runnerDomain);

                    // Allow any change events to finish (i.e. if multiple files are copied)
                    while (DateTime.Now < restartTime)
                    {
                        Thread.Sleep(500);
                    }
                }
            }
            return result;
        }

        /// <summary>
        /// Creates the new runner domain.
        /// </summary>
        /// <param name="useShadowCopying">If set to <c>true</c> shadow copying will be used.</param>
        /// <returns>The new <see cref="AppDomain"/>.</returns>
        private static AppDomain CreateNewDomain(bool useShadowCopying)
        {
            return AppDomain.CreateDomain(
                "CC.Net",
                null,
                AppDomain.CurrentDomain.BaseDirectory,
                AppDomain.CurrentDomain.RelativeSearchPath,
                useShadowCopying);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.