private void FrmMain_Load(object sender, EventArgs e) { // определение директории исполняемого файла приложения exeDir = ScadaUtils.NormalDir(Path.GetDirectoryName(Application.ExecutablePath)); // локализация приложения if (!Localization.UseRussian) { string langDir = exeDir + "Lang\\"; string errMsg; if (Localization.LoadDictionaries(langDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { ScadaUtils.ShowError(errMsg); } if (Localization.LoadDictionaries(langDir, "ScadaWebConfig", out errMsg)) { Localization.TranslateForm(this, "ScadaWebConfig.FrmMain"); WebPhrases.Init(); AppPhrases.Init(); folderBrowserDialog.Description = AppPhrases.ChooseConfigDir; openFileDialog.Title = AppPhrases.ChooseViewFile; openFileDialog.Filter = AppPhrases.FileFilter; } else { ScadaUtils.ShowError(errMsg); } } }
/// <summary> /// Локализовать форму /// </summary> private void LocalizeForm() { string errMsg; if (Localization.LoadDictionaries(appData.AppDirs.LangDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { log.WriteError(errMsg); } if (Localization.LoadDictionaries(appData.AppDirs.LangDir, "ScadaScheme", out errMsg)) { SchemePhrases.Init(); } else { log.WriteError(errMsg); } if (Localization.LoadDictionaries(appData.AppDirs.LangDir, "ScadaSchemeEditor", out errMsg)) { Translator.TranslateForm(this, "Scada.Scheme.Editor.FrmMain"); AppPhrases.Init(); ofdScheme.Filter = sfdScheme.Filter = AppPhrases.SchemeFileFilter; } else { log.WriteError(errMsg); } }
/// <summary> /// Обновить словари, если файл словарей изменился /// </summary> private static void RefreshDictionaries() { if (!Localization.UseRussian) { DateTime fileWriteTime1 = GetFileWriteTime(Localization.GetDictionaryFileName(LangDir, "ScadaData")); DateTime fileWriteTime2 = GetFileWriteTime(Localization.GetDictionaryFileName(LangDir, "ScadaWeb")); string writeTimeStr = fileWriteTime1.ToString() + fileWriteTime2.ToString(); if (dictWriteTimeStr != writeTimeStr) { dictWriteTimeStr = writeTimeStr; string errMsg; if (Localization.LoadDictionaries(LangDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { Log.WriteAction(errMsg, Log.ActTypes.Error); } if (Localization.LoadDictionaries(LangDir, "ScadaWeb", out errMsg)) { WebPhrases.Init(); } else { Log.WriteAction(errMsg, Log.ActTypes.Error); } } } }
/// <summary> /// Локализовать форму. /// </summary> private void LocalizeForm() { if (!Localization.LoadDictionaries(appData.AppDirs.LangDir, "ScadaData", out string errMsg)) { log.WriteError(errMsg); } if (!Localization.LoadDictionaries(appData.AppDirs.LangDir, "ScadaScheme", out errMsg)) { log.WriteError(errMsg); } bool appDictLoaded = Localization.LoadDictionaries(appData.AppDirs.LangDir, "ScadaSchemeEditor", out errMsg); if (!appDictLoaded) { log.WriteError(errMsg); } CommonPhrases.Init(); SchemePhrases.Init(); AppPhrases.Init(); if (appDictLoaded) { Translator.TranslateForm(this, "Scada.Scheme.Editor.FrmMain"); ofdScheme.SetFilter(AppPhrases.SchemeFileFilter); sfdScheme.SetFilter(AppPhrases.SchemeFileFilter); } }
private void FrmMain_Load(object sender, EventArgs e) { // локализация приложения if (!Localization.UseRussian) { string langDir = AppData.ExeDir + "Lang\\"; string errMsg; if (Localization.LoadDictionaries(langDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { ScadaUtils.ShowError(errMsg); } if (Localization.LoadDictionaries(langDir, "ScadaAdmin", out errMsg)) { Localization.TranslateForm(this, "ScadaAdmin.FrmMain", null, contextExpolorer, contextInCnls); AppPhrases.Init(); winControl.MessageText = AppPhrases.SelectTable; winControl.SaveReqCaption = AppPhrases.SaveReqCaption; winControl.SaveReqQuestion = AppPhrases.SaveReqQuestion; winControl.SaveReqYes = AppPhrases.SaveReqYes; winControl.SaveReqNo = AppPhrases.SaveReqNo; winControl.SaveReqCancel = AppPhrases.SaveReqCancel; } else { ScadaUtils.ShowError(errMsg); } } // инициализация дерева проводника InitTreeView(); // установка начального состояния разрешений элементов SetItemsEnabledOnConnect(); SetItemsEnabledOnWindowAction(); // загрузка состояния формы settings = new Settings(); settings.LoadFormState(); if (settings.FormSt.IsEmpty) { WindowState = FormWindowState.Maximized; } else { Left = settings.FormSt.Left; Top = settings.FormSt.Top; Width = settings.FormSt.Width; Height = settings.FormSt.Height; WindowState = settings.FormSt.Maximized ? FormWindowState.Maximized : FormWindowState.Normal; pnlLeft.Width = settings.FormSt.ExplorerWidth; } }
/// <summary> /// Localizes the application. /// </summary> private bool LocalizeApp() { if (!Locale.LoadDictionaries(AppDirs.LangDir, "ScadaCommon", out string errMsg)) { log.WriteError(errMsg); } CommonPhrases.Init(); EnginePhrases.Init(); return(true); }
/// <summary> /// Launch agent /// </summary> public bool StartAgent() { // common data initialization var appData = AppData.GetInstance(); string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); appData.Init(exeDir); log = appData.Log; log.WriteBreak(); log.WriteAction(string.Format(Localization.UseRussian ? "Агент {0} запущен" : "Agent {0} started", AgentUtils.AppVersion)); if (appData.AppDirs.Exist) { // localization if (Localization.LoadDictionaries(appData.AppDirs.LangDir, "ScadaData", out string errMsg)) { CommonPhrases.Init(); } else { log.WriteError(errMsg); } // launch string settingsFileName = appData.AppDirs.ConfigDir + Settings.DefFileName; agentLogic = new AgentLogic(appData.SessionManager, appData.AppDirs, appData.Log); if (appData.Settings.Load(settingsFileName, out errMsg) && StartWcfService() && agentLogic.StartProcessing()) { return(true); } else if (!string.IsNullOrEmpty(errMsg)) { log.WriteError(errMsg); } } else { log.WriteError(string.Format( Localization.UseRussian ? "Необходимые директории не существуют:{0}{1}" : "The required directories do not exist:{0}{1}", Environment.NewLine, string.Join(Environment.NewLine, appData.AppDirs.GetRequiredDirs()))); } log.WriteError(Localization.UseRussian ? "Нормальная работа программы невозможна" : "Normal program execution is impossible"); return(false); }
/// <summary> /// Запустить службу /// </summary> public void StartService() { // инициализация объекта логики string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); mainLogic.Init(exeDir); appLog.WriteBreak(); appLog.WriteAction(string.Format(Localization.UseRussian ? "Служба ScadaServerService {0} запущена" : "ScadaServerService {0} is started", ServerUtils.AppVersion)); if (mainLogic.AppDirs.Exist) { // локализация if (Localization.LoadDictionaries(mainLogic.AppDirs.LangDir, "ScadaData", out string errMsg)) { CommonPhrases.Init(); } else { appLog.WriteError(errMsg); } if (Localization.LoadDictionaries(mainLogic.AppDirs.LangDir, "ScadaServer", out errMsg)) { ModPhrases.InitFromDictionaries(); } else { appLog.WriteError(errMsg); } // запуск if (mainLogic.Start()) { return; } } else { appLog.WriteError(string.Format(Localization.UseRussian ? "Необходимые директории не существуют:{0}{1}" : "The required directories do not exist:{0}{1}", Environment.NewLine, string.Join(Environment.NewLine, mainLogic.AppDirs.GetRequiredDirs()))); } appLog.WriteError(Localization.UseRussian ? "Нормальная работа программы невозможна" : "Normal program execution is impossible"); }
private void FrmMain_Load(object sender, EventArgs e) { // application localization if (Localization.LoadDictionaries(AppData.AppDirs.LangDir, "ScadaData", out string errMsg)) { CommonPhrases.Init(); } else { ScadaUiUtils.ShowError(errMsg); } if (Localization.LoadDictionaries(AppData.AppDirs.LangDir, "ScadaAdmin", out errMsg)) { Translator.TranslateForm(this, "ScadaAdmin.FrmMain", null, contextExpolorer, contextInCnls); AppPhrases.Init(); winControl.MessageText = AppPhrases.SelectTable; winControl.SaveReqCaption = AppPhrases.SaveReqCaption; winControl.SaveReqQuestion = AppPhrases.SaveReqQuestion; winControl.SaveReqYes = AppPhrases.SaveReqYes; winControl.SaveReqNo = AppPhrases.SaveReqNo; winControl.SaveReqCancel = AppPhrases.SaveReqCancel; } else { ScadaUiUtils.ShowError(errMsg); } // conductor tree initialization InitTreeView(); // setting the initial state of element permissions SetItemsEnabledOnConnect(); SetItemsEnabledOnWindowAction(); // form state loading settings.LoadFormState(); if (settings.FormSt.IsEmpty) { WindowState = FormWindowState.Maximized; } else { Left = settings.FormSt.Left; Top = settings.FormSt.Top; Width = settings.FormSt.Width; Height = settings.FormSt.Height; WindowState = settings.FormSt.Maximized ? FormWindowState.Maximized : FormWindowState.Normal; pnlLeft.Width = settings.FormSt.ExplorerWidth; } }
/// <summary> /// Localizes the application. /// </summary> private void LocalizeApp(string langDir) { if (!Locale.LoadDictionaries(langDir, "ScadaCommon", out string errMsg)) { log.WriteError(errMsg); } if (!Locale.LoadDictionaries(langDir, "ScadaServer", out errMsg)) { log.WriteError(errMsg); } CommonPhrases.Init(); ServerPhrases.Init(); }
/// <summary> /// Localizes the application. /// </summary> private void LocalizeApp() { if (!Locale.LoadDictionaries(AppDirs.LangDir, "ScadaCommon", out string errMsg)) { Log.WriteError(errMsg); } if (!Locale.LoadDictionaries(AppDirs.LangDir, "ScadaWeb", out errMsg)) { Log.WriteError(errMsg); } CommonPhrases.Init(); WebPhrases.Init(); }
/// <summary> /// Applies localization to the form. /// </summary> private void LocalizeForm() { Localization.LoadDictionaries(langDir, "ScadaData", out string errMsg); Localization.LoadDictionaries(langDir, "ScadaScheme", out errMsg); bool appDictLoaded = Localization.LoadDictionaries(langDir, "TemplateBindingEditor", out errMsg); CommonPhrases.Init(); SchemePhrases.Init(); AppPhrases.Init(); if (appDictLoaded) { Translator.TranslateForm(this, GetType().FullName, null); ofdBindings.SetFilter(AppPhrases.BindingsFileFilter); sfdBindings.SetFilter(AppPhrases.BindingsFileFilter); } }
/// <summary> /// 启动服务 /// </summary> public void StartService() { // 初始化逻辑对象 string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); mainLogic.Init(exeDir); appLog.WriteBreak(); appLog.WriteAction($"ScadaServerService {ServerUtils.AppVersion} is started", Log.ActTypes.Action); if (mainLogic.AppDirs.Exist) { // 本地化 if (Localization.LoadDictionaries(mainLogic.AppDirs.LangDir, "ScadaData", out string errMsg)) { CommonPhrases.Init(); } else { appLog.WriteError(errMsg); } if (Localization.LoadDictionaries(mainLogic.AppDirs.LangDir, "ScadaServer", out errMsg)) { ModPhrases.InitFromDictionaries(); } else { appLog.WriteError(errMsg); } // 启动 if (mainLogic.Start()) { return; } } else { appLog.WriteError( $"The required directories do not exist:{Environment.NewLine}{string.Join(Environment.NewLine, mainLogic.AppDirs.GetRequiredDirs())}"); } appLog.WriteError("Normal program execution is impossible"); }
private void FrmMain_Load(object sender, EventArgs e) { // определение директории исполняемого файла приложения exeDir = ScadaUtils.NormalDir(Path.GetDirectoryName(Application.ExecutablePath)); // локализация приложения string langDir = exeDir + "Lang\\"; string errMsg; if (Localization.LoadingRequired(langDir, "ScadaData")) { if (Localization.LoadDictionaries(langDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { ScadaUiUtils.ShowError(errMsg); } } if (Localization.LoadingRequired(langDir, "ScadaTableEditor")) { if (Localization.LoadDictionaries(langDir, "ScadaTableEditor", out errMsg)) { Translator.TranslateForm(this, "ScadaTableEditor.FrmMain", toolTip); WebPhrases.Init(); AppPhrases.Init(); openFileDialog.Filter = AppPhrases.OpenFileFilter; saveFileDialog.Filter = AppPhrases.SaveFileFilter; } else { ScadaUiUtils.ShowError(errMsg); } } // настройка элементов управления dgvCnls.AutoGenerateColumns = false; dgvItems.AutoGenerateColumns = false; // создание нового представления CreateTableView(); }
/// <summary> /// Localizes the application. /// </summary> private void LocalizeApp() { // load instance culture if (!Locale.LoadCulture(GetInstanceConfigFileName(), out string errMsg)) { ErrLog.WriteError(errMsg); } // load dictionaries if (!Locale.LoadDictionaries(AppDirs.LangDir, "ScadaCommon", out errMsg)) { ErrLog.WriteError(errMsg); } if (!Locale.LoadDictionaries(AppDirs.LangDir, "ScadaAdmin", out errMsg)) { ErrLog.WriteError(errMsg); } if (!Locale.LoadDictionaries(AppDirs.LangDir, "ScadaServer", out errMsg)) { ErrLog.WriteError(errMsg); } if (!Locale.LoadDictionaries(AppDirs.LangDir, "ScadaComm", out errMsg)) { ErrLog.WriteError(errMsg); } // read phrases from the dictionaries CommonPhrases.Init(); AdminPhrases.Init(); AppPhrases.Init(); ServerPhrases.Init(); CommPhrases.Init(); }
/// <summary> /// Applies localization to the form. /// </summary> private void LocalizeForm() { if (!Localization.LoadDictionaries(langDir, "ScadaData", out string errMsg)) { errLog.WriteError(errMsg); } bool tableDictLoaded = Localization.LoadDictionaries(langDir, "ScadaTable", out errMsg); if (!tableDictLoaded) { errLog.WriteError(errMsg); } CommonPhrases.Init(); TablePhrases.Init(); if (tableDictLoaded) { Translator.TranslateForm(this, GetType().FullName, null, cmsDevice); ofdTable.SetFilter(TablePhrases.TableFileFilter); sfdTable.SetFilter(TablePhrases.TableFileFilter); } }
/// <summary> /// Запустить службу /// </summary> public void StartService() { // инициализация необходимых директорий bool dirsExist; // необходимые директории существуют bool logDirExists; // директория log-файлов существует InitAppDirs(out dirsExist, out logDirExists); if (logDirExists) { AppLog.WriteBreak(); AppLog.WriteAction(string.Format(Localization.UseRussian ? "Служба ScadaCommService {0} запущена" : "ScadaCommService {0} is started", CommUtils.AppVersion), Log.ActTypes.Action); } if (dirsExist) { // локализация ScadaData.dll string errMsg; if (Localization.LoadDictionaries(AppDirs.LangDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { AppLog.WriteAction(errMsg, Log.ActTypes.Error); } // запуск работы if (!StartOperation()) { AppLog.WriteAction(Localization.UseRussian ? "Нормальная работа программы невозможна." : "Normal program execution is impossible.", Log.ActTypes.Error); } } else { string errMsg = string.Format(Localization.UseRussian ? "Не существуют необходимые директории:{0}{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}" + "Нормальная работа программы невозможна." : "Required directories are not exist:{0}{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}" + "Normal program execution is impossible.", Environment.NewLine, AppDirs.ConfigDir, AppDirs.LangDir, AppDirs.LogDir, AppDirs.KPDir, AppDirs.CmdDir); try { if (EventLog.SourceExists("ScadaCommService")) { EventLog.WriteEvent("ScadaCommService", new EventInstance(0, 0, EventLogEntryType.Error), errMsg); } } catch { } if (logDirExists) { AppLog.WriteAction(errMsg, Log.ActTypes.Error); } } }
protected override void OnStart(string[] args) { // инициализация необходимых директорий bool dirsExist; // необходимые директории существуют bool logDirExists; // директория log-файлов существует mngr.InitAppDirs(out dirsExist, out logDirExists); if (logDirExists) { appLog.WriteBreak(); appLog.WriteAction(Localization.UseRussian ? "Служба ScadaCommService запущена" : "ScadaCommService is started", Log.ActTypes.Action); } if (dirsExist) { // локализация ScadaData.dll if (!Localization.UseRussian) { string errMsg; if (Localization.LoadDictionaries(Manager.LangDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { appLog.WriteAction(errMsg, Log.ActTypes.Error); } } // считывание конфигурации и запуск потоков if (mngr.ParseConfig()) { mngr.StartThreads(); } else { appLog.WriteAction(Localization.UseRussian ? "Нормальная работа программы невозможна." : "Normal program execution is impossible.", Log.ActTypes.Error); } } else { string errMsg = string.Format(Localization.UseRussian ? "Не существуют необходимые директории:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n" + "Нормальная работа программы невозможна." : "Required directories are not exist:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n" + "Normal program execution is impossible.", Manager.ConfigDir, Manager.LangDir, Manager.LogDir, Manager.KpDir, Manager.CmdDir); try { if (EventLog.SourceExists("ScadaCommService")) { EventLog.WriteEvent("ScadaCommService", new EventInstance(0, 0, EventLogEntryType.Warning), errMsg); } } catch { } if (logDirExists) { appLog.WriteAction(errMsg, Log.ActTypes.Error); } } }
private void FrmMain_Load(object sender, EventArgs e) { // определение директории исполняемого файла приложения exeDir = ScadaUtils.NormalDir(Path.GetDirectoryName(Application.ExecutablePath)); // локализация приложения string langDir = exeDir + "lang\\"; string errMsg; if (Localization.LoadingRequired(langDir, "ScadaData")) { if (Localization.LoadDictionaries(langDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { ScadaUtils.ShowError(errMsg); } } if (Localization.LoadingRequired(langDir, "ScadaSchemeEditor")) { if (Localization.LoadDictionaries(langDir, "ScadaSchemeEditor", out errMsg)) { Localization.TranslateForm(this, "Scada.Scheme.Editor.FrmMain"); SchemePhrases.InitStatic(); openFileDialog.Filter = saveFileDialog.Filter = SchemePhrases.FileFilter; } else { ScadaUtils.ShowError(errMsg); } } // инициализация данных SchemeApp schemeApp = SchemeApp.InitSchemeApp(SchemeApp.WorkModes.Edit); schemeUrl = exeDir + "web\\ScadaScheme.html?editMode=true"; editorData = schemeApp.EditorData; editorData.SelectElement = SelectElement; editorData.SetFormTitle = SetFormTitle; log = schemeApp.Log; elemClipboard = null; schemeSvcHost = null; domainSvcHost = null; schemeExThread = null; // проверка запуска второй копии программы try { bool createdNew; mutex = new Mutex(true, "ScadaSchemeEditorMutex", out createdNew); if (!createdNew) { ScadaUtils.ShowInfo("SCADA-Редактор схем уже запущен.\nВторая копия будет закрыта."); Close(); return; } } catch (Exception ex) { log.WriteAction("Ошибка при проверке запуска второй копии программы: " + ex.Message, Log.ActTypes.Exception); } // запуск WCF-служб if (StartWCF()) { // создание и запуск потока для обмена данными со схемой schemeExThread = new Thread(SchemeExchange); schemeExThread.Start(); // настройка элементов управления miEditCut.Enabled = btnEditCut.Enabled = false; miEditCopy.Enabled = btnEditCopy.Enabled = false; miEditPaste.Enabled = btnEditPaste.Enabled = false; miSchemeCancelAddElem.Enabled = btnSchemeCancelAddElem.Enabled = false; miSchemeDelElem.Enabled = btnSchemeDelElem.Enabled = false; // создание новой схемы miFileNew_Click(null, null); } else { // блокировка элементов управления foreach (ToolStripItem item in miFile.DropDown.Items) { item.Enabled = item == miFileExit; } foreach (ToolStripItem item in miEdit.DropDown.Items) { item.Enabled = false; } foreach (ToolStripItem item in miScheme.DropDown.Items) { item.Enabled = false; } foreach (ToolStripItem item in toolMain.Items) { item.Enabled = false; } } }
public void OnStart(string[] args) { // инициализация необходимых директорий bool dirsExist; // необходимые директории существуют bool logDirExists; // директория log-файлов существует mainLogic.InitAppDirs(out dirsExist, out logDirExists); if (logDirExists) { appLog.WriteBreak(); appLog.WriteAction(Localization.UseRussian ? "Служба ScadaServerService запущена" : "ScadaServerService is started", Log.ActTypes.Action); } if (dirsExist) { // локализация ScadaData.dll if (!Localization.UseRussian) { string errMsg; if (Localization.LoadDictionaries(mainLogic.LangDir, "ScadaData", out errMsg)) { CommonPhrases.Init(); } else { appLog.WriteAction(errMsg, Log.ActTypes.Error); } } // запуск работы SCADA-Сервера if (!mainLogic.Start()) { appLog.WriteAction(Localization.UseRussian ? "Нормальная работа программы невозможна." : "Normal program execution is impossible.", Log.ActTypes.Error); } else { checkThread.Start(); } } else { string errMsg = string.Format(Localization.UseRussian ? "Не существуют необходимые директории:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n" + "Нормальная работа программы невозможна." : "Required directories are not exist:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n" + "Normal program execution is impossible.", mainLogic.ConfigDir, mainLogic.LangDir, mainLogic.LogDir, mainLogic.ModDir); try { if (EventLog.SourceExists("ScadaServerService")) { EventLog.WriteEvent("ScadaServerService", new EventInstance(0, 0, EventLogEntryType.Warning), errMsg); } } catch { } if (logDirExists) { appLog.WriteAction(errMsg, Log.ActTypes.Error); } } }