ProcedureBase.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. public async Task<bool> DoWork() {
  35. if (!IsActivated)
  36. return false;
  37. InfoLog = "";
  38. Logger.Print(Name + "Started");
  39. var result = await Run();
  40. Dispose();
  41. Status = result ? ProcedureStatus.PASS : ProcedureStatus.FAIL;
  42. Logger.Print(Name + "Complete");
  43. return result;
  44. }
  45. internal virtual async Task<bool> Run()
  46. {
  47. return true;
  48. }
  49. public void Reset()
  50. {
  51. Status = ProcedureStatus.IDLE;
  52. InfoLog = "";
  53. }
  54. internal async Task<bool> CheckAndCreateSocket()
  55. {
  56. TcpSerializer socketConnection = null;
  57. if (socketConnection == null || socketConnection.ConnectStatus == ConnectStatus.ConnectionFail ||
  58. socketConnection.ConnectStatus == ConnectStatus.DisConnected)
  59. {
  60. socketConnection = new Assist.TcpSerializer(ip:ServerIpAddress);
  61. await socketConnection.OpenAsync();
  62. if(socketConnection.ConnectStatus != ConnectStatus.Connected)
  63. {
  64. Logger.Print("EVSE tcp connection Failed,Check EVSE is connected", isError: true);
  65. return false;
  66. }
  67. Logger.Print("Connected");
  68. serialPortocol = new SerialPortocol(socketConnection);
  69. return true;
  70. }
  71. return true;
  72. }
  73. public async Task<bool> ChekCsuBootCompelete()
  74. {
  75. var result = await EvApi.ChekCsuBootCompelete();
  76. return result.Result;
  77. }
  78. public async Task<bool> CheckGetQueryAction()
  79. {
  80. var result = await EvApi.CheckGetQueryAction();
  81. return result.Result;
  82. }
  83. private void Dispose()
  84. {
  85. if(serialPortocol!=null)
  86. {
  87. try
  88. {
  89. serialPortocol.Close();
  90. }catch
  91. {
  92. }
  93. }
  94. }
  95. }
  96. }