Ejemplo n.º 1
0
        private void Refresh()
        {
            try
            {
                var status = LocalServiceProcess.GetStatus();
                StartEnabled = status == ServiceControllerStatus.Stopped;
                StopEnabled  = status == ServiceControllerStatus.Running;

                StartTimer();
            }
            catch (InvalidOperationException)
            {
                OnUnknownService();
            }
            catch (Exception e)
            {
                OnUnknownError(e);
            }
        }
Ejemplo n.º 2
0
        private void ControlService(ServiceControlOperation operation)
        {
            try
            {
                switch (operation)
                {
                case ServiceControlOperation.Start:
                    LocalServiceProcess.Start();
                    break;

                case ServiceControlOperation.Stop:
                    LocalServiceProcess.Stop();
                    break;

                case ServiceControlOperation.Restart:
                    LocalServiceProcess.Restart();
                    break;
                }
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Info, e, "Failed to {0} service '{1}'.", operation.ToString().ToLower(), LocalServiceProcess.Name);

                if (LocalServiceProcess.IsAccessDeniedError(e))
                {
                    Context.DesktopWindow.ShowMessageBox(SR.MessageControlServiceAccessDenied, MessageBoxActions.Ok);
                }
                else if (e is TimeoutException)
                {
                    Context.DesktopWindow.ShowMessageBox(SR.MessageControlServiceTimeout, MessageBoxActions.Ok);
                }
                else
                {
                    Context.DesktopWindow.ShowMessageBox(SR.MessageFailedToStartService, MessageBoxActions.Ok);
                }
            }

            Refresh();
        }