LicenseManager.cs 1.8 KB

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