ApiDummyController.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using AipGateway.API.Application;
  2. using AipGateway.API.Domain.IRepositories.IGenericRepositories;
  3. using AipGateway.API.Domain.Models;
  4. using AipGateway.API.Domain.Models.Request;
  5. using AipGateway.API.Domain.Models.Response;
  6. using AipGateway.API.Extensions;
  7. using AipGateway.API.Service.Models;
  8. using AipGateway.API.Services;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Swashbuckle.AspNetCore.Annotations;
  11. namespace AipGateway.API.Controllers
  12. {
  13. [ApiController]
  14. [Route("/api/v1/dummy")]
  15. [Produces("application/json")]
  16. public class ApiDummyController : BaseModule
  17. {
  18. private readonly ILogger<ApiDummyController> _log;
  19. private readonly IApiDummyService _apiDummyService;
  20. public ApiDummyController(
  21. ILogger<ApiDummyController> logger,
  22. IUnitOfWork unitOfWork,
  23. IWebHostEnvironment webHostEnvironment,
  24. IApiDummyService apiDummyService)
  25. : base(unitOfWork, webHostEnvironment)
  26. {
  27. _log = logger;
  28. _apiDummyService = apiDummyService;
  29. }
  30. /// <remarks>
  31. /// Sample request:
  32. ///
  33. /// GET /linked-systems
  34. /// {
  35. /// "id": 1,
  36. /// "name": "Item #1",
  37. /// "isComplete": true
  38. /// }
  39. ///
  40. /// </remarks>
  41. [HttpGet("")]
  42. [SwaggerResponse(200, type: typeof(SuccessResponseModel<GeneralResponse>))]
  43. public async Task<IResult> GetDummy()
  44. {
  45. //GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_DUMMY, apiKey);
  46. return await CreateResponseAsync(async () =>
  47. {
  48. var response = new GeneralResponse
  49. {
  50. effectCount = 0,
  51. errorCode = 0,
  52. errorMessage = GlobalConstants.API_RESULT_SUCCESS,
  53. };
  54. var result = Results.Ok(new SuccessResponseModel<GeneralResponse>()
  55. {
  56. Message = GlobalConstants.API_RESULT_SUCCESS,
  57. Result = response,
  58. StatusCode = System.Net.HttpStatusCode.OK,
  59. Success = true
  60. });
  61. HttpContext.Items[GlobalConstants.API_RESULT] = result;
  62. return result;
  63. });
  64. }
  65. [HttpPost("file-data")]
  66. public FileData GetFileData([FromQuery] RequestFile file)
  67. {
  68. FileData result = new FileData();
  69. try
  70. {
  71. //Console.WriteLine("0.::::::::::::::::::::::::::::::::::::::::::::::::::::::: {0}", file.name);
  72. if (System.IO.File.Exists(file.realFileName))
  73. {
  74. using (FileStream fs = System.IO.File.OpenRead(file.realFileName))
  75. {
  76. using (var reader = new BinaryReader(fs))
  77. {
  78. result.byteDataArr = reader.ReadBytes((int)fs.Length);
  79. result.base64Data = Convert.ToBase64String(result.byteDataArr);
  80. //result.streamData = new MemoryStream();
  81. //result.streamData.Write(result.byteDataArr, 0, result.byteDataArr.Length);
  82. }
  83. var bytes = Convert.FromBase64String(result.base64Data);
  84. var contents = new StreamContent(new MemoryStream(bytes));
  85. //Console.WriteLine("{0}", contents);
  86. var stream = new MemoryStream(Convert.FromBase64String(result.base64Data));
  87. //if (file.name.Contains(".txt"))
  88. //{
  89. // System.IO.File.WriteAllBytes(@"c:\data\sample.txt.txt", Convert.FromBase64String(result.base64Data));
  90. //}
  91. //else
  92. //{
  93. // System.IO.File.WriteAllBytes(@"c:\data\sample.txt.pptx", Convert.FromBase64String(result.base64Data));
  94. //}
  95. }
  96. }
  97. }
  98. catch (Exception ex)
  99. {
  100. //Console.WriteLine("{0}", ex.Message);
  101. _log.LogError(ex, "AipFileController::GetFileData.");
  102. }
  103. return result;
  104. }
  105. }
  106. }