public BackupJob() { _settings = SettingsReader.GetSettings(); var secureString = SettingsReader.DecryptString(_settings.Password); var rawPass = SettingsReader.ToInsecureString(secureString); //ShowMessage = showMessage; //ShowBalloonMsg = showBalloon; _requestSender.Init(null, null, _settings.Login, rawPass); }
private void Init() { Logger.Log.Info("--- Инициализация ---"); if (_tbi == null) { _notificationManager = new NotificationManager(); CreateTaskBarIcon(); ShowMessage += AddTextToConsole; ShowBalloonMsg += ShowBalloonTip; } try { _settings = SettingsReader.GetSettings(); if (string.IsNullOrEmpty(_settings.Password)) { Logger.Log.Error("Пустой пароль в настройках!"); MessageBox.Show("Password is empty!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var secureString = SettingsReader.DecryptString(_settings.Password); var rawPass = SettingsReader.ToInsecureString(secureString); _requestSender.Init(ShowMessage, ShowBalloonMsg, _settings.Login, rawPass); } catch (Exception e) { AddTextToConsole(e.Message); Logger.Log.ErrorFormat("Ошибка чтения настроек. {0}", e.InnerException); } if (_settings != null) { //bind controls to settings DbList.Items.Clear(); SelectedFolder.Text = _settings.DefaultPath; FileNameTb.Text = _settings.SelectedDb; foreach (var listItem in _settings.List) { DbList.Items.Add(listItem.DbName); } if (!string.IsNullOrEmpty(_settings.SelectedDb)) { DbList.SelectedValue = _settings.SelectedDb; UrlTb.Text = _settings.List.FirstOrDefault(i => i.DbName == _settings.SelectedDb)?.Url ?? string.Empty; } } //hide instead of close Loaded += delegate { HwndSource source = (HwndSource)PresentationSource.FromDependencyObject(this); source?.AddHook(WindowProc); }; Closing += (x, y) => { switch (_closeReason) { case CloseReason.EndTask: break; case CloseReason.Logoff: break; case CloseReason.User: WindowState = WindowState.Minimized; y.Cancel = true; break; case CloseReason.Manually: break; default: throw new ArgumentOutOfRangeException(); } }; Logger.Log.Info("--- Конец инициализации ---"); }