App.xaml.cs 2.8 KB

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