HttpCruiseServerManager.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » Monitoring » 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 » Monitoring » HttpCruiseServerManager.cs
using System;
using System.Collections.Specialized;
using System.Xml;
using ThoughtWorks.CruiseControl.CCTrayLib.Configuration;
using ThoughtWorks.CruiseControl.Remote;
using ThoughtWorks.CruiseControl.Remote.Messages;

namespace ThoughtWorks.CruiseControl.CCTrayLib.Monitoring{
  public class HttpCruiseServerManager : ICruiseServerManager
  {
        private readonly CruiseServerClientBase manager;
        private readonly BuildServer configuration;
    private readonly string displayName;
        private string sessionToken;

        public HttpCruiseServerManager(CruiseServerClientBase manager, 
      BuildServer buildServer)
    {
            this.manager = manager;
            this.configuration = buildServer;
      displayName = GetDisplayNameFromUri(buildServer.Uri);
    }

        public BuildServer Configuration
    {
            get { return configuration; }
    }

        public string SessionToken
        {
            get { return sessionToken; }
        }

    public string DisplayName
    {
      get { return displayName; }
    }

    public void CancelPendingRequest(string projectName)
    {
      throw new NotImplementedException("Cancel pending not currently supported on servers monitored via HTTP");
    }

    /// <summary>
    /// Gets the projects and integration queues snapshot from this server.
    /// </summary>
        public CruiseServerSnapshot GetCruiseServerSnapshot()
        {
            // Question - what should happen if we get a System.Net.WebException (timeout) here?
            // I frequently see these when querying a CruiseControl.java instance.
            try
            {
                var snapshot = manager.GetCruiseServerSnapshot();
                return snapshot;
            }
            catch (System.Net.WebException)
            {
                return new CruiseServerSnapshot();
            }
        }


        /// <summary>
        /// Gets the list of projects.
        /// </summary>
        /// <returns>The available projects on the server.</returns>
        public CCTrayProject[] GetProjectList()
        {
            ProjectStatus[] statuses = manager.GetProjectStatus();
            CCTrayProject[] projects = new CCTrayProject[statuses.Length];

            for (int i = 0; i < statuses.Length; i++)
            {
                ProjectStatus status = statuses[i];
                projects[i] = new CCTrayProject(this.configuration, status.Name);
            }

            return projects;
        }

    private static string GetDisplayNameFromUri(Uri uri)
    {
      const int DefaultHttpPort = 80;
      // TODO: The BuildServer.DisplayName property is coded such that it only strips out the server
      // name if it is a remoting connection, not an http one.
      // Rather than changing this behaviour in case it is seen as "desirable" the functionality is
      // implemented within here so that the server queues treeview can just display the server name.
      if (uri.Port == DefaultHttpPort)
        return uri.Host;

      return uri.Host + ":" + uri.Port;
    }

        public bool Login()
        {
            if (configuration.SecurityType != null)
            {
                if (sessionToken != null) Logout();
                IAuthenticationMode authentication = ExtensionHelpers.RetrieveAuthenticationMode(configuration.SecurityType);
                authentication.Settings = configuration.SecuritySettings;

                var request = authentication.GenerateCredentials();
                if (manager.Login(request.Credentials))
                {
                    sessionToken = manager.SessionToken;
                }
                else
                {
                    sessionToken = null;
                }

                return (sessionToken != null);
            }
            else
            {
                return true;
            }
        }

        public void Logout()
        {
            if (sessionToken != null)
            {
                manager.Logout();
                sessionToken = null;
            }
        }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.