Beispiel #1
0
        /// <summary>
        /// Creates a new instance of the Growl server.
        /// </summary>
        /// <param name="port">The port to listen on. The standard GNTP port is <see cref="ConnectorBase.TCP_PORT"/>.</param>
        /// <param name="passwordManager">The <see cref="PasswordManager"/> containing the list of allowed passwords.</param>
        /// <param name="userFolder">The full path to the user folder where logs, resource cache, and other files will be stored.</param>
        public GrowlServer(int port, PasswordManager passwordManager, string userFolder)
        {
            // this will set the server name and version properly
            ServerName = serverName;

            this.port = (ushort)port;

            this.passwordManager = passwordManager;

            this.userFolder = userFolder;

            this.logFolder = PathUtility.Combine(userFolder, @"Log\");
            PathUtility.EnsureDirectoryExists(this.logFolder);

            this.resourceFolder = PathUtility.Combine(userFolder, @"Resources\");
            PathUtility.EnsureDirectoryExists(this.resourceFolder);

            this.listenSocket = new AsyncSocket();
            this.listenSocket.AllowMultithreadedCallbacks = true; // VERY IMPORTANT: if we dont set this, async socket events will silently be swallowed by the AsyncSocket class
            listenSocket.DidAccept += new AsyncSocket.SocketDidAccept(listenSocket_DidAccept);
            //listenSocket.DidClose += new AsyncSocket.SocketDidClose(listenSocket_DidClose);

            // Initialize list to hold connected sockets
            // We support multiple concurrent connections
            connectedSockets            = new ConnectedSocketCollection();
            connectedHandlers           = new Dictionary <AsyncSocket, MessageHandler>();
            socketCleanupTimer          = new System.Timers.Timer(30 * 1000);
            socketCleanupTimer.Elapsed += new System.Timers.ElapsedEventHandler(socketCleanupTimer_Elapsed);

            ResourceCache.ResourceFolder = this.resourceFolder;
            ResourceCache.Enabled        = true;

            this.bonjour = new BonjourService(BonjourServiceName, BONJOUR_SERVICE_TYPE);
        }
Beispiel #2
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    Stop();

                    if (this.listenSocket != null)
                    {
                        this.listenSocket.DidAccept -= new AsyncSocket.SocketDidAccept(listenSocket_DidAccept);
                        this.listenSocket            = null;
                    }

                    if (this.socketCleanupTimer != null)
                    {
                        this.socketCleanupTimer.Elapsed -= new System.Timers.ElapsedEventHandler(socketCleanupTimer_Elapsed);
                        this.socketCleanupTimer.Close();
                        this.socketCleanupTimer.Dispose();
                        this.socketCleanupTimer = null;
                    }

                    if (this.bonjour != null)
                    {
                        this.bonjour.Stop();
                        this.bonjour.Dispose();
                        this.bonjour = null;
                    }
                }
                catch
                {
                    // suppress
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    Stop();

                    if (this.listenSocket != null)
                    {
                        this.listenSocket.DidAccept -= new AsyncSocket.SocketDidAccept(listenSocket_DidAccept);
                        this.listenSocket = null;
                    }

                    if (this.socketCleanupTimer != null)
                    {
                        this.socketCleanupTimer.Elapsed -= new System.Timers.ElapsedEventHandler(socketCleanupTimer_Elapsed);
                        this.socketCleanupTimer.Close();
                        this.socketCleanupTimer.Dispose();
                        this.socketCleanupTimer = null;
                    }

                    if (this.bonjour != null)
                    {
                        this.bonjour.Stop();
                        this.bonjour.Dispose();
                        this.bonjour = null;
                    }
                }
                catch
                {
                    // suppress
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance of the Growl server.
        /// </summary>
        /// <param name="port">The port to listen on. The standard GNTP port is <see cref="ConnectorBase.TCP_PORT"/>.</param>
        /// <param name="passwordManager">The <see cref="PasswordManager"/> containing the list of allowed passwords.</param>
        /// <param name="userFolder">The full path to the user folder where logs, resource cache, and other files will be stored.</param>
        public GrowlServer(int port, PasswordManager passwordManager, string userFolder)
        {
            // this will set the server name and version properly
            ServerName = serverName;

            this.port = (ushort) port;

            this.passwordManager = passwordManager;

            this.userFolder = userFolder;

            this.logFolder = PathUtility.Combine(userFolder, @"Log\");
            PathUtility.EnsureDirectoryExists(this.logFolder);

            this.resourceFolder = PathUtility.Combine(userFolder, @"Resources\");
            PathUtility.EnsureDirectoryExists(this.resourceFolder);

            this.listenSocket = new AsyncSocket();
            this.listenSocket.AllowMultithreadedCallbacks = true; // VERY IMPORTANT: if we dont set this, async socket events will silently be swallowed by the AsyncSocket class
            listenSocket.DidAccept += new AsyncSocket.SocketDidAccept(listenSocket_DidAccept);
            //listenSocket.DidClose += new AsyncSocket.SocketDidClose(listenSocket_DidClose);
 
            // Initialize list to hold connected sockets
            // We support multiple concurrent connections
            connectedSockets = new ConnectedSocketCollection();
            connectedHandlers = new Dictionary<AsyncSocket, MessageHandler>();
            socketCleanupTimer = new System.Timers.Timer(30 * 1000);
            socketCleanupTimer.Elapsed += new System.Timers.ElapsedEventHandler(socketCleanupTimer_Elapsed);

            ResourceCache.ResourceFolder = this.resourceFolder;
            ResourceCache.Enabled = true;

            this.bonjour = new BonjourService(BonjourServiceName, BONJOUR_SERVICE_TYPE);
        }