WcfServerExtension.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Extensions » 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 » Extensions » WcfServerExtension.cs
using System;
using System.ServiceModel;
using ThoughtWorks.CruiseControl.Core.Util;
using ThoughtWorks.CruiseControl.Remote;

namespace ThoughtWorks.CruiseControl.Core.Extensions{
    /// <summary>
    /// This class extends CruiseServer and provides a WCF interface to it.
    /// </summary>
    public class WcfServerExtension
        : ICruiseServerExtension, IDisposable
    {
        #region Private fields
        private ServiceHost wcfServiceHost;
        private ICruiseServer cruiseServer;
        #endregion

        #region Public properties
        #region IsRunning
        /// <summary>
        /// Gets whether the service is currently listening for requests.
        /// </summary>
        public bool IsRunning
        {
            get { return (wcfServiceHost.State == CommunicationState.Opened); }
        }
        #endregion
        #endregion

        #region Public methods
        #region Initialise()
        /// <summary>
        /// Initialises the service host to use.
        /// </summary>
        /// <param name="server">The CruiseServer that is initialising this extension.</param>
        /// <param name="extensionConfig">The configuration for the extension.</param>
        public void Initialise(ICruiseServer server, ExtensionConfiguration extensionConfig)
        {
            // Validate the input parameters
            if (server == null) throw new ArgumentNullException("server");

            // Store the parameters that we need for later
            cruiseServer = server;

            // Create a new service host
            wcfServiceHost = new ServiceHost(new CruiseControlImplementation(cruiseServer));
        }
        #endregion

        #region Start()
        /// <summary>
        /// Starts listening for WCF requests.
        /// </summary>
        public void Start()
        {
            // Start the service host
            if ((wcfServiceHost.State != CommunicationState.Opened) &&
                (wcfServiceHost.State != CommunicationState.Opening))
            {
                Log.Info("Opening service host");
                wcfServiceHost.Open();
                Log.Debug("Service host opened");
            }
        }
        #endregion

        #region Stop()
        /// <summary>
        /// Stops listening for WCF requests.
        /// </summary>
        public void Stop()
        {
            // Stop the service host without waiting
            if ((wcfServiceHost.State != CommunicationState.Closed) &&
                (wcfServiceHost.State != CommunicationState.Closing) &&
                (wcfServiceHost.State != CommunicationState.Faulted))
            {
                Log.Info("Closing service host");
                wcfServiceHost.Close();
                Log.Debug("Service host closed");
            }
        }
        #endregion

        #region Abort()
        /// <summary>
        /// Stops listening for WCF requests.
        /// </summary>
        public void Abort()
        {
            // Stop the service host and wait for it to close
            if ((wcfServiceHost.State != CommunicationState.Closed) &&
                (wcfServiceHost.State != CommunicationState.Closing) &&
                (wcfServiceHost.State != CommunicationState.Faulted))
            {
                Log.Info("Aborting service host");
                wcfServiceHost.Abort();
                Log.Debug("Service host aborted");
            }
        }
        #endregion

        #region Dispose()
        /// <summary>
        /// Make sure everything is closed.
        /// </summary>
        public void Dispose()
        {
            Abort();
        }
        #endregion
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.