LicenseManager.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Serilog;
  2. using System.Runtime.InteropServices;
  3. namespace AipGateway.AIP.Service
  4. {
  5. public static class LicenseManager
  6. {
  7. [DllImport("LicenseManager.dll", CallingConvention = CallingConvention.StdCall)]
  8. public static extern int ValidateLicense([In] string licenseFilePath, ref int licenseAccounts);
  9. public static int LocalValidateLicense()
  10. {
  11. int licenseAccounts = 0;
  12. try
  13. {
  14. // 현재 실행 위치의 한 단계 위 경로를 얻어옵니다.
  15. string currDirectory = Directory.GetCurrentDirectory();
  16. string? parentDirectory = Directory.GetParent(currDirectory)?.FullName;
  17. if (parentDirectory == null)
  18. {
  19. Log.Error("라이센스 파일의 경로를 얻지 못하였습니다.");
  20. return -1;
  21. }
  22. string licenseFilePath = Path.Combine(parentDirectory, "License", "license.xml");
  23. //Log.Information("LicenseFilePath: {0}, {1}", parentDirectory, licenseFilePath);
  24. if (!File.Exists(licenseFilePath))
  25. {
  26. Log.Error("라이센스 정보를 찾을 수 없습니다.");
  27. return -2;
  28. }
  29. int result = ValidateLicense(licenseFilePath, ref licenseAccounts);
  30. if (result != 0)
  31. {
  32. Log.Error("라이센스 정보가 일치하지 않습니다. [error Code: {0}]", result);
  33. return -3;
  34. }
  35. //Log.Information("라이센스 할당 Accounts: {0} EA.", licenseAccounts);
  36. }
  37. catch (Exception ex)
  38. {
  39. Log.Error("라이센스 파일 검증 오류...");
  40. Log.Error("라이센스 파일 검증 오류", ex);
  41. return -4;
  42. }
  43. return licenseAccounts;
  44. }
  45. }
  46. }