예제 #1
0
        async void updatePhoto()
        {
            foreach (var employee in this.Employees)
            {
                var url     = $"{HmiConfig.StaticServerUrl}/images/{employee.Name}.png";
                var isExist = await YUtil.CheckHttpFileExist(url);

                Application.Current.Dispatcher.Invoke(() => {
                    if (isExist)
                    {
                        employee.Photo = url;
                    }
                    else
                    {
                        employee.Photo = null;
                    }
                });
            }
        }
예제 #2
0
        /// <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();
        }