Exemplo n.º 1
0
        /// <summary>
        /// Downloads the configuration database.
        /// </summary>
        private void DownloadBase()
        {
            transferControl.ThrowIfCancellationRequested();
            transferControl.WriteLine();
            transferControl.WriteMessage(AdminPhrases.DownloadBase);

            GetTempFileName(out string tempFileName, out string extractDir);
            agentClient.DownloadConfig(tempFileName, TopFolder.Base);
            ExtractArchive(tempFileName, extractDir, false);

            foreach (IBaseTable baseTable in project.ConfigDatabase.AllTables)
            {
                transferControl.ThrowIfCancellationRequested();
                transferControl.WriteMessage(string.Format(ExtensionPhrases.ImportTable, baseTable.Name));
                string datFileName = Path.Combine(extractDir, "BaseDAT", baseTable.FileNameDat);

                if (File.Exists(datFileName))
                {
                    BaseTableAdapter baseAdapter = new() { FileName = datFileName };
                    IBaseTable       srcTable    = BaseTableFactory.GetBaseTable(baseTable);
                    baseAdapter.Fill(srcTable);
                    baseTable.Modified = true;

                    foreach (object item in srcTable.EnumerateItems())
                    {
                        baseTable.AddObject(item);
                    }
                }
            }

            progressTracker.TaskIndex++;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Downloads the configuration database.
        /// </summary>
        private void DownloadBase()
        {
            transferControl.ThrowIfCancellationRequested();
            transferControl.WriteLine();
            transferControl.WriteMessage(AdminPhrases.DownloadBase);
            progressTracker.SubtaskCount = project.ConfigDatabase.AllTables.Length;

            foreach (IBaseTable baseTable in project.ConfigDatabase.AllTables)
            {
                transferControl.ThrowIfCancellationRequested();
                transferControl.WriteMessage(string.Format(ExtensionPhrases.DownloadTable, baseTable.Name));
                ReadBaseTable(baseTable, conn);
                progressTracker.SubtaskIndex++;
            }

            progressTracker.TaskIndex++;
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a database schema.
        /// </summary>
        private void CreateSchema()
        {
            transferControl.ThrowIfCancellationRequested();
            transferControl.WriteMessage(ExtensionPhrases.CreateSchema);

            string sql = "CREATE SCHEMA IF NOT EXISTS " + Schema;

            new NpgsqlCommand(sql, conn).ExecuteNonQuery();
            progressTracker.TaskIndex++;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Tests the connection with the Agent service.
        /// </summary>
        private void TestAgentConnection(IAgentClient agentClient)
        {
            transferControl.WriteMessage(ExtensionPhrases.TestAgentConn);

            if (!agentClient.TestConnection(out string errMsg))
            {
                throw new ScadaException(errMsg);
            }

            progressTracker.TaskIndex++;
        }