Пример #1
0
        /// <summary>
        /// Reads the configuration database.
        /// </summary>
        public override bool ReadBase(out BaseDataSet baseDataSet)
        {
            // do not read the configuration database from the server that likely contains partial data
            if (deviceFilter != null)
            {
                baseDataSet = null;
                return(false);
            }

            string tableName = Locale.IsRussian ? "неопределена" : "undefined";

            try
            {
                log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                "Приём базы конфигурации" :
                                "Receive the configuration database");

                ScadaClient localClient = new ScadaClient(connOptions);
                baseDataSet = new BaseDataSet();

                foreach (IBaseTable baseTable in baseDataSet.AllTables)
                {
                    tableName = baseTable.Name;
                    localClient.DownloadBaseTable(baseTable);
                }

                localClient.TerminateSession();
                log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                "База конфигурации получена успешно" :
                                "The configuration database has been received successfully");
                return(true);
            }
            catch (Exception ex)
            {
                log.WriteException(ex, CommPhrases.DataSourceMessage, Code, string.Format(Locale.IsRussian ?
                                                                                          "Ошибка при приёме базы конфигурации, таблица {0}" :
                                                                                          "Error receiving the configuration database, the {0} table", tableName));
                baseDataSet = null;
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Reads the configuration database.
        /// </summary>
        public override bool ReadConfigDatabase(out ConfigDatabase configDatabase)
        {
            // do not read the configuration database from the server that likely contains partial data
            if (deviceFilter != null)
            {
                configDatabase = null;
                return(false);
            }

            log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                            "Приём базы конфигурации" :
                            "Receive the configuration database");

            // check connection
            ScadaClient localClient = new ScadaClient(connOptions);

            try
            {
                localClient.GetStatus(out bool serverIsReady, out bool userIsLoggedIn);

                if (!serverIsReady)
                {
                    localClient.TerminateSession();
                    log.WriteError(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                   "Сервер не готов" :
                                   "Server is not ready");
                    configDatabase = null;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                log.WriteError(ex.BuildErrorMessage(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                                    "Ошибка при проверке соединения с сервером" :
                                                    "Error checking server connection"));
                configDatabase = null;
                return(false);
            }

            // receive tables
            string tableName = CommonPhrases.UndefinedTable;

            try
            {
                configDatabase = new ConfigDatabase();

                foreach (IBaseTable baseTable in configDatabase.AllTables)
                {
                    tableName = baseTable.Name;
                    localClient.DownloadBaseTable(baseTable);
                }

                log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                "База конфигурации получена успешно" :
                                "The configuration database has been received successfully");
                return(true);
            }
            catch (Exception ex)
            {
                log.WriteError(ex, CommPhrases.DataSourceMessage, Code, string.Format(Locale.IsRussian ?
                                                                                      "Ошибка при приёме базы конфигурации, таблица {0}" :
                                                                                      "Error receiving the configuration database, the {0} table", tableName));
                configDatabase = null;
                return(false);
            }
            finally
            {
                localClient.TerminateSession();
            }
        }