App.xaml.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using ComPDFKit.NativeMethod;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Xml;
  11. using static ComPDFKit.NativeMethod.CPDFSDKVerifier;
  12. namespace annotation_ctrl_demo
  13. {
  14. public class SDKLicenseHelper
  15. {
  16. public string key = string.Empty;
  17. public string secret = string.Empty;
  18. public SDKLicenseHelper()
  19. {
  20. string sdkLicensePath = "SDKLicense.xml";
  21. Assembly assembly = Assembly.GetExecutingAssembly();
  22. XmlDocument xmlDocument = new XmlDocument();
  23. xmlDocument.Load(sdkLicensePath);
  24. var node = xmlDocument.SelectSingleNode("License");
  25. if (node != null)
  26. {
  27. key = node.Attributes["key"].Value;
  28. secret = node.Attributes["secret"].Value;
  29. }
  30. }
  31. }
  32. /// <summary>
  33. /// App.xaml 的交互逻辑
  34. /// </summary>
  35. public partial class App : Application
  36. {
  37. protected override void OnStartup(StartupEventArgs e)
  38. {
  39. string str = this.GetType().Assembly.Location;
  40. base.OnStartup(e);
  41. LicenseVerify();
  42. }
  43. private static bool LicenseVerify()
  44. {
  45. bool result = false;
  46. try
  47. {
  48. result = CPDFSDKVerifier.LoadNativeLibrary();
  49. if (!result)
  50. return false;
  51. }
  52. catch
  53. { }
  54. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  55. try
  56. {
  57. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  58. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  59. return false;
  60. }
  61. catch { }
  62. return result;
  63. }
  64. }
  65. }