App.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. string stream = (string)Properties.Resources.ResourceManager.GetObject(sdkLicensePath);
  17. XmlDocument xmlDocument = new XmlDocument();
  18. if (!File.Exists(sdkLicensePath))
  19. {
  20. return;
  21. }
  22. xmlDocument.LoadXml(stream);
  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. /// <summary>
  32. /// Interaction logic for App.xaml
  33. /// </summary>
  34. ///
  35. public partial class App : Application
  36. {
  37. protected override void OnStartup(StartupEventArgs e)
  38. {
  39. string str = this.GetType().Assembly.Location;
  40. base.OnStartup(e);
  41. LicenseVerify();
  42. }
  43. private static bool LicenseVerify()
  44. {
  45. bool result = false;
  46. try
  47. {
  48. result = CPDFSDKVerifier.LoadNativeLibrary();
  49. if (!result)
  50. return false;
  51. }
  52. catch
  53. {}
  54. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  55. try
  56. {
  57. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  58. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  59. return false;
  60. }
  61. catch { }
  62. return result;
  63. }
  64. }
  65. }