CCTrayMultiConfiguration.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » Configuration » 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 » CCTrayLib » Configuration » CCTrayMultiConfiguration.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using ThoughtWorks.CruiseControl.CCTrayLib.Monitoring;
using System.Windows.Forms;

namespace ThoughtWorks.CruiseControl.CCTrayLib.Configuration{
    public class CCTrayMultiConfiguration : ICCTrayMultiConfiguration
    {
        private PersistentConfiguration persistentConfiguration;
        private readonly ICruiseServerManagerFactory cruiseServerManagerFactory;
        private readonly ICruiseProjectManagerFactory cruiseProjectManagerFactory;
        private readonly string configFileName;
        private readonly IDictionary<BuildServer, ICruiseServerManager> serverManagersList;

        public CCTrayMultiConfiguration(ICruiseServerManagerFactory cruiseServerManagerFactory,
            ICruiseProjectManagerFactory cruiseProjectManagerFactory, string configFileName)
        {
            this.cruiseServerManagerFactory = cruiseServerManagerFactory;
            this.cruiseProjectManagerFactory = cruiseProjectManagerFactory;
            this.configFileName = configFileName;
            serverManagersList = new Dictionary<BuildServer, ICruiseServerManager>();

            ReadConfigurationFile(configFileName);
        }

        public IProjectMonitor[] GetProjectStatusMonitors(ISingleServerMonitor[] serverMonitors)
        {
            int indexRetval = 0;
            ArrayList indexList = new ArrayList();

            for (int i = 0; i < Projects.Length; i++)
            {
                if (Projects[i].ShowProject) indexList.Add(i);
            }

            IProjectMonitor[] retVal = new IProjectMonitor[indexList.Count];

            foreach (int i in indexList)
            {
                if (Projects[i].ShowProject)
                {
                    ICruiseProjectManager projectManager = cruiseProjectManagerFactory.Create(Projects[i], serverManagersList);
                    ISingleServerMonitor serverMonitor = GetServerMonitorForProject(Projects[i], serverMonitors);
                    retVal[indexRetval++] = new ProjectMonitor(Projects[i], projectManager, serverMonitor);
                }
            }

            return retVal;
        }

        private static ISingleServerMonitor GetServerMonitorForProject(CCTrayProject project, IEnumerable<ISingleServerMonitor> serverMonitors)
        {
            foreach (ISingleServerMonitor serverMonitor in serverMonitors)
            {
                if (serverMonitor.ServerUrl == project.ServerUrl)
                {
                    return serverMonitor;
                }
            }
            throw new ApplicationException("Server monitor not found for project: " + project.ProjectName);
        }

        public ISingleServerMonitor[] GetServerMonitors()
        {
            BuildServer[] buildServers = GetUniqueBuildServerList();
            ISingleServerMonitor[] serverMonitors = new ISingleServerMonitor[buildServers.Length];
            for (int i = 0; i < buildServers.Length; i++)
            {
                BuildServer buildServer = buildServers[i];
                ICruiseServerManager serverManager = cruiseServerManagerFactory.Create(buildServer);
                serverManagersList[buildServer] = serverManager;
                serverMonitors[i] = new ServerMonitor(serverManager);
            }
            return serverMonitors;
        }

        /// <summary>
        /// Construct a unique list of the build servers based on the projects configured in CCTray.
        /// </summary>
        /// <returns></returns>
        public BuildServer[] GetUniqueBuildServerList()
        {
            ArrayList buildServerList = new ArrayList();
            for (int i = 0; i < Projects.Length; i++)
            {
                BuildServer buildServer = Projects[i].BuildServer;
                if (!buildServerList.Contains(buildServer))
                {
                    buildServerList.Add(buildServer);
                }
            }
            return (BuildServer[])buildServerList.ToArray(typeof(BuildServer));
        }

        public CCTrayProject[] Projects
        {
            get { return persistentConfiguration.Projects; }
            set { persistentConfiguration.Projects = value; }
        }

