App.xaml.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. SetUiLanguage();
  21. DispatcherUnhandledException += App_DispatcherUnhandledException;
  22. }
  23. private bool onlyOnce = true;
  24. private async void Test()
  25. {
  26. if (!onlyOnce)
  27. {
  28. return;
  29. }
  30. onlyOnce = false;
  31. //var test = new SajectConnectSajet2("ATC_TEST01");
  32. //bool result = false;
  33. //result = test.SajetTransStart();
  34. //await Task.Delay(5_000);
  35. //string userId = "001";
  36. //result = test.SajetTransSignIn(ref userId);
  37. //await Task.Delay(5_000);
  38. //result = test.SajetTransSnCheck("6300D000033-R00", "PL110001006");
  39. //result = test.SajetTransReport("6300D000033-R00", "PL110001006" , new Dictionary<string, string>() { {"Header1","Value1"} });
  40. //result = test.SajetTranFinishFail("6300D000033-R00", "PL110001006", MesErrorCode.BlueButtonTestFail);
  41. //result = test.SajetTranFinishSuccess("6300D000033-R00", "PL110001006");
  42. //result = test.SajetTransClose();
  43. }
  44. protected override void OnActivated(EventArgs e)
  45. {
  46. base.OnActivated(e);
  47. SetUiLanguage();
  48. Test();
  49. }
  50. private void SetUiLanguage()
  51. {
  52. var langSetting = AppSettingConfig.Language;
  53. if (langSetting.ToLower() == "zh-chs")
  54. {
  55. Resx.AppResources.Culture = System.Globalization.CultureInfo.GetCultureInfo("zh-CHS");
  56. }
  57. else
  58. {
  59. Resx.AppResources.Culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
  60. }
  61. }
  62. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  63. {
  64. var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
  65. var msg = e.Exception.Message + "\n" + e.Exception.StackTrace;
  66. File.WriteAllText(fileName, msg);
  67. MessageBox.Show($"App crashed,Please report error and send back {fileName}");
  68. Application.Current.Shutdown();
  69. }
  70. protected override void OnExit(ExitEventArgs e)
  71. {
  72. base.OnExit(e);
  73. if (SajetConnect.Instance != null)
  74. {
  75. var stopResult = SajetConnect.SajetTransClose();
  76. }
  77. Environment.Exit(0);
  78. }
  79. }
  80. }