/// <summary> /// 执行更新 /// </summary> public void StartUpdate() { bool needRestart = false; StringBuilder sb = new StringBuilder(); foreach (var name in GlobalConfig.UpdateMustReartHmiNames) { if (MachineConfig.HmiName.Contains(name)) { needRestart = true; } sb.Append(name).Append(","); } if (!needRestart) { //关闭监视进程 YUtil.StopWinService(HmiConfig.DaemonServiceName); YUtil.KillProcess(HmiConfig.AsylumProcessName); AppUpdater.StartExternalUpdater(); } else { YUtil.RestartPC(); } }
/// <summary> /// 启动 Hmi Pro /// </summary> /// <param name="data"></param> /// <returns></returns> ExecRest startHmiPro(object data) { var start = (CmdActions.StartHmiPro)data; var rest = new ExecRest(); try { rest.DebugMessage = YUtil.CheckProcessIsExist(hmiProName) ? "HmiPro 进程存在" : "HmiPro 进程不存在"; //强制启动 if (start.IsForced) { YUtil.KillProcess(hmiProName); YUtil.Exec(hmiProPath, start.StartArgs); rest.Message = "强制启动 HmiPro 成功"; //只有当进程不存在的时候才启动 } else if (!YUtil.CheckProcessIsExist(hmiProName)) { YUtil.Exec(hmiProPath, start.StartArgs); rest.Message = "启动 HmiPro 成功"; } rest.Code = ExecCode.Ok; } catch (Exception e) { rest.Message = "启动 HmiPro 失败"; rest.Code = ExecCode.StartHmiProFailed; rest.DebugMessage = e.Message; } return(rest); }
/// <summary> /// 关闭程序 /// </summary> public new static void Shutdown() { Current.Dispatcher.Invoke(() => { ConsoleHelper.Hide(); try { YUtil.KillProcess(Process.GetCurrentProcess().ProcessName); } catch { // ignored } }); }
/// <summary> /// 重启软件 /// </summary> public static void Restart() { Current.Dispatcher.Invoke(() => { //利用脚本启动 var startupParam = string.Join(" ", CmdOptions.StartupEventArgs.Args); ConsoleHelper.Hide(); YUtil.Exec(AssetsHelper.GetAssets().BatStartApp, startupParam, ProcessWindowStyle.Hidden); try { YUtil.KillProcess(Process.GetCurrentProcess().ProcessName); } catch { // ignored } }); }
/// <summary> /// 关闭 HmiPro /// 目前仅支持强制关闭 /// </summary> /// <param name="data"></param> /// <returns></returns> ExecRest closeHmiPro(object data) { var close = (CmdActions.CloseHmiPro)data; var rest = new ExecRest(); try { YUtil.KillProcess(hmiProName); rest.Message = "关闭 HmiPro 成功"; rest.Code = ExecCode.Ok; } catch (Exception e) { rest.DebugMessage = e.Message; rest.Code = ExecCode.CloseHmiProFailed; } return(rest); }
/// <summary> /// HmiPro 软件保活 /// </summary> void keepHmiAlive() { Logger.Debug("HmiPro 保活"); if ((DateTime.Now - HmiLastActiveTime).TotalMinutes > 3) { HmiLastActiveTime = DateTime.Now; var isExist = YUtil.CheckProcessIsExist(GlobalConfig.HmiProcessName); Logger.Error("HmiPro 已经无响应了,进程是否存在:" + isExist + ",最后活动时间:" + HmiLastActiveTime); YUtil.KillProcess(GlobalConfig.HmiProcessName); string startupArgs = string.Empty; if (GlobalConfig.IsDevEnv) { startupArgs = @"--console false --autostart false --splash false --config office --hmi DE_DF --mock true"; } Logger.Debug("HmiPro.exe 路径:" + GlobalConfig.StartupArgs.HmiProPath + " " + startupArgs); YUtil.Exec(GlobalConfig.StartupArgs.HmiProPath, startupArgs); } }