Exemplo n.º 1
0
        /// <summary>
        /// Sends the command to the service.
        /// </summary>
        private static void ControlService(IAgentClient client, ServiceApp serviceApp, ServiceCommand command)
        {
            if (client == null)
            {
                return;
            }

            try
            {
                bool commandResult;
                lock (client)
                {
                    commandResult = client.ControlService(serviceApp, command, 0);
                }

                if (commandResult)
                {
                    ScadaUiUtils.ShowInfo(AppPhrases.ControlServiceSuccessful);
                }
                else
                {
                    ScadaUiUtils.ShowError(AppPhrases.UnableControlService);
                }
            }
            catch (Exception ex)
            {
                ScadaUiUtils.ShowError(ex.BuildErrorMessage(AppPhrases.ControlServiceError));
            }
        }
Exemplo n.º 2
0
 private void btnRestartServer_Click(object sender, EventArgs e)
 {
     // restart the Server service
     if (agentClient != null)
     {
         try {
             if (agentClient.ControlService(ServiceApp.Server, ServiceCommand.Restart))
             {
                 ScadaUiUtils.ShowInfo(AppPhrases.ServiceRestarted);
             }
             else
             {
                 ScadaUiUtils.ShowError(AppPhrases.UnableRestartService);
             }
         } catch (Exception ex) {
             appData.ProcError(ex, AppPhrases.ServiceRestartError);
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Sends the command to the service.
 /// </summary>
 private void ControlService(ServiceApp serviceApp, ServiceCommand command)
 {
     if (agentClient != null)
     {
         try
         {
             if (agentClient.ControlService(serviceApp, command))
             {
                 ScadaUiUtils.ShowInfo(AppPhrases.ServiceCommandComplete);
             }
             else
             {
                 ScadaUiUtils.ShowError(AppPhrases.UnableControlService);
             }
         }
         catch (Exception ex)
         {
             appData.ProcError(ex, AppPhrases.ControlServiceError);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Sends the command to the service.
        /// </summary>
        private void ControlService(ServiceApp serviceApp, ServiceCommand cmd)
        {
            string cmdFormat = cmd switch
            {
                ServiceCommand.Start => AdminPhrases.StartNamedService,
                ServiceCommand.Stop => AdminPhrases.StopNamedService,
                ServiceCommand.Restart => AdminPhrases.RestartNamedService,
                _ => throw new ScadaException("Unknown service control command.")
            };

            transferControl.ThrowIfCancellationRequested();
            transferControl.WriteMessage(string.Format(cmdFormat, ScadaUtils.GetAppName(serviceApp)));

            if (agentClient.ControlService(serviceApp, cmd, ProcessTimeout))
            {
                transferControl.WriteMessage(AdminPhrases.ServiceCommandCompleted);
            }
            else
            {
                transferControl.WriteError(AdminPhrases.ServiceCommandFailed);
            }
        }