private static void ChangeLanguage(string language) { LocalizeDictionary dict = LocalizeDictionary.Instance; dict.IncludeInvariantCulture = true; dict.SetCurrentThreadCulture = true; dict.Culture = CultureInfo.GetCultureInfo(language); var xmlLang = XmlLanguage.GetLanguage(dict.Culture.IetfLanguageTag); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(xmlLang)); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(Run), new FrameworkPropertyMetadata(xmlLang)); }
private static void ChangeLanguage(string language) { LocalizeDictionary dict = LocalizeDictionary.Instance; dict.IncludeInvariantCulture = true; dict.SetCurrentThreadCulture = true; dict.Culture = CultureInfo.GetCultureInfo(language); // This is done so DateTime's in XAML are parsed based on the user language instead of // en-US which is the default language for XAML. var xmlLang = XmlLanguage.GetLanguage(dict.Culture.IetfLanguageTag); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(xmlLang)); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(Run), new FrameworkPropertyMetadata(xmlLang)); }
protected override void InitializeShell() { Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; LocalizeDictionary.ChangeLanguage(LocalSettings.CurrentLanguage); InteractionService.UserIntraction.ToggleSplashScreen(); ServiceLocator.Current.GetInstance <IApplicationState>().MainDispatcher = Application.Current.Dispatcher; base.InitializeShell(); Application.Current.MainWindow = (Shell)Shell; InteractionService.UserIntraction.ToggleSplashScreen(); Application.Current.MainWindow.Show(); EventServiceFactory.EventService.PublishEvent(EventTopicNames.ShellInitialized); //通知Shell初始化完成 }
private static void ChangeLanguage(IConfig config) { var language = config.General.Language; LocalizeDictionary dict = LocalizeDictionary.Instance; dict.IncludeInvariantCulture = true; dict.SetCurrentThreadCulture = true; if (string.IsNullOrWhiteSpace(language)) { // User has not decided for a language yet. Try to use current UI language LogTo.Info($"User has not set language. Trying to use {CultureInfo.CurrentUICulture}"); string localizedCode = Strings.ResourceManager.GetString("__Language_Code__", CultureInfo.CurrentUICulture); Debug.Assert(localizedCode != null, "localizedCode != null"); var culture = CultureInfo.CreateSpecificCulture(localizedCode); if (!CultureInfo.InvariantCulture.Equals(culture)) { dict.Culture = culture; config.General.Language = culture.Name; config.Save(); } } else { dict.Culture = CultureInfo.GetCultureInfo(language); } // This is done so DateTime's in XAML are parsed based on the user language instead of // en-US which is the default language for XAML. var xmlLang = XmlLanguage.GetLanguage(dict.Culture.IetfLanguageTag); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(xmlLang)); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(Run), new FrameworkPropertyMetadata(xmlLang)); }
/// <summary> /// This function returns the properly prepared output of the markup extension. /// </summary> public object FormatOutput() { object result = null; if (targetInfo == null) { return(null); } var targetObject = targetInfo.TargetObject as DependencyObject; // Get target type. Change ImageSource to BitmapSource in order to use our own converter. Type targetType = targetInfo.TargetPropertyType; if (targetType.Equals(typeof(System.Windows.Media.ImageSource))) { targetType = typeof(BitmapSource); } // Try to get the localized input from the resource. string resourceKey = this.Key; CultureInfo ci = GetForcedCultureOrDefault(); // Extract the names of the endpoint object and property string epName = ""; string epProp = ""; if (targetObject is FrameworkElement) { epName = (string)((FrameworkElement)targetObject).GetValue(FrameworkElement.NameProperty); } #if SILVERLIGHT #else else if (targetObject is FrameworkContentElement) { epName = (string)((FrameworkContentElement)targetObject).GetValue(FrameworkContentElement.NameProperty); } #endif if (targetInfo.TargetProperty is PropertyInfo) { epProp = ((PropertyInfo)targetInfo.TargetProperty).Name; } #if SILVERLIGHT else if (targetInfo.TargetProperty is DependencyProperty) { epProp = ((DependencyProperty)targetInfo.TargetProperty).ToString(); } #else else if (targetInfo.TargetProperty is DependencyProperty) { epProp = ((DependencyProperty)targetInfo.TargetProperty).Name; } #endif // What are these names during design time good for? Any suggestions? if (epProp.Contains("FrameworkElementWidth5")) { epProp = "Height"; } else if (epProp.Contains("FrameworkElementWidth6")) { epProp = "Width"; } else if (epProp.Contains("FrameworkElementMargin12")) { epProp = "Margin"; } string resKeyBase = ci.Name + ":" + targetType.Name + ":"; string resKeyNameProp = epName + LocalizeDictionary.GetSeparation(targetObject) + epProp; string resKeyName = epName; // Check, if the key is already in our resource buffer. object input = null; if (!String.IsNullOrEmpty(resourceKey)) { // We've got a resource key. Try to look it up or get it from the dictionary. if (ResourceBuffer.ContainsKey(resKeyBase + resourceKey)) { result = ResourceBuffer[resKeyBase + resourceKey]; } else { input = LocalizeDictionary.Instance.GetLocalizedObject(resourceKey, targetObject, ci); resKeyBase += resourceKey; } } else { // Try the automatic lookup function. // First, look for a resource entry named: [FrameworkElement name][Separator][Property name] if (ResourceBuffer.ContainsKey(resKeyBase + resKeyNameProp)) { result = ResourceBuffer[resKeyBase + resKeyNameProp]; } else { // It was not stored in the buffer - try to retrieve it from the dictionary. input = LocalizeDictionary.Instance.GetLocalizedObject(resKeyNameProp, targetObject, ci); if (input == null) { // Now, try to look for a resource entry named: [FrameworkElement name] // Note - this has to be nested here, as it would take precedence over the first step in the buffer lookup step. if (ResourceBuffer.ContainsKey(resKeyBase + resKeyName)) { result = ResourceBuffer[resKeyBase + resKeyName]; } else { input = LocalizeDictionary.Instance.GetLocalizedObject(resKeyName, targetObject, ci); resKeyBase += resKeyName; } } else { resKeyBase += resKeyNameProp; } } } // If no result was found, convert the input and add it to the buffer. if (result == null && input != null) { result = this.Converter.Convert(input, targetType, this.ConverterParameter, ci); ResourceBuffer.Add(resKeyBase, result); } return(result); }
/// <summary> /// This function returns the properly prepared output of the markup extension. /// </summary> /// <param name="info">Information about the target.</param> /// <param name="endPoint">Information about the endpoint.</param> public override object FormatOutput(TargetInfo endPoint, TargetInfo info) { object result = null; if (endPoint == null) { return(null); } else { lastEndpoint = SafeTargetInfo.FromTargetInfo(endPoint); } var targetObject = endPoint.TargetObject as DependencyObject; // Get target type. Change ImageSource to BitmapSource in order to use our own converter. var targetType = info.TargetPropertyType; if (targetType.Equals(typeof(System.Windows.Media.ImageSource))) { targetType = typeof(BitmapSource); } // In case of a list target, get the correct list element type. if ((info.TargetPropertyIndex != -1) && typeof(IList).IsAssignableFrom(info.TargetPropertyType)) { targetType = info.TargetPropertyType.GetGenericArguments()[0]; } // Try to get the localized input from the resource. var resourceKey = LocalizeDictionary.Instance.GetFullyQualifiedResourceKey(this.Key, targetObject); var ci = GetForcedCultureOrDefault(); // Extract the names of the endpoint object and property var epProp = GetPropertyName(endPoint.TargetProperty); var epName = ""; if (endPoint.TargetObject is FrameworkElement) { epName = ((FrameworkElement)endPoint.TargetObject).GetValueSync <string>(FrameworkElement.NameProperty); } else if (endPoint.TargetObject is FrameworkContentElement) { epName = ((FrameworkContentElement)endPoint.TargetObject).GetValueSync <string>(FrameworkContentElement.NameProperty); } var resKeyBase = ci.Name + ":" + targetType.Name + ":"; // Check, if the key is already in our resource buffer. object input = null; var isDefaultConverter = this.Converter is DefaultConverter; if (!String.IsNullOrEmpty(resourceKey)) { // We've got a resource key. Try to look it up or get it from the dictionary. if (isDefaultConverter && ResourceBuffer.ContainsKey(resKeyBase + resourceKey)) { result = ResourceBuffer[resKeyBase + resourceKey]; } else { input = LocalizeDictionary.Instance.GetLocalizedObject(resourceKey, targetObject, ci); resKeyBase += resourceKey; } } else { var resKeyNameProp = LocalizeDictionary.Instance.GetFullyQualifiedResourceKey(epName + LocalizeDictionary.GetSeparation(targetObject) + epProp, targetObject); // Try the automatic lookup function. // First, look for a resource entry named: [FrameworkElement name][Separator][Property name] if (isDefaultConverter && ResourceBuffer.ContainsKey(resKeyBase + resKeyNameProp)) { result = ResourceBuffer[resKeyBase + resKeyNameProp]; } else { // It was not stored in the buffer - try to retrieve it from the dictionary. input = LocalizeDictionary.Instance.GetLocalizedObject(resKeyNameProp, targetObject, ci); if (input == null) { var resKeyName = LocalizeDictionary.Instance.GetFullyQualifiedResourceKey(epName, targetObject); // Now, try to look for a resource entry named: [FrameworkElement name] // Note - this has to be nested here, as it would take precedence over the first step in the buffer lookup step. if (isDefaultConverter && ResourceBuffer.ContainsKey(resKeyBase + resKeyName)) { result = ResourceBuffer[resKeyBase + resKeyName]; } else { input = LocalizeDictionary.Instance.GetLocalizedObject(resKeyName, targetObject, ci); resKeyBase += resKeyName; } } else { resKeyBase += resKeyNameProp; } } } // If no result was found, convert the input and add it to the buffer. if (result == null) { if (input != null) { result = this.Converter.Convert(input, targetType, this.ConverterParameter, ci); if (isDefaultConverter) { SafeAddItemToResourceBuffer(resKeyBase, result); } } else { if (LocalizeDictionary.Instance.OnNewMissingKeyEvent(this, key)) { UpdateNewValue(); } if (!string.IsNullOrEmpty(key) && (targetType == typeof(String) || targetType == typeof(object))) { result = "Key: " + key; } } } return(result); }
/// <summary> /// Initializes a new instance of the BaseLocalizeExtension class. /// </summary> /// <param name="key">Three types are supported: /// Direct: passed key = key; /// Dict/Key pair: this have to be separated like ResXDictionaryName:ResourceKey /// Assembly/Dict/Key pair: this have to be separated like ResXDictionaryName:ResourceKey</param> /// <remarks> /// This constructor register the <see cref="EventHandler"/><c>OnCultureChanged</c> on <c>LocalizeDictionary</c> /// to get an acknowledge of changing the culture /// </remarks> protected BaseLocalizeExtension(string key) : this() { // parse the key value and split it up if necessary LocalizeDictionary.ParseKey(key, out this.assembly, out this.dict, out this.key); }
protected override void InitializeShell() { #if DEBUG // Bypass Singleton check #else if (!Mutex.WaitOne(TimeSpan.Zero, true)) { NativeWin32.PostMessage((IntPtr)NativeWin32.HWND_BROADCAST, NativeWin32.WM_SHOWSAMBAPOS, IntPtr.Zero, IntPtr.Zero); Environment.Exit(1); } #endif Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; System.Net.ServicePointManager.Expect100Continue = false; LocalizeDictionary.ChangeLanguage(LocalSettings.CurrentLanguage); InteractionService.UserIntraction = ServiceLocator.Current.GetInstance <IUserInteraction>(); InteractionService.UserIntraction.ToggleSplashScreen(); ServiceLocator.Current.GetInstance <IApplicationState>().MainDispatcher = Application.Current.Dispatcher; var logger = ServiceLocator.Current.GetInstance <ILogService>(); var messagingService = ServiceLocator.Current.GetInstance <IMessagingService>(); messagingService.RegisterMessageListener(new MessageListener()); if (LocalSettings.StartMessagingClient) { messagingService.StartMessagingClient(); } PresentationServices.Initialize(); base.InitializeShell(); try { var creationService = new DataCreationService(); creationService.CreateData(); } catch (Exception e) { if (!string.IsNullOrEmpty(LocalSettings.ConnectionString)) { var connectionString = InteractionService.UserIntraction.GetStringFromUser( "Connection String", string.Format(Resources.ConnectionStringError, e.Message), LocalSettings.ConnectionString); var cs = String.Join(" ", connectionString); if (!string.IsNullOrEmpty(cs)) { LocalSettings.ConnectionString = cs.Trim(); } logger.LogError(e, Resources.RestartAppError); } else { logger.LogError(e); LocalSettings.ConnectionString = ""; } LocalSettings.SaveSettings(); Environment.Exit(1); } var rm = Container.GetExportedValue <IRegionManager>(); rm.RegisterViewWithRegion("MessageRegion", typeof(WorkPeriodStatusView)); rm.RegisterViewWithRegion("MessageRegion", typeof(MessageClientStatusView)); Application.Current.MainWindow = (Shell)Shell; if (LocalizeDictionary.Instance.Culture.TextInfo.IsRightToLeft) { Application.Current.MainWindow.FlowDirection = FlowDirection.RightToLeft; } ServiceLocator.Current.GetInstance <ITriggerService>().UpdateCronObjects(); ServiceLocator.Current.GetInstance <IDeviceService>().InitializeDevices(); InteractionService.UserIntraction.ToggleSplashScreen(); EntityCollectionSortManager.Load(LocalSettings.DocumentPath + "\\CollectionSort.txt"); Application.Current.MainWindow.Show(); EventServiceFactory.EventService.PublishEvent(EventTopicNames.ShellInitialized); Mouse.UpdateCursor(); }
protected override void InitializeShell() { LocalizeDictionary.ChangeLanguage(LocalSettings.CurrentLanguage); LocalSettings.SetTraceLogPath("app"); InteractionService.UserIntraction = ServiceLocator.Current.GetInstance <IUserInteraction>(); InteractionService.UserIntraction.ToggleSplashScreen(); AppServices.MainDispatcher = Application.Current.Dispatcher; AppServices.MessagingService.RegisterMessageListener(new MessageListener()); if (LocalSettings.StartMessagingClient) { AppServices.MessagingService.StartMessagingClient(); } GenericRuleRegistator.RegisterOnce(); PresentationServices.Initialize(); base.InitializeShell(); try { var creationService = new DataCreationService(); creationService.CreateData(); } catch (Exception e) { if (!string.IsNullOrEmpty(LocalSettings.ConnectionString)) { var connectionString = InteractionService.UserIntraction.GetStringFromUser( "Connection String", Resources.DatabaseErrorMessage + e.Message, LocalSettings.ConnectionString); var cs = String.Join(" ", connectionString); if (!string.IsNullOrEmpty(cs)) { LocalSettings.ConnectionString = cs.Trim(); } AppServices.LogError(e, Resources.CurrentErrorLoggedMessage); } else { AppServices.LogError(e); LocalSettings.ConnectionString = ""; } LocalSettings.SaveSettings(); Environment.Exit(1); } if (string.IsNullOrEmpty(LocalSettings.MajorCurrencyName)) { LocalSettings.MajorCurrencyName = Resources.Dollar; LocalSettings.MinorCurrencyName = Resources.Cent; LocalSettings.PluralCurrencySuffix = Resources.PluralCurrencySuffix; } Application.Current.MainWindow = (Shell)Shell; Application.Current.MainWindow.Show(); InteractionService.UserIntraction.ToggleSplashScreen(); TriggerService.UpdateCronObjects(); RuleExecutor.NotifyEvent(RuleEventNames.ApplicationStarted, new { CommandLineArguments = LocalSettings.StartupArguments }); }
public MainWindowViewModel() { //TODO: Para birimi servisinden al. LocalizeDictionary.ChangeLanguage(LocalSettings.CurrentLanguage); LocalSettings.SetTraceLogPath("term"); LocalSettings.DefaultCurrencyFormat = "#,#0.00"; LocalSettings.AppPath = System.IO.Path.GetDirectoryName(Application.ResourceAssembly.Location); AppServices.MainDispatcher = Application.Current.Dispatcher; GenericRuleRegistator.RegisterOnce(); TriggerService.UpdateCronObjects(); LoggedInUserViewModel = new LoggedInUserViewModel(); LoggedInUserViewModel.CloseButtonClickedEvent += LoggedInUserViewModelCloseButtonClickedEvent; LoginViewModel = new LoginViewModel(); LoginViewModel.PinSubmitted += LoginViewModelPinSubmitted; TableScreenViewModel = new TableScreenViewModel(); TableScreenViewModel.TableSelectedEvent += TableScreenViewModelTableSelectedEvent; TicketScreenViewModel = new TicketScreenViewModel(); TicketScreenViewModel.TicketSelectedEvent += TicketScreenViewModelTicketSelectedEvent; DepartmentSelectorViewModel = new DepartmentSelectorViewModel(); DepartmentSelectorViewModel.DepartmentSelected += DepartmentSelectorViewModelDepartmentSelected; TicketEditorViewModel = new TicketEditorViewModel(); TicketEditorViewModel.OnAddMenuItemsRequested += TicketEditorViewModel_OnAddMenuItemsRequested; TicketEditorViewModel.OnCloseTicketRequested += TicketEditorViewModel_OnCloseTicketRequested; TicketEditorViewModel.OnSelectTableRequested += TicketEditorViewModel_OnSelectTableRequested; TicketEditorViewModel.OnTicketNoteEditorRequested += TicketEditorViewModel_OnTicketNoteEditorRequested; TicketEditorViewModel.OnTicketTagEditorRequested += TicketEditorViewModel_OnTicketTagEditorRequested; MenuItemSelectorViewModel = new MenuItemSelectorViewModel(); MenuItemSelectorViewModel.OnTicketItemSelected += MenuItemSelectorViewModel_OnTicketItemSelected; SelectedTicketItemEditorViewModel = new SelectedTicketItemEditorViewModel(); SelectedTicketItemEditorViewModel.TagUpdated += SelectedTicketItemEditorViewModelTagUpdated; PermissionRegistry.RegisterPermission(PermissionNames.AddItemsToLockedTickets, PermissionCategories.Ticket, "Kilitli adisyona ekleme yapabilir"); PermissionRegistry.RegisterPermission(PermissionNames.GiftItems, PermissionCategories.Ticket, "İkram yapabilir"); PermissionRegistry.RegisterPermission(PermissionNames.VoidItems, PermissionCategories.Ticket, "İade alabilir"); PermissionRegistry.RegisterPermission(PermissionNames.MoveTicketItems, PermissionCategories.Ticket, "Adisyon satırlarını taşıyabilir"); PermissionRegistry.RegisterPermission(PermissionNames.MoveUnlockedTicketItems, PermissionCategories.Ticket, "Kilitlenmemiş adisyon satırlarını taşıyabilir"); PermissionRegistry.RegisterPermission(PermissionNames.ChangeExtraProperty, PermissionCategories.Ticket, "Ekstra özellik girebilir"); AppServices.MessagingService.RegisterMessageListener(new MessageListener()); if (LocalSettings.StartMessagingClient) { AppServices.MessagingService.StartMessagingClient(); } EventServiceFactory.EventService.GetEvent <GenericEvent <Message> >().Subscribe( x => { if (SelectedIndex == 2 && x.Topic == EventTopicNames.MessageReceivedEvent && x.Value.Command == Messages.TicketRefreshMessage) { TableScreenViewModel.Refresh(); } }); }
protected override void InitializeShell() { #if DEBUG // Bypass Singleton check #else if (!Mutex.WaitOne(TimeSpan.Zero, true)) { NativeWin32.PostMessage((IntPtr)NativeWin32.HWND_BROADCAST, NativeWin32.WM_SHOWSAMBAPOS, IntPtr.Zero, IntPtr.Zero); Environment.Exit(1); } #endif LocalizeDictionary.ChangeLanguage(LocalSettings.CurrentLanguage); InteractionService.UserIntraction = ServiceLocator.Current.GetInstance <IUserInteraction>(); InteractionService.UserIntraction.ToggleSplashScreen(); AppServices.MainDispatcher = Application.Current.Dispatcher; AppServices.MessagingService.RegisterMessageListener(new MessageListener()); if (LocalSettings.StartMessagingClient) { AppServices.MessagingService.StartMessagingClient(); } PresentationServices.Initialize(); base.InitializeShell(); try { GenericRuleRegistator.RegisterOnce(); var creationService = new DataCreationService(); creationService.CreateData(); } catch (Exception e) { if (!string.IsNullOrEmpty(LocalSettings.ConnectionString)) { var connectionString = InteractionService.UserIntraction.GetStringFromUser( "Connection String", "Şu anki bağlantı ayarları ile veri tabanına bağlanılamıyor. Lütfen aşağıdaki bağlantı bilgisini kontrol ederek tekrar deneyiniz.\r\r" + "Hata Mesajı:\r" + e.Message, LocalSettings.ConnectionString); var cs = String.Join(" ", connectionString); if (!string.IsNullOrEmpty(cs)) { LocalSettings.ConnectionString = cs.Trim(); } AppServices.LogError(e, "Programı yeniden başlatınız. Mevcut problem log dosyasına kaydedildi."); } else { AppServices.LogError(e); LocalSettings.ConnectionString = ""; } LocalSettings.SaveSettings(); Environment.Exit(1); } var rm = Container.GetExportedValue <IRegionManager>(); rm.RegisterViewWithRegion("MessageRegion", typeof(WorkPeriodStatusView)); rm.RegisterViewWithRegion("MessageRegion", typeof(MessageClientStatusView)); Application.Current.MainWindow = (Shell)Shell; Application.Current.MainWindow.Show(); EventServiceFactory.EventService.PublishEvent(EventTopicNames.ShellInitialized); InteractionService.UserIntraction.ToggleSplashScreen(); ServiceLocator.Current.GetInstance <ITriggerService>().UpdateCronObjects(); ServiceLocator.Current.GetInstance <IAutomationService>().NotifyEvent(RuleEventNames.ApplicationStarted, new { }); }