123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using AwInitilizer.Assist;
- using AwInitilizer.Interface;
- using AwInitilizer.Model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading.Tasks;
- namespace AwInitilizer.Procedure
- {
- public enum ProcedureStatus
- {
- Idle,Success,Failed
- }
- public class ProcedureBase
- {
- public string Name { get; set; }
- public string Content { get; set; }
- public bool IsActivated { get; set; } = true;
- public ProcedureStatus Status { get; private set; }
- public string InfoLog { get; internal set; }
- public static UpdateData UpdateData { get; set; }
- public static IIogger Logger { get; set; }
- public Dictionary<string, string> LogPair { get; private set; } = new Dictionary<string, string>();
- internal SerialPortocol serialPortocol { get; private set; }
- internal static string ServerIpAddress = "192.168.1.10";
- public async Task<bool> DoWork() {
- if (!IsActivated)
- return false;
- InfoLog = "";
- Logger.Print(Name + "Started");
- var result = await Run();
- Dispose();
- Status = result ? ProcedureStatus.Success : ProcedureStatus.Failed;
- Logger.Print(Name + "Complete");
- return result;
- }
- internal virtual async Task<bool> Run()
- {
- return true;
- }
- public void Reset()
- {
- Status = ProcedureStatus.Idle;
- InfoLog = "";
- }
- internal async Task<bool> CheckAndCreateSocket()
- {
- TcpSerializer socketConnection = null;
- if (socketConnection == null || socketConnection.ConnectStatus == ConnectStatus.ConnectionFail ||
- socketConnection.ConnectStatus == ConnectStatus.DisConnected)
- {
- socketConnection = new Assist.TcpSerializer(ip:ServerIpAddress);
- await socketConnection.OpenAsync();
- if(socketConnection.ConnectStatus != ConnectStatus.Connected)
- {
- Logger.Print("EVSE tcp connection Failed,Check EVSE is connected", isError: true);
- return false;
- }
- Logger.Print("Connected");
- serialPortocol = new SerialPortocol(socketConnection);
- return true;
- }
- return true;
- }
- private void Dispose()
- {
- if(serialPortocol!=null)
- {
- try
- {
- serialPortocol.Close();
- }catch
- {
- }
- }
- }
- }
- }
|