App.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. try
  42. {
  43. if (!CPDFSDKVerifier.LoadNativeLibrary())
  44. {
  45. return false;
  46. }
  47. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  48. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  49. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  50. {
  51. return false;
  52. }
  53. return true;
  54. }
  55. catch(Exception ex)
  56. {
  57. }
  58. return false;
  59. }
  60. }
  61. }