123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- using System;
- using System.Globalization;
- using System.Linq;
- using System.Threading;
- using System.Windows;
- using System.Windows.Forms;
- using System.Windows.Media.Imaging;
- using Aitex.Core.Account;
- using Aitex.Core.RT.SCCore;
- using Aitex.Triton160.Common;
- using Aitex.Triton160.UI.Config;
- using Aitex.Triton160.UI.ViewModel;
- using Aitex.Triton160.UI.Views;
- using Aitex.Triton160.UI.Wcf;
- using Aitex.Core.UI.View.Frame;
- using Aitex.Core.Util;
- using Aitex.Core.RT.Log;
- using Application = System.Windows.Application;
- using MessageBox = System.Windows.Forms.MessageBox;
- namespace Aitex.Triton160.UI
- {
- class Triton160UiSystem : Singleton<Triton160UiSystem>
- {
- public string CurrentUserName
- {
- get; set;
- }
- public Action<string> CultureChanged;
- public string Culture
- {
- get; private set;
- }
- public WcfClient WCF { get { return WcfClient.Instance; } }
- public UiEvent EV { get { return _event; } }
- private UiEvent _event;
- private ViewManager _views;
- public bool Initialize()
- {
- try
- {
- _event = new UiEvent();
- SystemConfigManager.Instance.Initialize();
- Singleton<LogManager>.Instance.Initialize();
- WcfClient.Instance.Initialize();
- object language;
- int i = 0;
- do
- {
- language = WCF.Query.GetConfig(SCName.System_Language);
- i++;
- if (i == 100)
- break;
- Thread.Sleep(500);
- } while (language == null);
-
- _views = new ViewManager()
- {
- SystemName = "Triton160",
- SystemLogo = new BitmapImage(new Uri("pack://application:,,,/Resources/Triton160.ico", UriKind.Absolute)),
- UILayoutFile = SystemConfigManager.Instance.GetUiLayoutXmlFile() ,
- ViewAssembly = "Triton160UI",
- };
- SetCulture((language != null && (int)(language) == 2) ? "zh-CN" : "en-US");
-
- //try
- {
- _views.ShowMainWindow(false);
- _views.OnMainWindowLoaded += views_OnMainWindowLoaded;
- //登录对话框
- MainLogin mainLogin = new MainLogin();
- if (mainLogin.ShowDialog() == true)
- {
- Account account = Triton160UiSystem.Instance.WCF.Account.GetAccountInfo(Triton160UiSystem.Instance.CurrentUserName).AccountInfo;
- _views.SetViewPermission(account);
- _views.MainWindow.Show();
- }
- }
- }
- catch (Exception ex)
- {
- //System.Windows.Application.Current.Resources["All_Vehicles"]
- MessageBox.Show("系统初始化失败。\r\n" + ex.Message, "Triton160 UI系统初始化", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- return true;
- }
- void views_OnMainWindowLoaded()
- {
- _event.Start();
- }
- public void Logoff()
- {
-
- try
- {
- WCF.Account.Logout(CurrentUserName);
- _views.Logoff();
- }
- catch (Exception e)
- {
- LOG.Write(e);
- }
- }
- public void Terminate()
- {
- try
- {
- _event.Stop();
- WcfClient.Instance.Terminate();
- Singleton<LogManager>.Instance.Terminate();
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- public void SetCulture(string culture)
- {
- SelectCulture(culture);
- _views.SetCulture(culture);
- Culture = culture;
- if (CultureChanged != null)
- {
- CultureChanged(culture);
- }
- }
- void SelectCulture(string culture)
- {
- //string culture = language == 2 ? "zh-CN" : "en-US";
- //Copy all MergedDictionarys into a auxiliar list.
- var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList();
- //Search for the specified culture.
- string requestedCulture = string.Format(@"Resources/StringResources.{0}.xaml", culture);
- var resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
- if (resourceDictionary == null)
- {
- //If not found, select our default language.
- requestedCulture = "StringResources.xaml";
- resourceDictionary = dictionaryList.
- FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
- }
- //If we have the requested resource, remove it from the list and place at the end.
- //Then this language will be our string table to use.
- if (resourceDictionary != null)
- {
- Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
- Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
- }
- //Inform the threads of the new culture.
- Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
- Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
- }
- }
- }
|