App.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Threading;
  10. using System.Xml;
  11. using ComPDFKit.NativeMethod;
  12. using Compdfkit_Tools.Helper;
  13. namespace PDFViewer
  14. {
  15. /// <summary>
  16. /// Interaction logic for App.xaml
  17. /// </summary>
  18. public partial class App: Application
  19. {
  20. static public bool DefaultPDFLoaded = false;
  21. public static List<string> OpenedFilePathList = new List<string>();
  22. public App()
  23. {
  24. this.DispatcherUnhandledException += App_DispatcherUnhandledException;
  25. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  26. TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
  27. }
  28. private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
  29. {
  30. var ex = e.Exception as Exception;
  31. if (ex != null)
  32. {
  33. MessageBox.Show("发生Task未处理异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
  34. }
  35. }
  36. private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  37. {
  38. if (e.ExceptionObject is System.Exception)
  39. {
  40. Exception ex = (System.Exception)e.ExceptionObject;
  41. MessageBox.Show("发生非UI线程异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
  42. }
  43. }
  44. private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  45. {
  46. e.Handled = true;
  47. MessageBox.Show("发生UI线程异常:" + e.Exception.Message + "\n" + e.Exception.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
  48. }
  49. protected override void OnStartup(StartupEventArgs e)
  50. {
  51. string str = this.GetType().Assembly.Location;
  52. base.OnStartup(e);
  53. LicenseVerify();
  54. }
  55. private static bool LicenseVerify()
  56. {
  57. bool result = false;
  58. result = CPDFSDKVerifier.LoadNativeLibrary();
  59. if (!result)
  60. return false;
  61. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  62. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  63. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  64. return false;
  65. return result;
  66. }
  67. }
  68. }