| | |
| | | using System.Threading.Tasks; |
| | | using static Bro.Common.Helper.EnumHelper; |
| | | |
| | | namespace Bro.Process |
| | | namespace Bro.Process |
| | | { |
| | | [Process("", DeviceAttributeType.Device)] |
| | | public partial class ProcessControl : IProcess |
| | |
| | | #region AutoFac注册 |
| | | GlobalVar.Builder.RegisterInstance(this).As<IProcess>().ExternallyOwned(); |
| | | GlobalVar.Builder.RegisterInstance(IConfig).As<IProcessConfig>().ExternallyOwned(); |
| | | GlobalVar.Builder.RegisterInstance(DeviceCollection).ExternallyOwned(); |
| | | GlobalVar.Builder.RegisterInstance(ProcessMethodCollection).ExternallyOwned(); |
| | | GlobalVar.Builder.RegisterInstance(DeviceCollection); |
| | | GlobalVar.Builder.RegisterInstance(ProcessMethodCollection); |
| | | |
| | | //if (isBuild) |
| | | //{ |
| | |
| | | { |
| | | if (config == null) |
| | | throw new ProcessException("保存的配置信息不能为空"); |
| | | ProductionCode = newProductionCode; |
| | | |
| | | string newConfigPath = Path.Combine(Path.GetDirectoryName(_configPath), $"Config_{newProductionCode}.json"); |
| | | if (File.Exists(newConfigPath)) |
| | | { |
| | | throw new ProcessException($"{newProductionCode}配置文件已经存在"); |
| | | } |
| | | |
| | | //生成config.json |
| | | string newConfig = JsonConvert.SerializeObject(config, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); |
| | | using (StreamWriter writer = new StreamWriter(_configPath, false, System.Text.Encoding.UTF8)) |
| | | using (StreamWriter writer = new StreamWriter(newConfigPath, false, System.Text.Encoding.UTF8)) |
| | | { |
| | | writer.Write(newConfig); |
| | | writer.Flush(); |
| | |
| | | } |
| | | |
| | | //添加到Setting.json |
| | | SettingHelper.AddNewProductionCode(ProductionCode); |
| | | SettingHelper.AddNewProductionCode(newProductionCode); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | if (!ProcessInvokePreCheck()) |
| | | return; |
| | | |
| | | IOperationConfig config = monitorSet.OpConfig; |
| | | object res = null; |
| | | int reTryTimes = config.ReTryTimes; |
| | | IDevice device = DeviceCollection.FirstOrDefault(u => u.Id == deviceId); |
| | | LogAsync(DateTime.Now, $"{device.Name}调用{methodCode}开始", ""); |
| | | LogAsync(DateTime.Now, $"{device?.Name}调用{methodCode}开始", ""); |
| | | |
| | | Stopwatch sw = new Stopwatch(); |
| | | sw.Start(); |
| | |
| | | } |
| | | |
| | | LogAsync(DateTime.Now, methodCode + "异常信息", ex.GetExceptionMessage()); |
| | | |
| | | ExceptionRaisedInMonitor(ex); |
| | | } |
| | | } |
| | | |
| | |
| | | #endregion |
| | | |
| | | sw.Stop(); |
| | | LogAsync(DateTime.Now, $"{device.Name}调用{methodCode}完成,耗时{sw.ElapsedMilliseconds}ms", ""); |
| | | TimeRecordCSV(DateTime.Now, device.Name, $"{methodCode}调用完成", (int)sw.ElapsedMilliseconds); |
| | | LogAsync(DateTime.Now, $"{device?.Name}调用{methodCode}完成,耗时{sw.ElapsedMilliseconds}ms", ""); |
| | | TimeRecordCSV(DateTime.Now, device?.Name, $"{methodCode}调用完成", (int)sw.ElapsedMilliseconds); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 流程执行的预检查 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual bool ProcessInvokePreCheck() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 监听流程中异常抛出 在具体业务中具体处理 |
| | | /// </summary> |
| | | /// <param name="ex">监听流程中异常对象</param> |
| | | public virtual void ExceptionRaisedInMonitor(Exception ex) |
| | | { |
| | | } |
| | | #endregion |
| | | |
| | | #region 图像处理 |
| | | protected HImage CollectHImage(CameraBase camera, IOperationConfig opConfig, out string imgSetId, [CallerMemberName]string methodCode = "") |
| | | protected IImageSet CollectHImage(CameraBase camera, IOperationConfig opConfig, [CallerMemberName]string methodCode = "") |
| | | { |
| | | IImageSet set = null; |
| | | |
| | |
| | | TimeRecordCSV(DateTime.Now, camera.Name, methodCode + "采图", (int)sw.ElapsedMilliseconds); |
| | | } |
| | | |
| | | imgSetId = set?.Id; |
| | | return set.HImage; |
| | | return set; |
| | | } |
| | | |
| | | protected async void CameraUpdateImage(CameraBase camera, Bitmap image, string setId) |
| | |
| | | |
| | | OnAlarmUpdate?.BeginInvoke(alarmMsg, null, null); |
| | | } |
| | | |
| | | public virtual void RaisedAlarm(string alarmMsg) |
| | | { |
| | | OnAlarmUpdate?.Invoke(alarmMsg); |
| | | } |
| | | #endregion |
| | | |
| | | #region ILogger |