App.xaml.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using InitializerModel;
  2. using MesAdaptor;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. namespace AwInitilizer
  13. {
  14. /// <summary>
  15. /// Interaction logic for App.xaml
  16. /// </summary>
  17. public partial class App : Application
  18. {
  19. public App() : base()
  20. {
  21. SetUiLanguage();
  22. DispatcherUnhandledException += App_DispatcherUnhandledException;
  23. }
  24. private bool onlyOnce = true;
  25. private async void Test()
  26. {
  27. if (!onlyOnce)
  28. {
  29. return;
  30. }
  31. onlyOnce = false;
  32. //var test = new SajectConnectSajet2("ATC_TEST01");
  33. //bool result = false;
  34. //result = test.SajetTransStart();
  35. //await Task.Delay(5_000);
  36. //string userId = "001";
  37. //result = test.SajetTransSignIn(ref userId);
  38. //await Task.Delay(5_000);
  39. //result = test.SajetTransSnCheck("6300D000033-R00", "PL110001006");
  40. //result = test.SajetTransReport("6300D000033-R00", "PL110001006" , new Dictionary<string, string>() { {"Header1","Value1"} });
  41. //result = test.SajetTranFinishFail("6300D000033-R00", "PL110001006", MesErrorCode.BlueButtonTestFail);
  42. //result = test.SajetTranFinishSuccess("6300D000033-R00", "PL110001006");
  43. //result = test.SajetTransClose();
  44. }
  45. protected override void OnActivated(EventArgs e)
  46. {
  47. base.OnActivated(e);
  48. SetUiLanguage();
  49. Test();
  50. }
  51. private void SetUiLanguage()
  52. {
  53. var langSetting = AppSettingConfig.Instance.Language;
  54. if (langSetting.ToLower() == "zh-chs")
  55. {
  56. Resx.AppResources.Culture = System.Globalization.CultureInfo.GetCultureInfo("zh-CHS");
  57. }
  58. else
  59. {
  60. Resx.AppResources.Culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
  61. }
  62. }
  63. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  64. {
  65. var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
  66. var msg = e.Exception.Message + "\n" + e.Exception.StackTrace;
  67. File.WriteAllText(fileName, msg);
  68. MessageBox.Show($"App crashed,Please report error and send back {fileName}");
  69. Application.Current.Shutdown();
  70. }
  71. protected override void OnExit(ExitEventArgs e)
  72. {
  73. base.OnExit(e);
  74. if (SajetConnect.Instance != null)
  75. {
  76. var stopResult = SajetConnect.SajetTransClose();
  77. }
  78. Environment.Exit(0);
  79. }
  80. }
  81. }