/// <summary> Метод открытия логов </summary> private void OpenLog(string[] log) { if (log == null) { throw new Exception(LocalizationApp.GetInstance().GetValueByKey(@"ViewModelUserSettings_LogEmpty")); } var tempPath = Path.GetTempPath() + @"\" + Guid.NewGuid() + @".txt"; File.WriteAllLines(tempPath, log); Process.Start(tempPath); }
/// <summary> Метод сохранения контакта </summary> private void Save() { CurrentModelContact.ListModelUserContactExtra = CurrentModelContact.ListModelUserContactExtra.Where(obj => !String.IsNullOrWhiteSpace(obj.Identity.Trim('+')))?.ToList(); if (DataSourceContact.SaveModelContact(CurrentModelContact)) { AddManualContactSuccessful?.Invoke(this, CurrentModelContact); // кастыль для демо OnCloseView(); } else { throw new Exception(LocalizationApp.GetInstance().GetValueByKey(@"ViewModelManualContact_ContactNotSaved")); } }
/// <summary> Обработчик запуска приложение </summary> protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // подписка на необрабатываемые исключения в приложении DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Application_DispatcherUnhandledException); // подписка на необрабатываемые исключения в приложении System.AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; // Инициализация всех ModelEnum в главном потоке, в котором стартует GUI CommonModelEnum.InitializeModelEnum(); // привязка смены языка интерфейса к смене языка в приложении LocalizationApp.GetInstance().LocalizationChanged += LocalizationUI.ChangeLanguage; bool success; var userName = WindowsIdentity.GetCurrent().Name.Replace(@"\", "-"); Mutex = new Mutex(true, "DCBF3DE8-032E-4DCA-8158-AE0CF30A15AC" /*userName*/, out success); if (!success) { var allProcess = System.Diagnostics.Process.GetProcesses(); var currentProcess = System.Diagnostics.Process.GetCurrentProcess(); foreach (var process in allProcess) { if (currentProcess.ProcessName == process.ProcessName && currentProcess.Id != process.Id) { var hWndStartup = FindWindow(null, "DCBF3DE8-032E-4DCA-8158-AE0CF30A15AC" + userName); if (hWndStartup != IntPtr.Zero) { ShowWindow(hWndStartup, 1); SetForegroundWindow(hWndStartup); } else { WindowMessageBox.Show("Application is run"); } } } Environment.Exit(0); } }
/// <summary> Конструктор </summary> public WindowStartup() { InitializeComponent(); Title = "DCBF3DE8-032E-4DCA-8158-AE0CF30A15AC" + WindowsIdentity.GetCurrent().Name.Replace(@"\", "-"); Instance = this; _windowMain = FactoryWindow.GetWindowMain(); // привязка смены языка интерфейса к смене языка в приложении LocalizationApp.GetInstance().LocalizationChanged += (sender, language) => OnLocalizationChanged(); ModelUser.GetInstance().UserStatusChanged += (sender, args) => OnUserStatusChanged(); OnLocalizationChanged(); _itemStatus.DropDownItems.Add(_itemOnline); _itemStatus.DropDownItems.Add(_itemDnd); _itemStatus.DropDownItems.Add(_itemHidden); _itemStatus.DropDownItems.Add(_itemOffline); _itemStatus.DropDownItems.Add(new ToolStripSeparator()); _itemStatus.DropDownItems.Add(_itemSetStatus); _itemOnline.Click += (sender, args) => { ModelUser.GetInstance().ModelEnumUserBaseStatusObj = ModelEnumUserBaseStatus.GetModelEnum(1); _viewModelTray.SaveStatusModelUser(); }; _itemDnd.Click += (sender, args) => { ModelUser.GetInstance().ModelEnumUserBaseStatusObj = ModelEnumUserBaseStatus.GetModelEnum(3); _viewModelTray.SaveStatusModelUser(); }; _itemHidden.Click += (sender, args) => { ModelUser.GetInstance().ModelEnumUserBaseStatusObj = ModelEnumUserBaseStatus.GetModelEnum(2); _viewModelTray.SaveStatusModelUser(); }; _itemOffline.Click += (sender, args) => { ModelUser.GetInstance().ModelEnumUserBaseStatusObj = ModelEnumUserBaseStatus.GetModelEnum(0); _viewModelTray.SaveStatusModelUser(); }; _itemSetStatus.Click += (sender, args) => SetUserStatus(); _itemOpen.Click += (sender, args) => WindowDispacher.GetInstance.ShowAllWindow(); _itemExit.Click += (sender, args) => ApplicationExit(); var ctxmenustrip = new ContextMenuStrip(); ctxmenustrip.Items.Add(_itemStatus); ctxmenustrip.Items.Add(_itemOpen); ctxmenustrip.Items.Add(new ToolStripSeparator()); ctxmenustrip.Items.Add(_itemExit); NotifyIcon.ContextMenuStrip = ctxmenustrip; NotifyIcon.DoubleClick += (sender, args) => { WindowDispacher.GetInstance.ShowAllWindow(); }; _windowMain.ViewUserAuthorizationClosed += WindowMainOnViewUserAuthorizationClosed; _windowMain.Show(); }
/// <summary> Сортировка контактов </summary> private int CompareDependLocalization(string str1, string str2) { // -1 str1 или 0 str1=str2 или 1 str2 var result = 0; var length = str1.Length < str2.Length ? str1.Length : str2.Length; var r = new Regex(@"[a-z]", RegexOptions.IgnoreCase); if (LocalizationApp.GetInstance().ModelLanguageObj.CodeName == "ru") { r = new Regex(@"[а-я]", RegexOptions.IgnoreCase); } for (int i = 0; i < length; i++) { var char1 = str1[i].ToString(); var char2 = str2[i].ToString(); var result1 = r.Match(char1); var result2 = r.Match(char2); if (result1.Success && result2.Success) { result = String.Compare(char1, char2, StringComparison.InvariantCultureIgnoreCase); if (result != 0) { return(result); } } if (result1.Success && !result2.Success) { result = -1; return(result); } if (!result1.Success && result2.Success) { result = 1; return(result); } if (!result1.Success && !result2.Success) { var symbol1 = str1[i]; var symbol2 = str2[i]; if (Char.IsLetter(symbol1) && Char.IsLetter(symbol2)) { result = String.Compare(char1, char2, StringComparison.InvariantCultureIgnoreCase); } if (Char.IsLetter(symbol1) && !Char.IsLetter(symbol2)) { result = -1; } if (!Char.IsLetter(symbol1) && Char.IsLetter(symbol2)) { result = 1; } if (!Char.IsLetter(symbol1) && !Char.IsLetter(symbol2)) { result = String.Compare(char1, char2, StringComparison.InvariantCultureIgnoreCase); } if (result != 0) { return(result); } } } return(result); }
/// <summary> Метод возвращает предыдущий язык (если настройки не были сохранены, то язык приложения нужно вернуть) </summary> public void ResetLanguage() { LocalizationApp.GetInstance().ModelLanguageObj = _currentModelLanguage; }
/// <summary> Возвращает дату в строковом коротком формате с локализацией (сделано что бы выглядело как на iOS) </summary> public static string ConvertShortDateString(DateTime dateTime) { string result; var today = DateTime.Today; if (dateTime.Date == today) { result = dateTime.Hour + ":" + (dateTime.Minute < 10 ? "0" + dateTime.Minute : dateTime.Minute.ToString()); } else { if (dateTime.Year == today.Year) { result = (dateTime.Day < 10 ? "0" + dateTime.Day : dateTime.Day.ToString()) + " "; switch (dateTime.Month) { case 1: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Jan"); break; case 2: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Feb"); break; case 3: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Mar"); break; case 4: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Apr"); break; case 5: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_May"); break; case 6: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Jun"); break; case 7: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Jul"); break; case 8: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Aug"); break; case 9: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Sep"); break; case 10: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Oct"); break; case 11: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Nov"); break; case 12: result += LocalizationApp.GetInstance().GetValueByKey("UtilityDate_Dec"); break; } } else { result = (dateTime.Month < 10 ? "0" + dateTime.Month : dateTime.Month.ToString()) + "." + dateTime.Year; } } return(result); }
/// <summary> Конструктор </summary> protected AbstractLocalization() { LocalizationApp.GetInstance().PropertyChanged += OnChangeLocalizationApp; }