/// <summary> /// 呼叫维修完成 /// </summary> /// <param name="selectCall"></param> /// <returns></returns> async Task execCallRepairComplete(MqCall selectCall) { var call = new Redux.Models.MqCall() { machineCode = selectCall.MachineCode, callType = Redux.Models.MqCallType.RepairComplete, CallId = Guid.NewGuid().GetHashCode(), }; App.Logger.Info("维修完成: " + JsonConvert.SerializeObject(call)); var callSuccess = await App.Store.Dispatch(UnityIocService.ResolveDepend <MqEffects>().CallSystem(new MqActions.CallSystem(selectCall.MachineCode, call))); if (callSuccess) { App.Store.Dispatch(new SysActions.ShowNotification(new SysNotificationMsg() { Title = "通知", Content = $"{selectCall.MachineCode} 维修完成" })); } else { App.Store.Dispatch(new SysActions.ShowNotification(new SysNotificationMsg() { Title = "警告", Content = $"{selectCall.MachineCode} 维修完成状态上传失败,请重试" })); } }
/// <summary> /// /// </summary> /// <param name="mqEffects"></param> /// <param name="dbEffects"></param> public AlarmCore(MqEffects mqEffects, DbEffects dbEffects) { UnityIocService.AssertIsFirstInject(GetType()); this.mqEffects = mqEffects; this.dbEffects = dbEffects; actionExecutors[AlarmActions.GENERATE_ONE_ALARM] = doGenerateOneAlarm; }
/// <summary> /// /// </summary> /// <param name="sysEffects"></param> /// <param name="mqEffects"></param> public SchCore(SysEffects sysEffects, MqEffects mqEffects) { UnityIocService.AssertIsFirstInject(GetType()); this.sysEffects = sysEffects; this.mqEffects = mqEffects; Logger = LoggerHelper.CreateLogger(GetType().ToString()); }
/// <summary> /// 扫描物料模拟 /// </summary> /// <param name="machineCode"></param> public static void DispatchMqMockScanMaterial(string machineCode) { var data = MqMocks.CreateScanMaterial(); var mqService = UnityIocService.ResolveDepend <MqService>(); mqService.ScanMaterialAccept(machineCode, JsonConvert.SerializeObject(data)); Console.WriteLine("测试扫描物料完毕"); }
public DbEffects() { UnityIocService.AssertIsFirstInject(GetType()); MongoService = MongoHelper.GetMongoService(); initUploadCpmsInfluxDb(); initUploadDocMongo(); initUploadDocManyMongo(); Logger = LoggerHelper.CreateLogger(GetType().ToString()); }
/// <summary> /// 扫描线盘卡模拟 /// </summary> /// <param name="machineCode"></param> public static void DispatchMockMqAxisRfid(string machineCode) { var message = " {'axis_id':'P71211000061','date':'1514200349659','msg_type':'axis_end','machine_id':'M71207220621','rfids':'P71211000061','newDate':1514200462069,'msgType':'收线','macCode':'ED','name':'王者归来'}"; var mqRfid = JsonConvert.DeserializeObject <MqAxisRfid>(message); mqRfid.macCode = machineCode; UnityIocService.ResolveDepend <MqService>().AxisRfidAccpet(JsonConvert.SerializeObject(mqRfid)); Console.WriteLine("发送测试扫卡Mq数据成功"); }
/// <summary> /// 注入配置信息 /// </summary> /// <param name="hmiProName"></param> /// <param name="hmiProPath"></param> public CmdParseService(string hmiProName, string hmiProPath) { UnityIocService.AssertIsFirstInject(GetType()); this.hmiProName = hmiProName; this.hmiProPath = hmiProPath; Logger = LoggerHelper.Create(GetType().ToString()); executors = new Dictionary <Type, Func <object, ExecRest> >(); executors[typeof(CmdActions.StartHmiPro)] = startHmiPro; executors[typeof(CmdActions.CloseHmiPro)] = closeHmiPro; }
/// <summary> /// 人员打卡模拟 /// </summary> /// <param name="machineCode"></param> /// <param name="type"></param> public static void DispatchMockMqEmpRfid(string machineCode, string type = "上机") { var message = "{'id':400,'employeeCode':'S71220173321','type':'" + type + "','upTime':'Dec 25, 2017 5:15:16 PM','macCode':'DA','name':'李明'}"; var mqRfid = JsonConvert.DeserializeObject <MqEmpRfid>(message); mqRfid.macCode = machineCode; var mqService = UnityIocService.ResolveDepend <MqService>(); mqService.EmpRfidAccept(JsonConvert.SerializeObject(mqRfid)); Console.WriteLine("发送测试人员打卡数据成功成功"); }
/// <summary> /// 初始化上面的 Effect /// </summary> /// <param name="sysService"></param> public SysEffects(SysService sysService) { UnityIocService.AssertIsFirstInject(GetType()); Logger = LoggerHelper.CreateLogger(GetType().ToString()); //启动http解析服务 StartHttpSystem = App.Store.asyncAction <SysActions.StartHttpSystem, bool>( async(dispatch, getState, instance) => { dispatch(instance); var isStarted = await sysService.StartHttpSystem(instance); if (isStarted) { App.Store.Dispatch(new SysActions.StartHttpSystemSuccess()); } else { App.Store.Dispatch(new SysActions.StartHttpSystemFailed()); } return(isStarted); }); //启动关闭显示器定时器 StartCloseScreenTimer = App.Store.asyncActionVoid <SysActions.StartCloseScreenTimer>( async(dispatch, getState, instance) => { dispatch(instance); await Task.Run(() => { if (CloseScrrenTimer != null) { YUtil.RecoveryTimeout(CloseScrrenTimer); } else { CloseScrrenTimer = YUtil.SetInterval(instance.Interval, () => { App.Store.Dispatch(new SysActions.CloseScreen()); }); } }); }); //停止关闭显示器定时器 StopCloseScrenTimer = App.Store.asyncActionVoid <SysActions.StopCloseScreenTimer>( async(dispatch, getState, instance) => { dispatch(instance); await Task.Run(() => { if (CloseScrrenTimer != null) { YUtil.ClearTimeout(CloseScrrenTimer); } }); }); }
/// <summary> /// 初始化 /// </summary> static async Task <bool> Init() { var cmdParse = new CmdParseService("HmiPro", GlobalConfig.StartupArgs.HmiProPath); UnityIocService.RegisterGlobalDepend(cmdParse); UnityIocService.RegisterGlobalDepend <HttpParse>(); UnityIocService.RegisterGlobalDepend <AsylumService>(); UnityIocService.ResolveDepend <AsylumService>().Init(); if (!await UnityIocService.ResolveDepend <HttpParse>().Start("http://+:9988/")) { Logger.Error("Http 服务启动失败"); return(false); } var pipeService = new PipeService("Asylum"); UnityIocService.RegisterGlobalDepend(pipeService); return(pipeService.Start()); }
/// <summary> /// 初始化各个 Effect /// </summary> /// <param name="mqService"></param> public MqEffects(MqService mqService) { UnityIocService.AssertIsFirstInject(GetType()); activeMq = ActiveMqHelper.GetActiveMqService(); Logger = LoggerHelper.CreateLogger(GetType().ToString()); this.mqService = mqService; initSchTaskEffect(); initUploadCpmsEffect(); initStartUploadCpmsIntervalEffect(); initStartListenScanMaterial(); initUploadAlarm(); initUploadSchTaskManu(); initStartListenEmpRfid(); initStartListenAxisRfid(); initUploadDpms(); initCallSystem(); initStartListenCmd(); initUploadElecPower(); }
public void CheckUpdate() { var sysService = UnityIocService.ResolveDepend <SysService>(); Task.Run(() => { if (sysService.CheckUpdate()) { sysService.StartUpdate(); } else { App.Store.Dispatch( new SysActions.ShowNotification(new SysNotificationMsg() { Title = "未检查到更新", Content = "本软件版本目前已是最新版" })); } }); }
public void OnLoaded() { if (AppState.IsCompleteInited) { return; } //更新启动日志 App.StartupLog.IsStartSuccess = true; App.StartupLog.StartDurationMs = (long)(DateTime.Now - App.StartupLog.StartTime).TotalMilliseconds; SqliteHelper.DoAsync(ctx => { ctx.StartupLogs.Add(App.StartupLog); ctx.SaveChanges(); }); var dbEffects = UnityIocService.ResolveDepend <DbEffects>(); App.Store.Dispatch(dbEffects.UploadDocToMongo(new DbActions.UploadDocToMongo(MongoHelper.LogsDb, MongoHelper.StartupLogsCollection, App.StartupLog))); App.Store.Dispatch(new SysActions.CloseLoadingSplash()); App.Store.Dispatch(new SysActions.ChangeWindowBackgroundImage(AssetsHelper.GetAssets().ImageBackground)); //置位程序初始化完成 AppState.IsCompleteInited = true; }
/// <summary> /// 初始化继承一些父类的私有元素 /// </summary> private void init() { actionListenersDict = new ConcurrentDictionary <string, Action <T, IAction> >(); UnityIocService.AssertIsFirstInject(GetType()); if (baseStore == null) { baseStore = this.GetPrivateField <object>("store", GetType().BaseType); } if (rootReducer == null) { rootReducer = baseStore.GetPrivateField <Reducer <T> >("rootReducer"); } if (state == null) { state = baseStore.GetPrivateField <T>("state"); } if (middlewares == null) { middlewares = this.GetPrivateField <MiddlewareExecutor>("middlewares"); } }
/// <summary> /// 对程序进行配置 /// </summary> /// <param name="e"></param> protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); ReduxIoc.Init(); if (!YUtil.CheckProcessIsExist(HmiConfig.AsylumProcessName)) { string asylumnArgs = ""; if (HmiConfig.IsDevUserEnv) { asylumnArgs = "--autostart false --HmiPath " + YUtil.GetAbsolutePath(".\\HmiPro.exe"); } //YUtil.Exec(YUtil.GetAbsolutePath(@".\Asylum\Asylum.exe"), asylumnArgs); } Store = UnityIocService.ResolveDepend <StorePro <AppState> >(); //异步初始化,直接进入 DxWindow Task.Run(() => { hmiConfigInit(e); initSubscribe(); //通知 DxWindow 初始化完毕 Store.Dispatch(new SysActions.AppXamlInited(e)); }); }
/// <summary> /// 呼叫维修 /// </summary> /// <param name="selectCall"></param> void execCallRepair(MqCall selectCall) { var frm = new CallRepairForm() { OnOkPressed = async f => { var repairForm = f as CallRepairForm; var call = new Redux.Models.MqCall() { machineCode = selectCall.MachineCode, callType = Redux.Models.MqCallType.Repair, callAction = repairForm.RepairType.GetAttribute <DisplayAttribute>().Name, CallId = Guid.NewGuid().GetHashCode(), }; App.Logger.Info("呼叫维修: " + JsonConvert.SerializeObject(call)); var callSuccess = await App.Store.Dispatch(UnityIocService.ResolveDepend <MqEffects>().CallSystem(new MqActions.CallSystem(selectCall.MachineCode, call))); if (callSuccess) { App.Store.Dispatch(new SysActions.ShowNotification(new SysNotificationMsg() { Title = "通知", Content = $"{selectCall.MachineCode} 申报维修成功 {repairForm.RepairType.GetAttribute<DisplayAttribute>().Name }" })); } else { App.Store.Dispatch(new SysActions.ShowNotification(new SysNotificationMsg() { Title = "警告", Content = $"{selectCall.MachineCode} 申报维修失败 {repairForm.RepairType.GetAttribute<DisplayAttribute>().Name },请重试" })); } } }; App.Store.Dispatch(new SysActions.ShowFormView("选择故障类型", frm, false)); }
/// <summary> /// 派发模拟排产任务 /// </summary> public static void DispatchMockSchTask(string machineCode, int id = 0) { var mockEffects = UnityIocService.ResolveDepend <MockEffects>(); var task = YUtil.GetJsonObjectFromFile <MqSchTask>(AssetsHelper.GetAssets().MockMqSchTaskJson); task.workcode = YUtil.GetRandomString(8); task.id = id; task.taskId = id.ToString(); task.maccode = machineCode; foreach (var axis in task.axisParam) { axis.maccode = task.maccode; axis.axiscode = YUtil.GetRandomString(10); axis.taskId = task.taskId; } JavaTime startTime = new JavaTime() { time = YUtil.GetUtcTimestampMs(YUtil.GetRandomTime(DateTime.Now.AddDays(-1), DateTime.Now)) }; task.pstime = startTime; task.pdtime = startTime; App.Store.Dispatch(mockEffects.MockSchTaskAccept(new MockActions.MockSchTaskAccpet(task))); }
public static void Init() { UnityIocService.AssertIsFirstInject(typeof(ReduxIoc)); //== 注入 redux 相关数据 var reducer = new CompositeReducer <AppState>() .Part(s => s.CpmState, CpmReducer.Create()) .Part(s => s.SysState, SysReducer.Create()) .Part(s => s.MqState, MqReducer.Create()) .Part(s => s.AlarmState, AlarmReducer.Create()) .Part(s => s.OeeState, OeeReducer.Create()) .Part(s => s.DMesState, DMesReducer.Create()) .Part(s => s.ViewStoreState, ViewStoreReducer.Create()) .Part(s => s.DpmStore, DpmReducer.Create()); var storePro = new StorePro <AppState>(reducer); //== 设置依赖注入 UnityIocService.RegisterGlobalDepend(storePro); UnityIocService.RegisterGlobalDepend <CpmCore>(); UnityIocService.RegisterGlobalDepend <CpmEffects>(); UnityIocService.RegisterGlobalDepend <SysService>(); UnityIocService.RegisterGlobalDepend <SysEffects>(); UnityIocService.RegisterGlobalDepend <MqService>(); UnityIocService.RegisterGlobalDepend <MqEffects>(); UnityIocService.RegisterGlobalDepend <MockEffects>(); UnityIocService.RegisterGlobalDepend <DbEffects>(); UnityIocService.RegisterGlobalDepend <DMesCore>(); UnityIocService.RegisterGlobalDepend <SchCore>(); UnityIocService.RegisterGlobalDepend <OeeCore>(); UnityIocService.RegisterGlobalDepend <AlarmCore>(); UnityIocService.RegisterGlobalDepend <ViewStoreCore>(); UnityIocService.RegisterGlobalDepend <DpmCore>(); UnityIocService.RegisterGlobalDepend <PipeEffects>(); UnityIocService.RegisterGlobalDepend <LoadEffects>(); UnityIocService.RegisterGlobalDepend <HookCore>(); }
/// <summary> /// 初始化 日志、事件处理器 /// </summary> public OeeCore() { UnityIocService.AssertIsFirstInject(GetType()); Logger = LoggerHelper.CreateLogger(GetType().ToString()); actionExecutors[CpmActions.OEE_SPEED_ACCEPT] = whenOeeSpeedAccept; }
/// <summary> /// 防止多次注入 /// </summary> public AsylumService() { UnityIocService.AssertIsFirstInject(GetType()); }
public ViewStoreCore() { UnityIocService.AssertIsFirstInject(GetType()); }
public PipeEffects() { UnityIocService.AssertIsFirstInject(GetType()); Logger = LoggerHelper.CreateLogger(GetType().ToString()); initWriteStringAsync(); }
/// <summary> /// 只能注入一次 /// </summary> public HookCore() { UnityIocService.AssertIsFirstInject(GetType()); }
/// <summary> /// 配置文件加载成功之后执行的一些初始化 /// </summary> async void afterConfigLoaded() { //== 初始化部分State updateLoadingMessage("正在初始化系统核心...", 0.5); App.Store.Dispatch(new ViewStoreActions.Init()); App.Store.Dispatch(new CpmActions.Init()); App.Store.Dispatch(new AlarmActions.Init()); App.Store.Dispatch(new OeeActions.Init()); App.Store.Dispatch(new DMesActions.Init()); App.Store.Dispatch(new DpmActions.Init()); var sysEffects = UnityIocService.ResolveDepend <SysEffects>(); var cpmEffects = UnityIocService.ResolveDepend <CpmEffects>(); var mqEffects = UnityIocService.ResolveDepend <MqEffects>(); updateLoadingMessage("正在连接服务器...", 0.55); var task = Task.Run(() => { mqEffects.Start(); }); //更新连接服务器的进度 double p = 0.55; bool isMqEffectsStarted = false; Timer updateTimer = null; updateTimer = YUtil.SetInterval(500, () => { if (!isMqEffectsStarted) { p += 0.01; updateLoadingMessage("正在连接服务器...", p, 0); Logger.Debug("正在连接服务器..." + p.ToString("P1")); } if (isMqEffectsStarted || p > 0.64) { YUtil.ClearTimeout(updateTimer); } }); isMqEffectsStarted = Task.WaitAll(new[] { task }, 10000); YUtil.ClearTimeout(updateTimer); if (!isMqEffectsStarted) { updateLoadingMessage("连接 Mq 超时...", 0.6); App.Store.Dispatch(new SysActions.AddMarqueeMessage(SysActions.MARQUEE_CONECT_MQ_TIMEOUT, "Mq 连接超时")); restartAppAfterSec(10, 0.6, "连接 Mq 超时"); return; } updateLoadingMessage("正在注册程序...", 0.65); if (!await YUtil.CheckHttpFileExist(HmiConfig.StaticServerUrl + "/verify.txt")) { updateLoadingMessage("程序启动失败,请联系管理员", 0.66); restartAppAfterSec(10, 0.66, "程序启动失败,请联系管理员"); return; } UnityIocService.ResolveDepend <DMesCore>().Init(); UnityIocService.ResolveDepend <AlarmCore>().Init(); UnityIocService.ResolveDepend <CpmCore>().Init(); UnityIocService.ResolveDepend <OeeCore>().Init(); UnityIocService.ResolveDepend <DpmCore>().Init(); UnityIocService.ResolveDepend <HookCore>().Init(); //Http 命令解析 updateLoadingMessage("正在启动Http服务...", 0.7); var starHttpSystem = App.Store.Dispatch(sysEffects.StartHttpSystem(new SysActions.StartHttpSystem($"http://+:{HmiConfig.CmdHttpPort}/"))); //参数采集服务 updateLoadingMessage("正在启动参数采集服务...", 0.75); var startCpmServer = App.Store.Dispatch(cpmEffects.StartServer(new CpmActions.StartServer(HmiConfig.CpmTcpIp, HmiConfig.CpmTcpPort))); //监听排产和来料 updateLoadingMessage("正在启动监听排产服务...", 0.8); Dictionary <string, Task <bool> > startListenMqDict = new Dictionary <string, Task <bool> >(); foreach (var pair in MachineConfig.MachineDict) { //监听排产任务 var stQueueName = @"QUEUE_" + pair.Key; var stTask = App.Store.Dispatch(mqEffects.StartListenSchTask(new MqActions.StartListenSchTask(pair.Key, stQueueName))); startListenMqDict[stQueueName] = stTask; //监听来料 var smQueueName = $@"JUDGE_MATER_{pair.Key}"; var smTask = App.Store.Dispatch(mqEffects.StartListenScanMaterial(new MqActions.StartListenScanMaterial(pair.Key, smQueueName))); startListenMqDict[smQueueName] = smTask; } //监听人员打卡 updateLoadingMessage("正在启动监听人员打卡...", 0.85); var empRfidTask = App.Store.Dispatch(mqEffects.StartListenEmpRfid(new MqActions.StartListenEmpRfid(MachineConfig.HmiName + "_employee", HmiConfig.TopicEmpRfid))); startListenMqDict["rfidEmpTask"] = empRfidTask; //监听轴号卡 updateLoadingMessage("正在启动监听盘卡扫描...", 0.90); var axisRfidTask = App.Store.Dispatch(mqEffects.StartListenAxisRfid(new MqActions.StartListenAxisRfid(MachineConfig.HmiName + "_axis", HmiConfig.TopicListenHandSet))); startListenMqDict["rfidAxisTask"] = axisRfidTask; //监听机台命令 updateLoadingMessage("正在启动监听机台命令...", 0.92); var cmdTask = App.Store.Dispatch(mqEffects.StartListenCmd(new MqActions.StartListenCmd(MachineConfig.HmiName + "_cmd", HmiConfig.TopicCmdReceived))); startListenMqDict["cmdTask"] = cmdTask; updateLoadingMessage("正在启动系统核心服务...", 0.95); var tasks = new List <Task <bool> >() { starHttpSystem, startCpmServer }; tasks.AddRange(startListenMqDict.Values); //检查各项任务启动情况 await Task.Run(() => { //等等所有任务完成 var isStartedOk = Task.WaitAll(tasks.ToArray(), 30000); if (!isStartedOk) { var message = "系统核心启动超时,请检查网络连接"; updateLoadingMessage(message, 0.95); restartAppAfterSec(10, 0.95, "系统核心启动超时"); return; } //是否启动完成Cpm服务 var isCpmServer = startCpmServer.Result; if (!isCpmServer) { var message = "参数采集核心启动失败"; updateLoadingMessage(message, 0.95, 0); restartAppAfterSec(10, 0.95, message); return; } //是否启动完成Http解析系统 var isHttpSystem = starHttpSystem.Result; if (!isHttpSystem) { var message = "Http 核心启动失败"; updateLoadingMessage(message, 0.95, 0); restartAppAfterSec(10, 0.95, message); return; } //是否完成监听Mq foreach (var pair in startListenMqDict) { var isStartListenMq = pair.Value.Result; var mqKey = pair.Key.ToUpper(); if (!isStartListenMq) { string failedMessage = string.Empty; if (mqKey.Contains("QUEUE")) { failedMessage = $"监听Mq 排产队列 {pair.Key} 失败"; } else if (mqKey.Contains("JUDGE_MATER")) { failedMessage = $"监听Mq 扫描来料队列 {pair.Key} 失败"; } else if (mqKey.Contains("RFIDEMP")) { failedMessage = $"监听mq 人员打卡 数据失败"; } else if (mqKey.Contains("RFIDAXIS")) { failedMessage = $"监听Mq 线盘卡失败"; } else if (mqKey.Contains("CMD")) { failedMessage = $"监听Mq 机台命令失败"; } if (!string.IsNullOrEmpty(failedMessage)) { updateLoadingMessage(failedMessage, 0.95, 0); restartAppAfterSec(10, 0.95, failedMessage); return; } } } if (HmiConfig.IsDevUserEnv) { updateLoadingMessage("系统核心启动完毕,正在渲染界面...", 1, 0); App.Store.Dispatch(new SysActions.AppInitCompleted()); return; } var percent = 0.95; YUtil.SetInterval(300, t => { percent += 0.01; updateLoadingMessage("系统核心启动完毕,正在渲染界面...", percent, 0); if (t == 5 || percent >= 1) { App.Store.Dispatch(new SysActions.AppInitCompleted()); } }, 5); }); //update: 2018-3-28 // 将调度器最后启用,这些调度器需要依赖比较多,但本身不提供依赖 updateLoadingMessage("正在启动调度器...", 0.98); await UnityIocService.ResolveDepend <SchCore>().Init(); }
/// <summary> /// 初始化命令解析器、日志 /// </summary> public SysService() { UnityIocService.AssertIsFirstInject(GetType()); Logger = LoggerHelper.CreateLogger(GetType().ToString()); initCmdExecers(); }
/// <summary> /// /// </summary> /// <param name="mqEffects"></param> public DpmCore(MqEffects mqEffects) { UnityIocService.AssertIsFirstInject(GetType()); this.mqEffects = mqEffects; }
public MqService() { UnityIocService.AssertIsFirstInject(GetType()); Logger = LoggerHelper.CreateLogger(GetType().ToString()); }
/// <summary> /// 代理注入 /// </summary> /// <param name="cmdParse"></param> public HttpParse(CmdParseService cmdParse) { UnityIocService.AssertIsFirstInject(GetType()); this.cmdPrase = cmdParse; Logger = LoggerHelper.Create(GetType().ToString()); }