Connection.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using BO.AppServer.Metadata.Dto;
  5. using BO.AppServer.Metadata.Enums;
  6. using Quadarax.Foundation.Core.Data.Interface;
  7. using Quadarax.Foundation.Core.Data.Interface.Entity.Dto;
  8. using Quadarax.Foundation.Core.Logging;
  9. namespace BO.Connector.Console
  10. {
  11. public class Connection : AbstractConnection
  12. {
  13. #region *** Private fields ***
  14. protected override string ApiName => "Console";
  15. #endregion
  16. #region *** Constructors ***
  17. public Connection(Uri uriApiBase, TimeSpan timeout, ILogHandler log = null, bool isDumpContentEnabled = false) : base(uriApiBase, timeout, log, isDumpContentEnabled)
  18. {
  19. }
  20. #endregion
  21. #region *** CRUD User ***
  22. public async Task<UserRDto> GetUserAsync(IdentificationTypeEnum identificationType, string identificationValue)
  23. {
  24. CheckIsOpen();
  25. var result = await CallRequestAsync<ResultValueDto<UserRDto>>($"{Ticket}/user/{identificationType}/{identificationValue}", RestCallTypeEnum.Get);
  26. return result.Value;
  27. }
  28. public async Task<IEnumerable<UserRDto>> GetUsersAsync(UserScopeEnums scope, PagingDto paging = null)
  29. {
  30. CheckIsOpen();
  31. var result = await CallRequestAsync<ResultsValueDto<UserRDto>>($"{Ticket}/users/{scope}", RestCallTypeEnum.Get,null, GetPagingHeaderAttributes(paging));
  32. return result.Values;
  33. }
  34. public async Task<UserRDto> CreateUserAsync(UserCDto newUser)
  35. {
  36. CheckIsOpen();
  37. var result = await CallRequestAsync<ResultValueDto<UserRDto>>($"{Ticket}/user", RestCallTypeEnum.Post, newUser);
  38. return result.Value;
  39. }
  40. public async Task<UserRDto> UpdateUserAsnc(IdentificationTypeEnum identificationType, string identificationValue, UserUDto updateUser)
  41. {
  42. CheckIsOpen();
  43. var result = await CallRequestAsync<ResultValueDto<UserRDto>>($"{Ticket}/user/{identificationType}/{identificationValue}", RestCallTypeEnum.Put, updateUser);
  44. return result.Value;
  45. }
  46. public async Task<UserRDto> DeleteUserAsync(IdentificationTypeEnum identificationType, string identificationValue)
  47. {
  48. CheckIsOpen();
  49. var result = await CallRequestAsync<ResultValueDto<UserRDto>>($"{Ticket}/user/{identificationType}/{identificationValue}", RestCallTypeEnum.Delete);
  50. return result.Value;
  51. }
  52. #endregion
  53. #region *** Statistics ***
  54. public async Task<IEnumerable<StatisticsDto>> GetStatisticsAsync(StatisticsScopeEnums scope, PagingDto paging = null)
  55. {
  56. CheckIsOpen();
  57. var result = await CallRequestAsync<ResultsValueDto<StatisticsDto>>($"{Ticket}/statistics/{scope}", RestCallTypeEnum.Get,null,GetPagingHeaderAttributes(paging));
  58. return result.Values;
  59. }
  60. public async Task<IEnumerable<AssemblyInfoDto>> GetVersionsAsync()
  61. {
  62. CheckIsOpen();
  63. var result = await CallRequestAsync<ResultsValueDto<AssemblyInfoDto>>($"{Ticket}/versions", RestCallTypeEnum.Get);
  64. return result.Values;
  65. }
  66. #endregion
  67. #region *** CRUD BillingPlan ***
  68. public async Task<BillingPlanRDto> CreateBillingPlanAsync(BillingPlanCDto newBillingPlan)
  69. {
  70. CheckIsOpen();
  71. var result = await CallRequestAsync<ResultValueDto<BillingPlanRDto>>($"{Ticket}/bplan", RestCallTypeEnum.Post,newBillingPlan);
  72. return result.Value;
  73. }
  74. public async Task<BillingPlanRDto> UpdateBillingPlanAsync(BillingPlanUDto updBillingPlan)
  75. {
  76. CheckIsOpen();
  77. var result = await CallRequestAsync<ResultValueDto<BillingPlanRDto>>($"{Ticket}/bplan", RestCallTypeEnum.Put,updBillingPlan);
  78. return result.Value;
  79. }
  80. public async Task<IEnumerable<BillingPlanRDto>> GetBillingPlansAsync(BPlanScopeEnums scope, PagingDto paging = null)
  81. {
  82. CheckIsOpen();
  83. var result = await CallRequestAsync<ResultsValueDto<BillingPlanRDto>>($"{Ticket}/bplans/{scope}", RestCallTypeEnum.Get,null,GetPagingHeaderAttributes(paging));
  84. return result.Values;
  85. }
  86. #endregion
  87. #region *** CRUD MIME Type ***
  88. public async Task<MimeTypeRDto> CreateMimeTypeAsync(MimeTypeCDto newMimeType)
  89. {
  90. CheckIsOpen();
  91. var result = await CallRequestAsync<ResultValueDto<MimeTypeRDto>>($"{Ticket}/mtype", RestCallTypeEnum.Post,newMimeType);
  92. return result.Value;
  93. }
  94. public async Task<MimeTypeRDto> UpdateMimeTypeAsync(MimeTypeUDto updMimeType)
  95. {
  96. CheckIsOpen();
  97. var result = await CallRequestAsync<ResultValueDto<MimeTypeRDto>>($"{Ticket}/mtype", RestCallTypeEnum.Put,updMimeType);
  98. return result.Value;
  99. }
  100. public async Task<IEnumerable<MimeTypeRDto>> GetMimeTypesAsync(MimeTypeScopeEnums scope, PagingDto paging = null)
  101. {
  102. CheckIsOpen();
  103. var result = await CallRequestAsync<ResultsValueDto<MimeTypeRDto>>($"{Ticket}/mtypes/{scope}", RestCallTypeEnum.Get,null,GetPagingHeaderAttributes(paging));
  104. return result.Values;
  105. }
  106. #endregion
  107. #region *** Documents ***
  108. public async Task<IEnumerable<DocumentRDto>> GetDocumentsAsync(MimeTypeScopeEnums scope,IdentificationTypeEnum identificationType, string identificationValue, PagingDto paging = null)
  109. {
  110. CheckIsOpen();
  111. var result = await CallRequestAsync<ResultsValueDto<DocumentRDto>>($"{Ticket}/documents/{identificationType}/{identificationValue}/{scope}", RestCallTypeEnum.Get,null,GetPagingHeaderAttributes(paging));
  112. return result.Values;
  113. }
  114. #endregion
  115. #region *** Workspace ***
  116. public async Task<WorkspaceRDto> CreateWorkspaceAsync(WorkspaceCDto workspace)
  117. {
  118. CheckIsOpen();
  119. var result = await CallRequestAsync<ResultValueDto<WorkspaceRDto>>($"{Ticket}/workspace", RestCallTypeEnum.Post,workspace);
  120. return result.Value;
  121. }
  122. public async Task<IEnumerable<WorkspaceRDto>> GetWorkspacesAsync(WorkspaceScopeEnums scope,string userContext, PagingDto paging = null)
  123. {
  124. CheckIsOpen();
  125. var headers = GetPagingHeaderAttributes(paging);
  126. headers.Add("context", userContext);
  127. var result = await CallRequestAsync<ResultsValueDto<WorkspaceRDto>>($"{Ticket}/workspaces/{scope}", RestCallTypeEnum.Get,null,headers);
  128. return result.Values;
  129. }
  130. #endregion
  131. }
  132. }