Пример #1
0
        /// <summary>
        /// Start the server.
        /// </summary>
        public void Start()
        {
            try
            {
                // Start the server.
                if (_server != null)
                {
                    _server.Start();
                }
            }
            catch (Exception)
            {
                if (_server != null)
                {
                    _server.Dispose();
                }

                if (_appHostDomain != null)
                {
                    _appHostDomain.Dispose();
                }

                _server        = null;
                _appHostDomain = null;
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.  If disposing
        /// equals true, the method has been called directly or indirectly by a user's
        /// code. Managed and unmanaged resources can be disposed.  If disposing equals
        /// false, the method has been called by the runtime from inside the finalizer
        /// and you should not reference other objects. Only unmanaged resources can
        /// be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    if (_server != null)
                    {
                        _server.Dispose();
                    }

                    if (_appHostDomain != null)
                    {
                        _appHostDomain.Dispose();
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _server        = null;
                _appHostDomain = null;
            }
        }
Пример #3
0
        /// <summary>
        /// Stop the server.
        /// </summary>
        public void Stop()
        {
            try
            {
                // Stop the server.
                if (_server != null)
                {
                    _server.Stop();
                }
            }
            catch { }
            finally
            {
                if (_server != null)
                {
                    _server.Dispose();
                }

                if (_appHostDomain != null)
                {
                    _appHostDomain.Dispose();
                }

                _server        = null;
                _appHostDomain = null;
            }
        }
Пример #4
0
        /// <summary>
        /// Initialise the server.
        /// </summary>
        private void Init()
        {
            try
            {
                // Create application host domain.
                _appHostDomain = new AppHostDomain(_basePath, _virtualDir, _configurationFile);

                string socketProviderHostPrefix   = "HttpDynamicServerSingle_";
                string hostProviderFullName       = socketProviderHostPrefix + "SocketProviderV6";
                string hostProviderFullNameSecure = socketProviderHostPrefix + "SocketProviderV6Ssl";

                // Get the certificate reader.
                Nequeo.Security.Configuration.Reader certificateReader = new Nequeo.Security.Configuration.Reader();
                Nequeo.Net.Configuration.Reader      hostReader        = new Nequeo.Net.Configuration.Reader();

                // Create the server endpoint.
                Nequeo.Net.Sockets.MultiEndpointModel[] model = new Nequeo.Net.Sockets.MultiEndpointModel[]
                {
                    // None secure.
                    new Nequeo.Net.Sockets.MultiEndpointModel()
                    {
                        Port      = hostReader.GetServerHost(hostProviderFullName).Port,
                        Addresses = new System.Net.IPAddress[]
                        {
                            System.Net.IPAddress.IPv6Any,
                            System.Net.IPAddress.Any
                        }
                    },
                    // Secure.
                    new Nequeo.Net.Sockets.MultiEndpointModel()
                    {
                        Port      = hostReader.GetServerHost(hostProviderFullNameSecure).Port,
                        Addresses = new System.Net.IPAddress[]
                        {
                            System.Net.IPAddress.IPv6Any,
                            System.Net.IPAddress.Any
                        }
                    }
                };

                // Start the server.
                _server                   = new Nequeo.Net.Http.HttpServerSingle(model, hostReader.GetServerHost(hostProviderFullName).MaxNumClients);
                _server.Name              = "Application Server";
                _server.OnHttpContext    += HttpContext;
                _server.OnClientConnected = (context) => ClientConnected(context);
                _server.Timeout           = hostReader.GetServerHost(hostProviderFullName).ClientTimeOut;
                _server.ReadBufferSize    = 32768;
                _server.WriteBufferSize   = 32768;

                // Inititalise.
                _server.Initialisation();

                try
                {
                    // Look for the certificate information in the configuration file.

                    // Get the certificate if any.
                    X509Certificate2 serverCertificate = certificateReader.GetServerCredentials();

                    // If a certificate exists.
                    if (serverCertificate != null)
                    {
                        // Get the secure servers.
                        _server.Server[2].UseSslConnection = true;
                        _server.Server[2].X509Certificate  = serverCertificate;
                        _server.Server[3].UseSslConnection = true;
                        _server.Server[3].X509Certificate  = serverCertificate;
                    }
                }
                catch { }

                // Create the application host.
                _appHostDomain.CreateApplicationHost();
            }
            catch (Exception)
            {
                if (_server != null)
                {
                    _server.Dispose();
                }

                if (_appHostDomain != null)
                {
                    _appHostDomain.Dispose();
                }

                _server        = null;
                _appHostDomain = null;
                throw;
            }
        }