App.xaml.cs 1.6 KB

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