ApiAipService.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using AipGateway.AIP;
  2. using AipGateway.API.Application;
  3. using AipGateway.API.Application.Interfaces.Services;
  4. using AipGateway.API.Domain.Models.Response;
  5. using AipGateway.API.Services.Interfaces;
  6. namespace AipGateway.API.Services
  7. {
  8. public class ApiAipService : BaseService, IApiAipService
  9. {
  10. private readonly ILogger<ApiAipService> _log;
  11. private readonly IAipFileService _aipFileService;
  12. public ApiAipService(ILogger<ApiAipService> log, IAipFileService aipFileService)
  13. : base(aipFileService)
  14. {
  15. _log = log;
  16. _aipFileService = aipFileService;
  17. }
  18. public async Task<GeneralResponse> DownloadAipInfo()
  19. {
  20. try
  21. {
  22. var task = Task.Run(() =>
  23. {
  24. int result = _aipFileService.DownloadAipFileInformations();
  25. return result;
  26. });
  27. int result = await task;
  28. return new GeneralResponse
  29. {
  30. errorCode = 0,
  31. errorMessage = GlobalConstants.API_RESULT_SUCCESS,
  32. effectCount = result,
  33. };
  34. }
  35. catch (Exception e)
  36. {
  37. _log.LogError($"{e}");
  38. throw;
  39. }
  40. }
  41. public async Task<List<AipLabel>> GetLabels()
  42. {
  43. try
  44. {
  45. var task = Task.Run(() =>
  46. {
  47. return _aipFileService.aipFileManager.SensitivityLabels();
  48. });
  49. List<AipLabel> result = await task;
  50. return result;
  51. }
  52. catch (Exception)
  53. {
  54. throw;
  55. }
  56. }
  57. public async Task<List<AipLabel>> GetPolicies()
  58. {
  59. try
  60. {
  61. var task = Task.Run(() =>
  62. {
  63. return _aipFileService.aipFileManager.ListSensitivityLabels();
  64. });
  65. List<AipLabel> result = await task;
  66. return result;
  67. }
  68. catch (Exception)
  69. {
  70. throw;
  71. }
  72. }
  73. public async Task<List<AipTemplate>> GetProtections()
  74. {
  75. try
  76. {
  77. var task = Task.Run(() =>
  78. {
  79. return _aipFileService.aipFileManager.GetTemplates();
  80. });
  81. List<AipTemplate> result = await task;
  82. return result;
  83. }
  84. catch (Exception)
  85. {
  86. throw;
  87. }
  88. }
  89. }
  90. }