/// <summary> /// Stop the http listener. /// </summary> public void Stop() { try { // Stop the service. _running = false; if (_listener != null) { _listener.Stop(); } } catch (Exception ex) { // Log the error. LogHandler.WriteTypeMessage( ex.Message, MethodInfo.GetCurrentMethod(), Nequeo.Net.Common.Helper.EventApplicationName); } finally { _listener = null; } }
/// <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 override void Dispose(bool disposing) { base.Dispose(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 (_listener != null) { _listener.Dispose(); } } // Call the appropriate methods to clean up // unmanaged resources here. _listener = null; } }
/// <summary> /// Start the http listener. /// </summary> /// <exception cref="System.ArgumentNullException">Thrown when the urlBaseAddress parameter is missing.</exception> /// <exception cref="System.ArgumentNullException">Thrown when the localBaseDirectory parameter is missing.</exception> public void Start() { // If the server is already running. if (_running) { return; } bool ret = false; try { // Make sure the url base address is set. if (System.String.IsNullOrEmpty(_urlBaseAddress)) { throw new ArgumentNullException("urlBaseAddress"); } // Make sure the local base directory is set. if (System.String.IsNullOrEmpty(_localBaseDirectory)) { throw new ArgumentNullException("localBaseDirectory"); } // Create a new http listener _listener = new Nequeo.Net.Server.HttpServer(_urlBaseAddress, _localBaseDirectory); // Get the mime types _contextMimeType = ReaderHttp.GetMimeType(); // Initialise the listener if (!_initialized) { ret = _listener.Initialize(); _initialized = ret; } // Start the listener if (ret) { ret = _listener.Start(); } // Assign the running indicator. if (ret) { _running = true; } } catch (Exception ex) { // Log the error. LogHandler.WriteTypeMessage( ex.Message, MethodInfo.GetCurrentMethod(), Nequeo.Net.Common.Helper.EventApplicationName); // Stop the http listener. Stop(); } }