DevOpsController.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using ProductionLineMonitor.Application.Services.CimService.Dtos;
  4. using ProductionLineMonitor.Core.Dtos;
  5. using System.Net.Http;
  6. using System.Text;
  7. using System.Text.Json;
  8. namespace ProductionLineMonitor.Web.Controllers
  9. {
  10. public class DevOpsController : BaseController
  11. {
  12. public IActionResult Index()
  13. {
  14. return View();
  15. }
  16. public IActionResult GetCimPasswords()
  17. {
  18. try
  19. {
  20. HttpClient httpClient = new HttpClient();
  21. using HttpResponseMessage response = httpClient
  22. .GetAsync(Config.SafeguardUrl + "/api/Cims").Result;
  23. var jsonResponse = response.Content.ReadAsStringAsync().Result;
  24. return Ok(jsonResponse);
  25. }
  26. catch (System.Exception ex)
  27. {
  28. return Ok(ResultDto.Fail(ex.Message));
  29. }
  30. }
  31. public IActionResult SetCimPassword([FromBody] CimPasswordDto dto)
  32. {
  33. try
  34. {
  35. HttpClient httpClient = new HttpClient();
  36. using StringContent jsonContent = new StringContent(
  37. JsonSerializer.Serialize(new
  38. {
  39. No = dto.No,
  40. Password = dto.Password,
  41. Enabled = dto.Enabled,
  42. }),
  43. Encoding.UTF8, "application/json");
  44. using HttpResponseMessage response = httpClient
  45. .PostAsync(Config.SafeguardUrl + "/api/Cim/SetPassword", jsonContent).Result;
  46. var jsonResponse = response.Content.ReadAsStringAsync().Result;
  47. return Ok(jsonResponse);
  48. }
  49. catch (System.Exception ex)
  50. {
  51. return Ok(ResultDto.Fail(ex.Message));
  52. }
  53. }
  54. [HttpPost]
  55. public IActionResult UploadAlarmFile(IFormFile file)
  56. {
  57. try
  58. {
  59. if (file == null || file.Length == 0)
  60. {
  61. return Ok(ResultDto.Fail("No file uploaded"));
  62. }
  63. return Ok("file uploaded successfully");
  64. }
  65. catch (System.Exception ex)
  66. {
  67. return Ok(ex.Message);
  68. }
  69. }
  70. }
  71. }