App.xaml.cs 1.9 KB

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