        public bool ShouldShowBalloonOnBuildTransition
        {
            get { return persistentConfiguration.BuildTransitionNotification.ShowBalloon; }
            set { persistentConfiguration.BuildTransitionNotification.ShowBalloon = value; }
        }

        public ToolTipIcon MinimumNotificationLevel
        {
            get { return persistentConfiguration.BuildTransitionNotification.MinimumNotificationLevel; }
            set { persistentConfiguration.BuildTransitionNotification.MinimumNotificationLevel = value; }
        }

        public bool AlwaysOnTop
        {
            get { return persistentConfiguration.AlwaysOnTop; }
            set { persistentConfiguration.AlwaysOnTop = value; }
        }

        public bool ShowInTaskbar
        {
            get { return persistentConfiguration.ShowInTaskbar; }
            set { persistentConfiguration.ShowInTaskbar = value; }
        }
        /// <summary>
        /// Report any changes to the projects.
        /// </summary>
        public bool ReportProjectChanges
        {
            get { return persistentConfiguration.ReportProjectChanges; }
            set { persistentConfiguration.ReportProjectChanges = value; }
        }

        public string FixUserName
        {
            get { return persistentConfiguration.FixUserName; }
            set { persistentConfiguration.FixUserName = value; }
        }

        public int PollPeriodSeconds
        {
            get { return persistentConfiguration.PollPeriodSeconds; }
            set { persistentConfiguration.PollPeriodSeconds = value; }
        }

        public void Persist()
        {
            WriteConfigurationFile(configFileName);
        }
        /// <summary>
        /// Load the settings from a different location.
        /// </summary>
        /// <param name="settingsFile"></param>
        public virtual void Load(string settingsFile)
        {
            ReadConfigurationFile(settingsFile);
        }

        /// <summary>
        /// Save the settings to a different location.
        /// </summary>
        /// <param name="settingsFile"></param>
        public virtual void Save(string settingsFile)
        {
            WriteConfigurationFile(settingsFile);
        }

        private void ReadConfigurationFile(string settingsFile)
        {
            if (!File.Exists(settingsFile))
            {
                persistentConfiguration = new PersistentConfiguration();
                return;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(PersistentConfiguration));

            using (StreamReader configFile = File.OpenText(settingsFile))
                persistentConfiguration = (PersistentConfiguration)serializer.Deserialize(configFile);
        }

        private void WriteConfigurationFile(string settingsFile)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(PersistentConfiguration));

            using (StreamWriter configFile = File.CreateText(settingsFile))
                serializer.Serialize(configFile, persistentConfiguration);
        }

        public void Reload()
        {
            ReadConfigurationFile(configFileName);
        }

        public ICCTrayMultiConfiguration Clone()
        {
            return new CCTrayMultiConfiguration(cruiseServerManagerFactory, cruiseProjectManagerFactory, configFileName);
        }

        public AudioFiles Audio
        {
            get { return persistentConfiguration.BuildTransitionNotification.AudioFiles; }
        }


        public ExecCommands Execs
        {
            get { return persistentConfiguration.BuildTransitionNotification.Exec; }
        }

        public TrayIconDoubleClickAction TrayIconDoubleClickAction
        {
            get { return persistentConfiguration.TrayIconDoubleClickAction; }
            set { persistentConfiguration.TrayIconDoubleClickAction = value; }
        }

        public BalloonMessages BalloonMessages
        {
            get { return persistentConfiguration.BuildTransitionNotification.BalloonMessages; }
        }

        public Icons Icons
        {
            get { return persistentConfiguration.Icons; }
        }

        public X10Configuration X10
        {
            get { return persistentConfiguration.X10; }
        }

        public GrowlConfiguration Growl
        {
            get { return persistentConfiguration.Growl; }
        }

        public ICruiseServerManagerFactory CruiseServerManagerFactory
        {
            get { return cruiseServerManagerFactory; }
        }

        public ICruiseProjectManagerFactory CruiseProjectManagerFactory
        {
            get { return cruiseProjectManagerFactory; }
        }
        public SpeechConfiguration Speech
        {
            get { return persistentConfiguration.Speech; }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.