/// <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 (_udpServer != null) { _udpServer.Dispose(); } if (_syslogList != null) { _syslogList.Clear(); } // Close all files. CloseFiles(); } // Call the appropriate methods to clean up // unmanaged resources here. _server = null; _udpServer = null; _syslogList = null; _syslogFiles = null; _writeLogLock = null; } }
/// <summary> /// Start the server. /// </summary> public void Start() { try { // Start the server. if (_server != null) { _server.Start(); } // Start the server. if (_udpServer != null) { _udpServer.Start(); } } catch (Exception) { // Close all files. CloseFiles(); if (_server != null) { _server.Dispose(); } if (_udpServer != null) { _udpServer.Dispose(); } _server = null; _udpServer = null; throw; } }
/// <summary> /// Stop the server. /// </summary> public void Stop() { try { // Close all files. CloseFiles(); // Stop the server. if (_server != null) { _server.Stop(); } // Stop the server. if (_udpServer != null) { _udpServer.Stop(); } } catch { } finally { if (_server != null) { _server.Dispose(); } if (_udpServer != null) { _udpServer.Dispose(); } _server = null; _udpServer = null; } }
/// <summary> /// Initialise the server. /// </summary> private void Init() { try { string socketProviderHostPrefix = "SyslogServerSingle_"; string hostProviderFullName = socketProviderHostPrefix + "SocketProviderV6"; // 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 syslog context list. _syslogList = new ConcurrentDictionary <string, SyslogContext>(); _syslogFiles = new ConcurrentDictionary <short, Stream>(); // Open or create the log files. OpenFiles(Message.SyslogUtility.GetPriorities()); // 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 } }, }; // Start the server. _server = new Nequeo.Net.ServerSingle(model, _maxClient); _server.OnContext += Server_OnContext; _server.Servers.OnClientDisconnected = (Provider.ISingleContextBase context) => Server_OnDisconnected(context); // Start the server. _udpServer = new Nequeo.Net.UdpServer(model, _maxClient); _udpServer.OnContext += Server_OnContext; _udpServer.Servers.OnClientDisconnected = (Nequeo.Net.Sockets.IUdpServerContext context) => ServerUdp_OnDisconnected(context); } catch (Exception) { // Close all files. CloseFiles(); if (_server != null) { _server.Dispose(); } if (_udpServer != null) { _udpServer.Dispose(); } _server = null; _udpServer = null; throw; } }