App.xaml.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace DocsEditControl
  12. {
  13. public class SDKLicenseHelper
  14. {
  15. public string key = string.Empty;
  16. public string secret = string.Empty;
  17. public SDKLicenseHelper()
  18. {
  19. string sdkLicensePath = "license_key_windows.xml";
  20. Assembly assembly = Assembly.GetExecutingAssembly();
  21. XmlDocument xmlDocument = new XmlDocument();
  22. xmlDocument.Load(sdkLicensePath);
  23. var node = xmlDocument.SelectSingleNode("License");
  24. if (node != null)
  25. {
  26. key = node.Attributes["key"].Value;
  27. secret = node.Attributes["secret"].Value;
  28. }
  29. }
  30. }
  31. /// <summary>
  32. /// App.xaml 的交互逻辑
  33. /// </summary>
  34. public partial class App : Application
  35. {
  36. protected override void OnStartup(StartupEventArgs e)
  37. {
  38. string str = this.GetType().Assembly.Location;
  39. base.OnStartup(e);
  40. LicenseVerify();
  41. }
  42. private static bool LicenseVerify()
  43. {
  44. bool result = false;
  45. result = CPDFSDKVerifier.LoadNativeLibrary();
  46. if (!result)
  47. return false;
  48. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  49. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  50. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  51. return false;
  52. return result;
  53. }
  54. }
  55. }