/// <summary> /// Receives the configuration database subset from Server. /// </summary> private bool ReceiveConfigBase(out ConfigBaseSubset configBase) { configBase = new ConfigBaseSubset(); if (ServerComm.ReceiveBaseTable("incnl.dat", configBase.InCnlTable) && ServerComm.ReceiveBaseTable("kp.dat", configBase.KPTable)) { return(true); } else { configBase = null; return(false); } }
/// <summary> /// Принять таблицу входных каналов и таблицу КП от SCADA-Сервера /// </summary> private bool ReceiveBaseTables(out DataTable tblInCnl, out DataTable tblKP) { tblInCnl = new DataTable(); tblKP = new DataTable(); if (ServerComm.ReceiveBaseTable("incnl.dat", tblInCnl) && ServerComm.ReceiveBaseTable("kp.dat", tblKP)) { return(true); } else { tblInCnl = null; tblKP = null; return(false); } }
/// <summary> /// Обновить таблицы базы конфигурации, свойства каналов и статусов /// </summary> public void RefreshBaseTables() { lock (baseLock) { try { DateTime utcNowDT = DateTime.UtcNow; if (utcNowDT - baseRefrDT > BaseValidSpan) // данные устарели { baseRefrDT = utcNowDT; DateTime newBaseAge = serverComm.ReceiveFileAge(ServerComm.Dirs.BaseDAT, BaseTables.GetFileName(BaseTables.InCnlTable)); if (newBaseAge == DateTime.MinValue) // база конфигурации не существует или нет связи с сервером { throw new ScadaException(Localization.UseRussian ? "Не удалось принять время изменения базы конфигурации." : "Unable to receive the configuration database modification time."); } else if (BaseTables.BaseAge != newBaseAge) // база конфигурации изменена { log.WriteAction(Localization.UseRussian ? "Обновление таблиц базы конфигурации" : "Refresh the tables of the configuration database"); // ожидание снятия возможной блокировки базы конфигурации DateTime t0 = utcNowDT; while (serverComm.ReceiveFileAge(ServerComm.Dirs.BaseDAT, "baselock") > DateTime.MinValue && DateTime.UtcNow - t0 <= WaitBaseLock) { Thread.Sleep(ScadaUtils.ThreadDelay); } // загрузка данных в таблицы BaseTables newBaseTables = new BaseTables() { BaseAge = newBaseAge }; foreach (DataTable dataTable in newBaseTables.AllTables) { string tableName = BaseTables.GetFileName(dataTable); if (!serverComm.ReceiveBaseTable(tableName, dataTable)) { throw new ScadaException(string.Format(Localization.UseRussian ? "Не удалось принять таблицу {0}" : "Unable to receive the table {0}", tableName)); } } BaseTables = newBaseTables; // заполнение свойств каналов и статусов lock (BaseTables.SyncRoot) { FillCnlProps(); FillCtrlCnlProps(); FillCnlStatProps(); } } } } catch (Exception ex) { BaseTables.BaseAge = DateTime.MinValue; log.WriteException(ex, Localization.UseRussian ? "Ошибка при обновлении таблиц базы конфигурации" : "Error refreshing the tables of the configuration database"); } } }
/// <summary> /// Update configuration database tables, channel properties and statuses /// </summary> public void RefreshBaseTables() { lock (baseLock) { try { var utcNowDT = DateTime.UtcNow; if (utcNowDT - baseRefrDT > BaseValidSpan) // data is out of date { baseRefrDT = utcNowDT; var newBaseAge = serverComm.ReceiveFileAge(ServerComm.Dirs.BaseDAT, BaseTables.GetFileName(BaseTables.InCnlTable)); if (newBaseAge == DateTime.MinValue) { // configuration database does not exist or there is no connection to the server throw new ScadaException("Unable to receive the configuration database modification time."); } if (BaseTables.BaseAge != newBaseAge) // configuration base changed { log.WriteAction("Refresh the tables of the configuration database"); // waiting for unlocking possible configuration base var t0 = utcNowDT; while (serverComm.ReceiveFileAge(ServerComm.Dirs.BaseDAT, "baselock") > DateTime.MinValue && DateTime.UtcNow - t0 <= WaitBaseLock) { Thread.Sleep(ScadaUtils.ThreadDelay); } // loading data into tables var newBaseTables = new BaseTables() { BaseAge = newBaseAge }; foreach (var dataTable in newBaseTables.AllTables) { string tableName = BaseTables.GetFileName(dataTable); if (!serverComm.ReceiveBaseTable(tableName, dataTable)) { throw new ScadaException($"Unable to receive the table {tableName}"); } } BaseTables = newBaseTables; // filling channel properties and statuses lock (BaseTables.SyncRoot) { FillCnlProps(); FillCtrlCnlProps(); FillCnlStatProps(); } } } } catch (Exception ex) { BaseTables.BaseAge = DateTime.MinValue; log.WriteException(ex, "Error refreshing the tables of the configuration database"); } } }