| | |
| | | //using BroCComn.PubSub; |
| | | using static Bro.Common.Helper.EnumHelper; |
| | | using System.ComponentModel; |
| | | using System.IO; |
| | | |
| | | namespace Bro.Common.Base |
| | | { |
| | |
| | | [JsonIgnore] |
| | | public Action<EnumHelper.DeviceState> OnDeviceStateChanged { get; set; } |
| | | #endregion |
| | | |
| | | |
| | | int RetryTime = 3; |
| | | /// <summary> |
| | |
| | | |
| | | [JsonIgnore] |
| | | public Dictionary<DeviceInputMethodAttribute, MethodInfo> InputMethods { get; set; } = new Dictionary<DeviceInputMethodAttribute, MethodInfo>(); |
| | | |
| | | |
| | | |
| | | //public event DeviceStateChangedDelegate OnDeviceStateChanged; |
| | | |
| | |
| | | { |
| | | string currentStateStr = CurrentStateToBe.GetEnumDescription(); |
| | | string stateToBeStr = stateToBe.GetEnumDescription(); |
| | | throw new ProcessException($"{InitialConfig.Name}设备的当前状态为{currentStateStr},无法切换至{stateToBeStr}", null); |
| | | throw new ProcessException($"{InitialConfig.Name}设备的当前状态为{currentStateStr},无法切换至{stateToBeStr}"); |
| | | } |
| | | |
| | | CurrentState = EnumHelper.DeviceState.TBD; |
| | |
| | | } |
| | | else |
| | | { |
| | | throw new ProcessException($"{InitialConfig.Name}设备操作超时", null); |
| | | throw new ProcessException($"{InitialConfig.Name}设备操作超时"); |
| | | } |
| | | } |
| | | |
| | |
| | | //this.CurrentState = EnumHelper.DeviceState.DSExcept; |
| | | //this.CurrentStateToBe = EnumHelper.DeviceState.DSExcept; |
| | | |
| | | throw new ProcessException($"设备{InitialConfig.Name}的{CurrentStateToBe.GetEnumDescription()}操作重复3次失败", ex); |
| | | throw new ProcessException($"设备{InitialConfig.Name}的{CurrentStateToBe.GetEnumDescription()}操作重复3次失败", ExceptionLevel.Warning, ex); |
| | | } |
| | | } |
| | | } |
| | |
| | | CurrentUserId = obj; |
| | | } |
| | | #endregion |
| | | |
| | | #region 日志处理 |
| | | object logObject = new object(); |
| | | public virtual async void LogAsync(DateTime dt, string prefix, string msg) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | if (InitialConfig.IsEnableLog) |
| | | { |
| | | OnLog?.Invoke(dt, this, prefix + "\t" + msg); |
| | | |
| | | if (string.IsNullOrWhiteSpace(InitialConfig.LogPath) || !Path.IsPathRooted(InitialConfig.LogPath)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (!Directory.Exists(InitialConfig.LogPath)) |
| | | { |
| | | Directory.CreateDirectory(InitialConfig.LogPath); |
| | | } |
| | | |
| | | string filePath = Path.Combine(InitialConfig.LogPath, $"Log_{Name}_{DateTime.Now.ToString("yyyyMMdd")}.txt"); |
| | | lock (logObject) |
| | | { |
| | | using (StreamWriter writer = new StreamWriter(filePath, true, Encoding.UTF8)) |
| | | { |
| | | writer.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}\t{prefix}\t{msg}"); |
| | | writer.Flush(); |
| | | writer.Close(); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | #endregion |
| | | } |
| | | } |