ProcedureBase.cs 3.3 KB

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