Example #1
0
        public bool Start()
        {
            bool started = false;

            this.gntpListener = new Growl.Daemon.GrowlServer(Growl.Connector.GrowlConnector.TCP_PORT, this.passwordManager, Utility.UserSettingFolder);
            this.gntpListener.RegisterReceived += new Growl.Daemon.GrowlServer.RegisterReceivedEventHandler(gntpListener_RegisterReceived);
            this.gntpListener.NotifyReceived += new Growl.Daemon.GrowlServer.NotifyReceivedEventHandler(gntpListener_NotifyReceived);
            this.gntpListener.SubscribeReceived += new Growl.Daemon.GrowlServer.SubscribeReceivedEventHandler(gntpListener_SubscribeReceived);
            this.gntpListener.LoggingEnabled = ApplicationMain.LoggingEnabled;
            this.gntpListener.AllowWebNotifications = Properties.Settings.Default.AllowWebNotifications;
            this.gntpListener.AllowNetworkNotifications = Properties.Settings.Default.AllowNetworkNotifications;
            this.gntpListener.AllowSubscriptions = Properties.Settings.Default.AllowSubscriptions;
            this.gntpListener.RequireLocalPassword = Properties.Settings.Default.RequireLocalPassword;
            this.gntpListener.RequireLANPassword = Properties.Settings.Default.RequireLANPassword;
            started = this.gntpListener.Start();
            if (!started)
            {
                this.OnFailedToStart(this, new PortConflictEventArgs(Growl.Connector.GrowlConnector.TCP_PORT));
                return false;
            }

            // this starts the legacy UDP listeners. it can be disabled via user.config if necessary
            if (!Properties.Settings.Default.DisableLegacySupport)
            {
                string udpLogFolder = Growl.CoreLibrary.PathUtility.Combine(Utility.UserSettingFolder, @"Log\");

                // this is for network UDP requests (old Growl network protocol)
                this.udpListener = new Growl.UDPLegacy.MessageReceiver(Growl.UDPLegacy.MessageReceiver.NETWORK_PORT, this.passwordManager, ApplicationMain.LoggingEnabled, udpLogFolder);
                this.udpListener.RegistrationReceived += new Growl.UDPLegacy.MessageReceiver.RegistrationHandler(udpListener_RegistrationReceived);
                this.udpListener.NotificationReceived += new Growl.UDPLegacy.MessageReceiver.NotificationHandler(udpListener_NotificationReceived);
                this.udpListener.AllowNetworkNotifications = Properties.Settings.Default.AllowNetworkNotifications;
                this.udpListener.RequireLocalPassword = Properties.Settings.Default.RequireLocalPassword;
                this.udpListener.RequireLANPassword = Properties.Settings.Default.RequireLANPassword;
                started = this.udpListener.Start();
                if (!started)
                {
                    if (this.gntpListener != null) this.gntpListener.Stop();    // stop the GNTP listener if it was already started
                    this.OnFailedToStartUDPLegacy(this, new PortConflictEventArgs(Growl.UDPLegacy.MessageReceiver.NETWORK_PORT));
                    return false;
                }

                // this is for local UDP requests (old GFW local protocol)
                this.udpListenerLocal = new Growl.UDPLegacy.MessageReceiver(Growl.UDPLegacy.MessageReceiver.LOCAL_PORT, this.passwordManager, ApplicationMain.LoggingEnabled, udpLogFolder);
                this.udpListenerLocal.RegistrationReceived += new Growl.UDPLegacy.MessageReceiver.RegistrationHandler(udpListener_RegistrationReceived);
                this.udpListenerLocal.NotificationReceived += new Growl.UDPLegacy.MessageReceiver.NotificationHandler(udpListener_NotificationReceived);
                this.udpListenerLocal.AllowNetworkNotifications = false;    // always false
                this.udpListenerLocal.RequireLocalPassword = Properties.Settings.Default.RequireLocalPassword;
                this.udpListenerLocal.RequireLANPassword = Properties.Settings.Default.RequireLANPassword;
                started = this.udpListenerLocal.Start();
                if (!started)
                {
                    if (this.gntpListener != null) this.gntpListener.Stop();    // stop the GNTP listener if it was already started
                    if (this.udpListener != null) this.udpListener.Stop();      // stop the network UDP listener if it was already started
                    this.OnFailedToStartUDPLegacy(this, new PortConflictEventArgs(Growl.UDPLegacy.MessageReceiver.NETWORK_PORT));
                    return false;
                }
            }

            this.isRunning = true;

            bool createdNew = true;
            this.mutex = new Mutex(true, String.Format(@"Global\{0}", Growl.CoreLibrary.Detector.MUTEX_NAME), out createdNew);

            this.isStarted = started;
            OnStarted();

            TimeSpan ts = DateTime.Now - ApplicationMain.st;
            Utility.WriteDebugInfo("FINAL LOAD TIME: {0}", ts.TotalSeconds);

            // send a notification that growl is running
            if (!ApplicationMain.SilentMode)
                SendSystemNotification(Properties.Resources.SystemNotification_Running_Title, Properties.Resources.SystemNotification_Running_Text);

            StartActivityMonitor();

            return true;
        }
Example #2
0
        public void Stop()
        {
            this.isStarted = false;
            this.isRunning = false;

            StopActivityMonitor();

            if (this.mutex != null)
            {
                try
                {
                    this.mutex.ReleaseMutex();
                    this.mutex.Close();
                    this.mutex = null;
                }
                catch
                {
                }
            }

            if (this.gntpListener != null)
            {
                this.gntpListener.Stop();
                this.gntpListener.Dispose();
                this.gntpListener = null;
            }
            if (this.udpListener != null)
            {
                this.udpListener.Stop();
                this.udpListener.Dispose();
                this.udpListener = null;
            }
            if (this.udpListenerLocal != null)
            {
                this.udpListenerLocal.Stop();
                this.udpListenerLocal.Dispose();
                this.udpListenerLocal = null;
            }

            SaveAppState();

            OnStopped();
        }
Example #3
0
        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    if (this.mutex != null)
                    {
                        try
                        {
                            this.mutex.ReleaseMutex();
                            this.mutex.Close();
                            this.mutex = null;
                        }
                        catch
                        {
                        }
                    }

                    DisplayStyleManager.DisplayLoaded -= new DisplayStyleManager.DisplayLoadedEventHandler(DisplayStyleManager_DisplayLoaded);

                    if (this.bonjour != null)
                    {
                        this.bonjour.ServiceFound -= new Bonjour.NetServiceFoundEventHandler(bonjour_ServiceFound);
                        this.bonjour.ServiceRemoved -= new Bonjour.NetServiceRemovedEventHandler(bonjour_ServiceRemoved);
                        this.bonjour.Stop();
                        this.bonjour.Dispose();
                        this.bonjour = null;
                    }

                    if (this.activityMonitor != null)
                    {
                        this.activityMonitor.WentIdle -= new ActivityMonitor.ActivityMonitorEventHandler(activityMonitor_WentIdle);
                        this.activityMonitor.ResumedActivity -= new ActivityMonitor.ActivityMonitorEventHandler(activityMonitor_ResumedActivity);
                        this.activityMonitor.StillActive -= new EventHandler(activityMonitor_StillActive);
                        this.activityMonitor.Dispose();
                        this.activityMonitor = null;
                    }

                    if (this.gntpListener != null)
                    {
                        this.gntpListener.RegisterReceived -= new Growl.Daemon.GrowlServer.RegisterReceivedEventHandler(gntpListener_RegisterReceived);
                        this.gntpListener.NotifyReceived -= new Growl.Daemon.GrowlServer.NotifyReceivedEventHandler(gntpListener_NotifyReceived);
                        this.gntpListener.SubscribeReceived -= new Growl.Daemon.GrowlServer.SubscribeReceivedEventHandler(gntpListener_SubscribeReceived);
                        this.gntpListener.Dispose();
                        this.gntpListener = null;
                    }

                    if (this.udpListener != null)
                    {
                        this.udpListener.RegistrationReceived -= new Growl.UDPLegacy.MessageReceiver.RegistrationHandler(udpListener_RegistrationReceived);
                        this.udpListener.NotificationReceived -= new Growl.UDPLegacy.MessageReceiver.NotificationHandler(udpListener_NotificationReceived);
                        this.udpListener.Dispose();
                        this.udpListener = null;
                    }

                    if (this.udpListenerLocal != null)
                    {
                        this.udpListenerLocal.RegistrationReceived -= new Growl.UDPLegacy.MessageReceiver.RegistrationHandler(udpListener_RegistrationReceived);
                        this.udpListenerLocal.NotificationReceived -= new Growl.UDPLegacy.MessageReceiver.NotificationHandler(udpListener_NotificationReceived);
                        this.udpListenerLocal.Dispose();
                        this.udpListenerLocal = null;
                    }

                    if (this.subscriptions != null)
                    {
                        foreach (Subscription subscription in this.subscriptions.Values)
                        {
                            subscription.StatusChanged -= new Subscription.SubscriptionStatusChangedEventHandler(subscription_StatusChanged);
                        }
                    }

                    if (this.forwards != null)
                    {
                        foreach (ForwardDestination fd in this.forwards.Values)
                        {
                            SubscribedForwardDestination sfd = fd as SubscribedForwardDestination;
                            if(sfd != null)
                                sfd.Unsubscribed -= new SubscribedForwardDestination.SubscribingComputerUnscubscribedEventHandler(sfc_Unsubscribed);
                        }
                    }

                    if (DisplayStyleManager.AvailableDisplayStyles != null)
                    {
                        foreach (Display display in DisplayStyleManager.AvailableDisplayStyles.Values)
                        {
                            display.NotificationCallback -= new Display.NotificationCallbackEventHandler(display_NotificationCallback);
                        }
                    }
                }
                this.disposed = true;
            }
        }