ProcedureBase.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using AwInitilizer.Assist;
  2. using AwInitilizer.Interface;
  3. using AwInitilizer.Model;
  4. using CsuWebApiLib;
  5. using MesAdaptor;
  6. using Newtonsoft.Json;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.Specialized;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Net.Sockets;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading.Tasks;
  16. namespace AwInitilizer.Procedure
  17. {
  18. public enum ProcedureStatus
  19. {
  20. IDLE,PASS,FAIL
  21. }
  22. public class ProcedureBase
  23. {
  24. public string Name { get; set; }
  25. public string Content { get; set; }
  26. public bool IsActivated { get; set; } = true;
  27. public ProcedureStatus Status { get; private set; }
  28. public string InfoLog { get; internal set; }
  29. public static UpdateData UpdateData { get; set; }
  30. public static IIogger Logger { get; set; }
  31. public ValueReportDatas MesLogData { get; private set; } = new ValueReportDatas();
  32. public List<string> ReportLog { get; private set; } = new List<string>();
  33. internal SerialPortocol serialPortocol { get; private set; }
  34. internal static string ServerIpAddress = "192.168.1.10";
  35. //internal static string ServerIpAddress = "172.18.13.84";
  36. public async Task<bool> DoWork() {
  37. if (!IsActivated)
  38. return false;
  39. InfoLog = "";
  40. Logger.Print(Name + "Started");
  41. var result = await Run();
  42. Dispose();
  43. Status = result ? ProcedureStatus.PASS : ProcedureStatus.FAIL;
  44. Logger.Print(Name + "Complete");
  45. return result;
  46. }
  47. internal virtual async Task<bool> Run()
  48. {
  49. return true;
  50. }
  51. public void Reset()
  52. {
  53. Status = ProcedureStatus.IDLE;
  54. InfoLog = "";
  55. }
  56. internal async Task<bool> CheckAndCreateSocket()
  57. {
  58. string ipAddress = null;
  59. if (!string.IsNullOrEmpty(UpdateData.IpAddress))
  60. {
  61. ipAddress = UpdateData.IpAddress;
  62. }
  63. else
  64. {
  65. ipAddress = ServerIpAddress;
  66. }
  67. TcpSerializer socketConnection = null;
  68. if (socketConnection == null || socketConnection.ConnectStatus == ConnectStatus.ConnectionFail ||
  69. socketConnection.ConnectStatus == ConnectStatus.DisConnected)
  70. {
  71. socketConnection = new Assist.TcpSerializer(ip: ipAddress);
  72. await socketConnection.OpenAsync();
  73. if(socketConnection.ConnectStatus != ConnectStatus.Connected)
  74. {
  75. Logger.Print("EVSE tcp connection Failed,Check EVSE is connected", isError: true);
  76. return false;
  77. }
  78. Logger.Print("Connected");
  79. serialPortocol = new SerialPortocol(socketConnection);
  80. return true;
  81. }
  82. return true;
  83. }
  84. public async Task<bool> ChekCsuBootCompelete()
  85. {
  86. var result = await EvApi.ChekCsuBootCompelete();
  87. return result.Result;
  88. }
  89. public async Task<bool> CheckGetQueryAction()
  90. {
  91. var result = await EvApi.CheckGetQueryAction();
  92. return result.Result;
  93. }
  94. private void Dispose()
  95. {
  96. if(serialPortocol!=null)
  97. {
  98. try
  99. {
  100. serialPortocol.Close();
  101. }catch
  102. {
  103. }
  104. }
  105. }
  106. }
  107. }