Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CruiseServerHarness"/> class.
        /// </summary>
        /// <param name="projects">The projects.</param>
        public CruiseServerHarness(XmlDocument configuration, params string[] projects)
        {
            // Initialise the default values
            this.TimeoutLength = new TimeSpan(0, 5, 0);

            // Initialise the configuration file (this needs to be in the physical directory since CC.NET reads from the directory)
            var workingFolder = Environment.CurrentDirectory;

            this.configFile = Path.Combine(workingFolder, "ScenarioTests.xml");
            configuration.Save(configFile);

            // Initialise the projects (state files, build folders, etc.)
            this.projects     = new List <string>(projects);
            this.stateFiles   = projects.Select(p => Path.Combine(workingFolder, p + ".state")).ToArray();
            this.buildFolders = projects.Select(p => Path.Combine(workingFolder, Path.Combine("ScenarioTests", p))).ToArray();

            // Initialise the server instance
            this.factory = new CruiseServerFactory();
            this.server  = this.factory.Create(true, this.configFile);

            // Initialise the events
            this.completionEvents = new ManualResetEvent[projects.Length];
            for (var loop = 0; loop < this.completionEvents.Length; loop++)
            {
                this.completionEvents[loop] = new ManualResetEvent(false);
            }

            // Handle integration completed
            this.server.IntegrationCompleted += (o, e) =>
            {
                if (this.IntegrationCompleted != null)
                {
                    this.IntegrationCompleted(o, e);
                }

                // Do this last - this ensures that any processing in the event handler has completed (otherwise strange errors can occur due to timing issues)
                this.FindCompletionEvent(e.ProjectName).Set();
            };
        }
Пример #2
0
        /// <summary>
        /// Starts the actual application.
        /// </summary>
        /// <param name="args">The arguments for the application.</param>
        /// <param name="usesShadowCopying">A flag indicating whether shadow copying should be used.</param>
        /// <returns>
        /// The return code for the application.
        /// </returns>
        public int Run(string[] args, bool usesShadowCopying)
        {
            // Parse the command line arguments
            var webOptions  = new WebApiOptions();
            var consoleArgs = new ConsoleRunnerArguments();
            var opts        = new OptionSet();

            opts.Add("h|?|help", "display this help screen", v => consoleArgs.ShowHelp = v != null)
            .Add("c|config=", "the configuration file to use (defaults to ccnet.conf)", v => consoleArgs.ConfigFile = v)
            .Add("r|remoting=", "turn remoting on/off (defaults to on)", v => consoleArgs.UseRemoting                = v == "on")
            .Add("p|project=", "the project to integrate (???)", v => consoleArgs.Project                            = v)
            .Add("v|validate", "validate the configuration file and exit", v => consoleArgs.ValidateConfigOnly       = v != null)
            .Add("l|logging=", "turn logging on/off (defaults to on)", v => consoleArgs.Logging                      = v == "on")
            .Add("sc|shadowCopy=", "turn shadow copying on/off (defaults to on)", v => usesShadowCopying             = v == "on")
            .Add("e|errorpause=", "turn pause on error on/off (defaults to on)", v => consoleArgs.PauseOnError       = v == "on")
            .Add("we|webEndPoint=", "the base endpoint for the web API (default none)", v => webOptions.BaseEndpoint = v);
            try
            {
                opts.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(1);
            }

            // Display the help
            if (consoleArgs.ShowHelp)
            {
                DisplayHelp(opts);
                return(0);
            }

            ICruiseServerFactory factory = null;

            try
            {
                // Start the actual console runner
                if (webOptions.IsConfigured)
                {
                    var apiFactory = new WebApiServerFactory();
                    apiFactory.StartWebApi(apiFactory, webOptions);
                    factory = apiFactory;
                }
                else
                {
                    factory = new CruiseServerFactory();
                }

                runner = new ConsoleRunner(consoleArgs, factory);
                if (!usesShadowCopying)
                {
                    Log.Warning("Shadow-copying has been turned off - hot-swapping will not work!");
                }

                runner.Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                if (consoleArgs.PauseOnError)
                {
                    Console.WriteLine("An unexpected error has caused the console to crash");
                    Console.ReadKey();
                }
                return(2);
            }
            finally
            {
                // Clean up
                runner = null;
                var disposable = factory as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }