App.xaml.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 DocsEditor
  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_win.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. public partial class App : Application
  32. {
  33. protected override void OnStartup(StartupEventArgs e)
  34. {
  35. string str = this.GetType().Assembly.Location;
  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. }