App.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 = "license_key_win.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. result = CPDFSDKVerifier.LoadNativeLibrary();
  47. if (!result)
  48. return false;
  49. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  50. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  51. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  52. return false;
  53. return result;
  54. }
  55. }
  56. }