ApiAipService.cs 2.3 KB

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