HomeController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Cksoft.Unity;
  7. using DllParamCheckServer;
  8. using Microsoft.AspNetCore.Mvc;
  9. namespace WebMainHsms.Controllers
  10. {
  11. public class HomeController : Controller
  12. {
  13. public IParamCheckServer CurrSec { get; set; }
  14. //自动注入服务
  15. public HomeController(IParamCheckServer psecs)
  16. {
  17. CurrSec = psecs;
  18. }
  19. public IActionResult Index()
  20. {
  21. //CurrSec.StartAll();
  22. //List<MacOrder> lists = CurrSec.GetMacOrder();
  23. return View();
  24. }
  25. public IActionResult About()
  26. {
  27. ViewData["Message"] = "Your application description page.";
  28. return View();
  29. }
  30. public IActionResult Contact()
  31. {
  32. ViewData["Message"] = "Your contact page.";
  33. return View();
  34. }
  35. public IActionResult Privacy()
  36. {
  37. return View();
  38. }
  39. public ActionResult GetStatus()
  40. {
  41. try
  42. {
  43. string temperrorinfo = "";
  44. int result = CurrSec.GetStatus(ref temperrorinfo);
  45. return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson());
  46. }
  47. catch (Exception ex)
  48. {
  49. return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson());
  50. }
  51. }
  52. public ActionResult Start()
  53. {
  54. try
  55. {
  56. string temperrorinfo = "";
  57. int result = CurrSec.Start(ref temperrorinfo);
  58. return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson());
  59. }
  60. catch (Exception ex)
  61. {
  62. return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson());
  63. }
  64. }
  65. public ActionResult GetInfo()
  66. {
  67. try
  68. {
  69. List<ServerInfo> info = CurrSec.GetInfo();
  70. return Content(info.ToJson());
  71. //Newtonsoft.Json.JsonSerializerSettings jsonformat = new Newtonsoft.Json.JsonSerializerSettings();
  72. //jsonformat.DateFormatString = "yyyy-MM-dd hh:mm:ss";
  73. //return Json(info, jsonformat);
  74. //return Json(info);
  75. }
  76. catch (Exception ex)
  77. {
  78. return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson());
  79. }
  80. }
  81. [HttpPost]
  82. public ActionResult GetCount()
  83. {
  84. try
  85. {
  86. long result = CurrSec.GetAccount();
  87. return Content(new { resultcode = 1, errorinfo = result }.ToJson());
  88. }
  89. catch (Exception ex)
  90. {
  91. return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson());
  92. }
  93. }
  94. public ActionResult Stop()
  95. {
  96. try
  97. {
  98. string temperrorinfo = "";
  99. int result = CurrSec.Stop(ref temperrorinfo);
  100. return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson());
  101. }
  102. catch (Exception ex)
  103. {
  104. return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson());
  105. }
  106. }
  107. public ActionResult ClearInfo()
  108. {
  109. try
  110. {
  111. string temperrorinfo = "";
  112. int result = CurrSec.ClearInfo(ref temperrorinfo);
  113. return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson());
  114. }
  115. catch (Exception ex)
  116. {
  117. return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson());
  118. }
  119. }
  120. }
  121. }