private void FrmConfig_Load(object sender, EventArgs e) { // translate the form if (Localization.LoadDictionaries(appDirs.LangDir, "KpDbImport", out string errMsg)) { Translator.TranslateForm(this, "Scada.Comm.Devices.DbImport.UI.FrmConfig"); } else { ScadaUiUtils.ShowError(errMsg); } Text = string.Format(Text, kpNum); // load a configuration configFileName = KpConfig.GetFileName(appDirs.ConfigDir, kpNum); if (File.Exists(configFileName) && !config.Load(configFileName, out errMsg)) { ScadaUiUtils.ShowError(errMsg); } // display the configuration ConfigToControls(); Modified = false; }
/// <summary> /// Выполнить действия после добавления КП на линию связи /// </summary> public override void OnAddedToCommLine() { // загрузка конфигурации КП bool configLoaded = config.Load(KpConfig.GetFileName(AppDirs.ConfigDir, Number, ReqParams.CmdLine), out string errMsg); if (configLoaded) { try { // инициализация тегов КП InitKPTags(); fatalError = false; } catch { fatalError = true; throw; } } else { fatalError = true; throw new Exception(errMsg); } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmConfig(AppDirs appDirs, int kpNum) : this() { this.appDirs = appDirs ?? throw new ArgumentNullException("appDirs"); this.kpNum = kpNum; config = new KpConfig(); configFileName = ""; modified = false; connChanging = false; cmdSelecting = false; }
/// <summary> /// Gets an array of tag names according to the configuration. /// </summary> internal static string[] GetTagNames(KpConfig config) { int tagCount = config.AutoTagCount ? config.CalcTagCount() : config.TagCount; string[] tagNames = new string[tagCount]; for (int i = 0; i < tagCount; i++) { tagNames[i] = "Tag " + (i + 1); } return(tagNames); }
/// <summary> /// Initializes the data source. /// </summary> private void InitDataSource(KpConfig config) { switch (config.DataSourceType) { case DataSourceType.MSSQL: dataSource = new SqlDataSource(); break; case DataSourceType.Oracle: dataSource = new OraDataSource(); break; case DataSourceType.PostgreSQL: dataSource = new PgSqlDataSource(); break; case DataSourceType.MySQL: dataSource = new MySqlDataSource(); break; case DataSourceType.OLEDB: dataSource = new OleDbDataSource(); break; default: dataSource = null; WriteToLog(Localization.UseRussian ? "Data source type is not set or not supported" : "Тип источника данных не задан или не поддерживается"); break; } if (dataSource != null) { string connStr = string.IsNullOrEmpty(config.DbConnSettings.ConnectionString) ? dataSource.BuildConnectionString(config.DbConnSettings) : config.DbConnSettings.ConnectionString; if (string.IsNullOrEmpty(connStr)) { dataSource = null; WriteToLog(Localization.UseRussian ? "Соединение не определено" : "Connection is undefined"); } else { dataSource.Init(connStr, config); } } }
private VersionCode snmpVersion; // версия SNMP /// <summary> /// Конструктор /// </summary> public KpSnmpLogic(int number) : base(number) { CanSendCmd = true; ConnRequired = false; config = new KpConfig(); fatalError = false; varGroups = null; strVals = null; isBitsArr = null; endPoint = null; readCommunity = null; writeCommunity = null; snmpVersion = VersionCode.V2; }
/// <summary> /// Initializes the device tags. /// </summary> private void InitDeviceTags(KpConfig config) { string[] tagNames = GetTagNames(config); int tagCnt = tagNames.Length; List <KPTag> kpTags = new List <KPTag>(tagCnt); tagTypes = new TagType[tagCnt]; for (int i = 0; i < tagCnt; i++) { kpTags.Add(new KPTag(i + 1, tagNames[i])); tagTypes[i] = TagType.Number; } InitKPTags(kpTags); }
/// <summary> /// Performs actions after adding the device to a communication line. /// </summary> public override void OnAddedToCommLine() { // load configuration KpConfig config = new KpConfig(); if (config.Load(KpConfig.GetFileName(AppDirs.ConfigDir, Number), out string errMsg)) { InitDataSource(config); InitDeviceTags(config); CanSendCmd = config.ExportCmds.Count > 0; } else { dataSource = null; WriteToLog(errMsg); } }
/// <summary> /// Загрузить конфигурацию соединения с почтовым сервером /// </summary> private void LoadConfig() { fatalError = !config.Load(KpConfig.GetFileName(AppDirs.ConfigDir, Number), out string errMsg); if (fatalError) { state = Localization.UseRussian ? "Отправка уведомлений невозможна" : "Sending notifocations is impossible"; throw new Exception(errMsg); } else { state = Localization.UseRussian ? "Ожидание команд..." : "Waiting for commands..."; } }
private bool writeState; // вывести состояние КП /// <summary> /// Конструктор /// </summary> public KpEmailLogic(int number) : base(number) { CanSendCmd = true; ConnRequired = false; WorkState = WorkStates.Normal; addressBook = null; config = new KpConfig(); smtpClient = new SmtpClient(); fatalError = false; state = ""; writeState = false; InitKPTags(new List <KPTag>() { new KPTag(1, Localization.UseRussian ? "Отправлено писем" : "Sent emails") }); }
/// <summary> /// Initializes the data source. /// </summary> public void Init(string connectionString, KpConfig config) { if (config == null) { throw new ArgumentNullException("config"); } Connection = CreateConnection(); Connection.ConnectionString = connectionString; SelectCommand = CreateCommand(); SelectCommand.CommandText = config.SelectQuery; SelectCommand.Connection = Connection; foreach (ExportCmd exportCmd in config.ExportCmds) { DbCommand exportCommand = CreateCommand(); exportCommand.CommandText = exportCmd.Query; exportCommand.Connection = Connection; ExportCommands[exportCmd.CmdNum] = exportCommand; } }