App.xaml.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 ContentEditor
  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. public partial class App : Application
  33. {
  34. protected override void OnStartup(StartupEventArgs e)
  35. {
  36. base.OnStartup(e);
  37. LicenseVerify();
  38. }
  39. private static bool LicenseVerify()
  40. {
  41. bool result = false;
  42. result = CPDFSDKVerifier.LoadNativeLibrary();
  43. if (!result)
  44. return false;
  45. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  46. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  47. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  48. return false;
  49. return result;
  50. }
  51. }
  52. }