App.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using MesAdaptor;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. namespace AwInitilizer
  12. {
  13. /// <summary>
  14. /// Interaction logic for App.xaml
  15. /// </summary>
  16. public partial class App : Application
  17. {
  18. public App():base()
  19. {
  20. DispatcherUnhandledException += App_DispatcherUnhandledException;
  21. }
  22. protected override void OnActivated(EventArgs e)
  23. {
  24. base.OnActivated(e);
  25. SetUiLanguage();
  26. }
  27. private void SetUiLanguage()
  28. {
  29. var langSetting = AppSettingConfig.Language;
  30. if (langSetting.ToLower() == "zh-chs")
  31. {
  32. Cultures.CulturesHelper.Instance.ChangeCulture(System.Globalization.CultureInfo.GetCultureInfo("zh-CHS"));
  33. }
  34. else
  35. {
  36. Cultures.CulturesHelper.Instance.ChangeCulture(System.Globalization.CultureInfo.GetCultureInfo("en-US"));
  37. }
  38. }
  39. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  40. {
  41. var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
  42. var msg = e.Exception.Message + "\n"+ e.Exception.StackTrace;
  43. File.WriteAllText(fileName,msg);
  44. MessageBox.Show($"App crashed,Please report error and send back {fileName}");
  45. Application.Current.Shutdown();
  46. }
  47. protected override void OnExit(ExitEventArgs e)
  48. {
  49. base.OnExit(e);
  50. if (SajetConnect.Type != MesType.none)
  51. {
  52. var stopResult = SajetConnect.SajetTransClose();
  53. }
  54. Environment.Exit(0);
  55. }
  56. }
  57. }