コード例 #1
0
        void HandleServiceEnabling(bool enable, bool shouldUpdateApiFlag)
        {
            var beforeArgs = new ServiceBeforeEventArgs();

            OnServiceBeforeEvent(enable, beforeArgs);
            if (beforeArgs.operationCancelled)
            {
                return;
            }
            try
            {
                InternalEnableService(enable, shouldUpdateApiFlag);
            }
            catch (Exception ex)
            {
                NotificationManager.instance.Publish(notificationTopic, Notification.Severity.Error,
                                                     enable ? string.Format(k_EnableServiceFailedMessage, title, ex.Message)
                    : string.Format(k_DisableServiceFailedMessage, title, ex.Message));
                return;
            }


            try
            {
                OnServiceAfterEvent(enable, new EventArgs());
            }
            catch (Exception ex)
            {
                //Here report exception and swallow it: at this point the service was toggled successfully, but actors that acted afterward may have had issue.
                //It is their responsibility to handle things correctly
                NotificationManager.instance.Publish(notificationTopic, Notification.Severity.Error,
                                                     enable ? string.Format(k_AfterEnableExceptionMessage, title, ex.Message)
                    : string.Format(k_AfterDisableExceptionMessage, title, ex.Message));
            }
        }
コード例 #2
0
        void OnServiceBeforeEvent(bool enabled, ServiceBeforeEventArgs beforeArgs)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribe
            // immediately after the null check and before the event is raised.
            var handler = enabled ? serviceBeforeEnableEvent : serviceBeforeDisableEvent;

            // Event will be null if there are no subscribers
            handler?.Invoke(this, beforeArgs);
        }
コード例 #3
0
        void HandleServiceEnabling(bool enable)
        {
            var beforeArgs = new ServiceBeforeEventArgs();

            OnServiceBeforeEvent(enable, beforeArgs);
            if (beforeArgs.operationCancelled)
            {
                return;
            }
            try
            {
                InternalEnableService(enable);
            }
            catch (Exception ex)
            {
                NotificationManager.instance.Publish(notificationTopic, Notification.Severity.Error,
                                                     enable ? string.Format(k_EnableServiceFailedMessage, title, ex.Message)
                    : string.Format(k_DisableServiceFailedMessage, title, ex.Message));
                return;
            }

            // The ServicesEditorWindow instance can be null if the window is closed.
            var servicesEditorWindow = ServicesEditorWindow.instance;

            if (servicesEditorWindow != null)
            {
                servicesEditorWindow.SetServiceStatusValue(name, enable);
            }

            try
            {
                OnServiceAfterEvent(enable, new EventArgs());
            }
            catch (Exception ex)
            {
                //Here report exception and swallow it: at this point the service was toggled successfully, but actors that acted afterward may have had issue.
                //It is their responsibility to handle things correctly
                NotificationManager.instance.Publish(notificationTopic, Notification.Severity.Error,
                                                     enable ? string.Format(k_AfterEnableExceptionMessage, title, ex.Message)
                    : string.Format(k_AfterDisableExceptionMessage, title, ex.Message));
            }
        }