CruiseServerSnapshot.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Remote » 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 » Remote » CruiseServerSnapshot.cs
using System;
using System.Xml.Serialization;

namespace ThoughtWorks.CruiseControl.Remote{
    /// <summary>
    /// Contains a snapshot of the current CC.Net server status and activity.
    /// </summary>
    [Serializable]
    [XmlRoot("serverSnapshot")]
    public class CruiseServerSnapshot
    {
        private ProjectStatus[] projectStatuses;
        private QueueSetSnapshot queueSetSnapshot;

        /// <summary>
        /// Initialise a new blank <see cref="CruiseServerSnapshot"/>.
        /// </summary>
        public CruiseServerSnapshot()
        {
            projectStatuses = new ProjectStatus[0];
            queueSetSnapshot = new QueueSetSnapshot();
        }

        /// <summary>
        /// Initialise a new populated <see cref="CruiseServerSnapshot"/>.
        /// </summary>
        /// <param name="projectStatuses"></param>
        /// <param name="queueSetSnapshot"></param>
        public CruiseServerSnapshot(ProjectStatus[] projectStatuses, QueueSetSnapshot queueSetSnapshot)
        {
            this.projectStatuses = projectStatuses;
            this.queueSetSnapshot = queueSetSnapshot;
        }

        /// <summary>
        /// The current state of the projects.
        /// </summary>
        [XmlArray("projects")]
        [XmlArrayItem("projectStatus")]
        public ProjectStatus[] ProjectStatuses
        {
            get { return projectStatuses; }
            set { projectStatuses = value; }
        }

        /// <summary>
        /// The current state of the queues.
        /// </summary>
        [XmlElement("queueSet")]
        public QueueSetSnapshot QueueSetSnapshot
        {
            get { return queueSetSnapshot; }
            set { queueSetSnapshot = value; }
        }

        /// <summary>
        /// Checks if a snapshot has changed.
        /// </summary>
        /// <param name="queueSetSnapshotToCompare"></param>
        /// <returns></returns>
        public bool IsQueueSetSnapshotChanged(QueueSetSnapshot queueSetSnapshotToCompare)
        {
            if (queueSetSnapshotToCompare == null)
            {
                if (queueSetSnapshot == null)
                    return false;
                else
                    return true;
            }
            if (queueSetSnapshot == null)
                return true;
            if (queueSetSnapshotToCompare.Queues.Count != queueSetSnapshot.Queues.Count)
                return true;

            for (int queueIndex = 0; queueIndex < queueSetSnapshot.Queues.Count; queueIndex++)
            {
                QueueSnapshot queueSnapshot = queueSetSnapshot.Queues[queueIndex];
                QueueSnapshot queueSnapshotToCompare = queueSetSnapshotToCompare.Queues[queueIndex];
                if (queueSnapshotToCompare.QueueName != queueSnapshot.QueueName)
                    return true;
                if (queueSnapshotToCompare.Requests.Count != queueSnapshot.Requests.Count)
                    return true;

                for (int requestIndex = 0; requestIndex < queueSnapshot.Requests.Count; requestIndex++)
                {
                    QueuedRequestSnapshot request = queueSnapshot.Requests[requestIndex];
                    QueuedRequestSnapshot requestToCompare = queueSnapshotToCompare.Requests[requestIndex];
                    if (requestToCompare.ProjectName != request.ProjectName)
                        return true;
                    if (requestToCompare.Activity != request.Activity)
                        return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Retrieves the status of a project.
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
    public ProjectStatus GetProjectStatus(string projectName)
    {
      foreach (ProjectStatus projectStatus in ProjectStatuses)
      {
        if (projectStatus.Name == projectName)
        {
          return projectStatus;
        }
      }
      return null;
    }
    
        /// <summary>
        /// Retrieves the hashcode for the snapshot.
        /// </summary>
        /// <returns></returns>
    public override int GetHashCode()
    {
      int hashCode = 0;
      unchecked {
        if (projectStatuses != null) hashCode += 1000000007 * projectStatuses.GetHashCode(); 
        if (queueSetSnapshot != null) hashCode += 1000000009 * queueSetSnapshot.GetHashCode(); 
      }
      return hashCode;
    }
      
        /// <summary>
        /// Compares two snapshots to see if they are equal.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
    public override bool Equals(object obj)
    {
      CruiseServerSnapshot other = obj as CruiseServerSnapshot;
      if (other == null) return false; 
      return object.Equals(this.projectStatuses, other.projectStatuses) && object.Equals(this.queueSetSnapshot, other.queueSetSnapshot);
    }
    
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.