public void Stop() { _server.CloseAsync().Wait(); ProcessTool.Start("netsh", "http delete urlacl url=" + _baseAddress, IOHelper.SYS32_DIR); Logging.Info("Rest server is stopped"); }
/// <summary> /// 启动最新版本程序 /// </summary> /// <param name="route">路径:程序版本文件夹路径</param> /// <param name="exeFile">可执行文件名</param> /// <returns></returns> public static bool StartNewVersion(string route, string exeFile) { if (GetNewVersion(route, exeFile, out Version version, out string startFile)) { return(ProcessTool.Start(startFile)); } return(false); }
public async Task KillByPort_Successful() { this.process = ProcessTool.Start(ExePath); await Task.Delay(2000); ProcessTool.KillByPort(ExePort); await Task.Delay(1000); Assert.IsTrue(this.process.HasExited); }
public void Start() { //http://stackoverflow.com/questions/2521950/wcf-selfhosted-service-installer-class-and-netsh var everyone = new SecurityIdentifier("S-1-1-0").Translate(typeof(NTAccount)).ToString(); //Use Netsh.exe to give your account permissions to reserve the URL. //https://www.asp.net/web-api/overview/older-versions/self-host-a-web-api ProcessTool.Start("netsh", "http add urlacl url=" + _baseAddress + " user="******"Rest server is tarted.Listening by " + _baseAddress); }
/// <summary> /// 启动最新版本程序 /// </summary> /// <param name="route">路径:程序版本文件夹路径</param> /// <param name="startfilename">可执行文件名</param> /// <returns></returns> public static bool StartNewVersion(string route, string startfilename) { //判断路径是文件还是文件夹,并统一处理为文件夹 string appPath = route; if (FileTool.IsFile(route)) { appPath = DirTool.GetFilePath(route); } if (Directory.Exists(appPath)) { //获取运行目录下所有文件 List <string> paths = DirTool.GetPath(appPath); if (ListTool.HasElements(paths)) { //解析属于版本号的文件 Version version = null; string startfile = null; foreach (var path in paths) { //只解析文件名带三个点的文件夹 string filename = Path.GetFileName(path); if (StringTool.SubStringCount(filename, ".") == 3) { try { Version tempVersion = new Version(filename); string tempFile = DirTool.Combine(path, startfilename); if ((version == null || tempVersion > version) && File.Exists(tempFile)) { version = tempVersion; startfile = tempFile; } } catch { } } } //准备启动 if (startfile != null) { return(ProcessTool.Start(startfile)); } } } return(false); }
/// <summary> /// 更新结束启动程序 /// </summary> void EndRunProcess() { int percent = 1; if (!ListTool.IsNullOrEmpty(version.EndRunProcess)) { foreach (var p in version.EndRunProcess) { Thread.Sleep(R.cst.WAIT_TIME); UIPbStatus((int)((double)(percent++) / version.EndRunProcess.Count() * 100)); if (!string.IsNullOrWhiteSpace(p)) { ProcessTool.Start(Path.Combine(R.AppPath, p)); } } } }
public void Start_Successful() { this.process = ProcessTool.Start(ExePath); Assert.IsFalse(this.process.HasExited); this.process.Kill(); }
/// <summary> /// 接受消息 /// </summary> /// <param name="host"></param> /// <param name="model"></param> public static void ReceiveMessage(string host, TcpDataModel model) { switch (model.Type) { case 10001000: R.Tx.IsAuth = true; R.Tx.ConnectTime = DateTime.Now; R.MainUI.UITxStatus(); TxSendQueue.Start(); break; //状态信息 case 20001000: /* 普通应答 */ break; case 20001001: /* 状态 */ //R.MainUI.UIStatus(model); break; case 20001002: /* 状态(二维码) */ break; case 20002000: //R.MainUI.UILog(Json.Byte2Object<string>(model.Data)); break; case 20003000: //R.MainUI.UIScreen(model); break; case 20004000: /* 系统信息 */ //R.MainUI.UIInfo(model); break; case 20004001: /* 软件信息 */ //R.MainUI.UIInfo(model); break; case 20004002: /* 硬件信息 */ //R.MainUI.UIInfo(model); break; case 20004003: /* 共享信息 */ //R.MainUI.UIInfo(model); break; case 20004004: /* APP信息 */ //R.MainUI.UIInfo(model); break; case 30001000: //R.MainUI.UIConsole(Json.Byte2Object<List<string>>(model.Data)); break; //指令操作 case 40001000: /* 清除过期日志 */ R.Log.I("收到指令操作:40001000:清除过期日志:15天之前日志"); LogCleaner.CleanLogFile(); break; case 40002000: /* 重启服务 */ try { R.Log.I("收到指令操作:40002000:重启服务"); string ss = Json.Byte2Object <string>(model.Data); Tuple <string, int> info = Json.String2Object <Tuple <string, int> >(ss); if (R.Tx.LocalIP == info.Item1 && R.ProjectItems.Any(x => x.Port == info.Item2)) { Parts.ProjectItemPart item = R.ProjectItems.FirstOrDefault(x => x.Port == info.Item2); if (item != null) { item.Restart(); } } } catch { } break; //更新操作 case 90001000: /* 获取更新文件基本信息 */ try { Tuple <string, string> data = Json.Byte2Object <Tuple <string, string> >(model.Data); if (Str.Ok(data.Item1, data.Item2)) { R.AppointName = data.Item1; R.AppointMD5 = data.Item2; TxSendQueue.Add(90001000, "Fire in the hole"); } } catch { } break; case 90002000: /* 获取更新文件 */ try { if (Str.Ok(R.AppointName, R.AppointMD5)) { if (File.Exists(DirTool.Combine(R.Paths.App, R.AppointName))) { FileTool.Delete(DirTool.Combine(R.Paths.App, R.AppointName)); } if (BinaryFileTool.write(DirTool.Combine(R.Paths.App, R.AppointName), model.Data)) { IniTool.Set(R.Files.Settings, "Appoint", "Name", R.AppointName); IniTool.Set(R.Files.Settings, "Appoint", "MD5", R.AppointMD5); // 判断文件存在,并且MD5相符,则退出并运行新版本(否则删除不一致文件) if (File.Exists(DirTool.Combine(R.Paths.App, R.AppointName)) && FileTool.GetMD5(DirTool.Combine(R.Paths.App, R.AppointName)) == R.AppointMD5) { ProcessTool.Start(R.Files.App); R.MainUI.UIExitApp(); } else { FileTool.Delete(DirTool.Combine(R.Paths.App, R.AppointName)); } } } } catch { } break; default: break; } }
public static bool Start(string file) { return(ProcessTool.Start(file)); }
static void Main() { //taskkill /IM BigBirdDeployer-1.exe /F //启动自动运行指定最新版本 string appoint_name = IniTool.GetString(R.Files.Settings, "Appoint", "Name", ""); string appoint_md5 = IniTool.GetString(R.Files.Settings, "Appoint", "MD5", ""); string current_file = Path.GetFileName(R.Files.App); if (Str.Ok(appoint_name, appoint_md5)) { string file = DirTool.Combine(R.Paths.App, appoint_name); if (File.Exists(file) && FileTool.GetMD5(file) == appoint_md5) { R.Log.V($"appoint:{appoint_name} current:{current_file}"); R.Log.V($"appoint:{file} current:{R.Files.App}"); if (appoint_name != current_file) { if (ProcessTool.Start(file)) { return; } } } } //var a = FileTool.GetAllFile(@"F:\Temp\logs", new[] { "*.log"}); //解决进程互斥 if (!AppUnique.IsUnique(R.AppName)) { return; } try { //处理未捕获的异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); R.Log.i("========== 程序启动:BigBirdDeployer(正常启动) =========="); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); R.MainUI = new MainForm(); InitIni(); //初始化Ini配置信息 StatusLog.Instance.Start(); //启动计算机状态日志记录 R.Log.SetCacheDays(10); //保存最近10天的普通日志信息 StatusLog.Instance.SetCacheDays(10); //保存最近10天的状态日志信息 SystemSleepAPI.PreventSleep(false); //禁用计算机息屏和待机 PlanTaskCore.Start(); //启动定时任务 Application.Run(R.MainUI); //启动主UI } catch (Exception ex) { R.Log.e("应用程序异常 App Main Exception"); WriteExceptionAndRestart(ex); } }