IntegrationQueueManager.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » 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 » IntegrationQueueManager.cs

using System.Collections;
using ThoughtWorks.CruiseControl.Core.Config;
using ThoughtWorks.CruiseControl.Core.Queues;
using ThoughtWorks.CruiseControl.Core.State;
using ThoughtWorks.CruiseControl.Core.Util;
using ThoughtWorks.CruiseControl.Remote;
using System;
using ThoughtWorks.CruiseControl.Remote.Events;
using System.Collections.Generic;

namespace ThoughtWorks.CruiseControl.Core{
  public class IntegrationQueueManager
        : IQueueManager
  {
    private readonly IProjectIntegratorListFactory projectIntegratorListFactory;
    private IProjectIntegratorList projectIntegrators;

    private readonly IntegrationQueueSet integrationQueues = new IntegrationQueueSet();
        private readonly IProjectStateManager stateManager;

    public IntegrationQueueManager(IProjectIntegratorListFactory projectIntegratorListFactory,
                                   IConfiguration configuration,
                                       IProjectStateManager stateManager)
    {
      this.projectIntegratorListFactory = projectIntegratorListFactory;
      Initialize(configuration);
            this.stateManager = stateManager;
    }

    /// <summary>
    /// Gets the projects and integration queues snapshot from this server.
    /// </summary>
        public CruiseServerSnapshot GetCruiseServerSnapshot()
    {
        ProjectStatus[] projectStatuses = GetProjectStatuses();
        QueueSetSnapshot queueSetSnapshot = integrationQueues.GetIntegrationQueueSnapshot();
            return new CruiseServerSnapshot(projectStatuses, queueSetSnapshot);
    }

    public void StartAllProjects()
    {
      foreach (IProjectIntegrator integrator in projectIntegrators)
      {
                bool canStart = (integrator.Project == null) ||
                    ((integrator.Project.StartupMode == ProjectStartupMode.UseLastState) &&
                    stateManager.CheckIfProjectCanStart(integrator.Name)) ||
                    ((integrator.Project.StartupMode == ProjectStartupMode.UseInitialState) &&
                    (integrator.Project.InitialState == ProjectInitialState.Started));
                if (canStart) integrator.Start();
      }
    }

    public void StopAllProjects()
    {
      foreach (IProjectIntegrator integrator in projectIntegrators)
      {
        integrator.Stop();
      }
      WaitForIntegratorsToExit();
      // We should clear the integration queue so the queues can be rebuilt when start again.
      integrationQueues.Clear();
    }

    public void Abort()
    {
      foreach (IProjectIntegrator integrator in projectIntegrators)
      {
        integrator.Abort();
      }
      WaitForIntegratorsToExit();
      // We should clear the integration queue so the queues can be rebuilt when start again.
      integrationQueues.Clear();
    }

    public ProjectStatus[] GetProjectStatuses()
    {
      ArrayList projectStatusList = new ArrayList();
      foreach (IProjectIntegrator integrator in projectIntegrators)
      {
        IProject project = integrator.Project;
        projectStatusList.Add(project.CreateProjectStatus(integrator));
      }
      return (ProjectStatus[]) projectStatusList.ToArray(typeof (ProjectStatus));
    }

    public IProjectIntegrator GetIntegrator(string projectName)
    {
      IProjectIntegrator integrator = projectIntegrators[projectName];
      if (integrator == null) throw new NoSuchProjectException(projectName);
      return integrator;
    }

        public void ForceBuild(string projectName, string enforcerName, Dictionary<string, string> buildValues)
    {
            GetIntegrator(projectName).ForceBuild(enforcerName, buildValues);
    }

    public void WaitForExit(string projectName)
    {
      GetIntegrator(projectName).WaitForExit();
    }

    public void Request(string project, IntegrationRequest request)
    {
      GetIntegrator(project).Request(request);
    }

    public void CancelPendingRequest(string projectName)
    {
      GetIntegrator(projectName).CancelPendingRequest();
    }

    public void Stop(string project)
    {
            stateManager.RecordProjectAsStopped(project);
      GetIntegrator(project).Stop();
    }

    public void Start(string project)
    {
            stateManager.RecordProjectAsStartable(project);
      GetIntegrator(project).Start();
    }

    public void Restart(IConfiguration configuration)
    {
      StopAllProjects();
      Initialize(configuration);
      StartAllProjects();
    }

    private void WaitForIntegratorsToExit()
    {
      foreach (IProjectIntegrator integrator in projectIntegrators)
      {
        integrator.WaitForExit();
      }
    }

    private void Initialize(IConfiguration configuration)
    {
      foreach (IProject project in configuration.Projects)
      {
        // Force the queue to be created if it does not exist already.
                IQueueConfiguration config = configuration.FindQueueConfiguration(project.QueueName);
        integrationQueues.Add(project.QueueName, config);
      }
      projectIntegrators = projectIntegratorListFactory.CreateProjectIntegrators(configuration.Projects, integrationQueues);

      if (projectIntegrators.Count == 0)
      {
        Log.Info("No projects found");
      }
    }

    /// <summary>
    /// Returns an array of the current queue names in usage.
    /// </summary>
    /// <returns>Array of current queue names in use.</returns>
    public string[] GetQueueNames()
    {
      return integrationQueues.GetQueueNames();
    }

        /// <summary>
        /// Associates the integration events.
        /// </summary>
        /// <param name="integrationStarted"></param>
        /// <param name="integrationCompleted"></param>
        public void AssociateIntegrationEvents(EventHandler<IntegrationStartedEventArgs> integrationStarted,
            EventHandler<IntegrationCompletedEventArgs> integrationCompleted)
        {
            foreach (IProjectIntegrator integrator in projectIntegrators)
            {
                integrator.IntegrationStarted += integrationStarted;
                integrator.IntegrationCompleted += integrationCompleted;
            }
        }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.