Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates and fills the application dictionary.
        /// </summary>
        private void CreateAppTable()
        {
            transferControl.ThrowIfCancellationRequested();
            transferControl.WriteMessage(ExtensionPhrases.CreateAppDict);
            NpgsqlTransaction trans = null;

            try
            {
                trans = conn.BeginTransaction();
                new NpgsqlCommand(GetAppTableDDL(), conn, trans).ExecuteNonQuery();

                string sql = $"INSERT INTO {Schema}.app (app_id, name) VALUES (@appID, @name) " +
                             "ON CONFLICT (app_id) DO NOTHING";
                NpgsqlCommand   insertCmd  = new(sql, conn, trans);
                NpgsqlParameter appIdParam = insertCmd.Parameters.Add("appID", NpgsqlDbType.Integer);
                NpgsqlParameter nameParam  = insertCmd.Parameters.Add("name", NpgsqlDbType.Varchar);

                foreach (ServiceApp app in Enum.GetValues(typeof(ServiceApp)))
                {
                    if (app != ServiceApp.Unknown)
                    {
                        appIdParam.Value = (int)app;
                        nameParam.Value  = ScadaUtils.GetAppName(app);
                        insertCmd.ExecuteNonQuery();
                    }
                }

                trans.Commit();
                progressTracker.TaskIndex++;
            }
            catch
            {
                trans?.Rollback();
                throw;
            }
        }