public void Listen() { if (this.Value == null) { return; } this.pipeServer = new PipeServer(this.Value); this.pipeServer.Listen(); this.pipeServer.ReceivePipeData += async(b) => { //if (PipeUpgradeCommand.TryFromBytes(b, out PipeUpgradeCommand pipeCommand)) //{ // switch (pipeCommand.Command) // { // case PipeUpgradeCommand.Commands.Colse: // Application.Exit(); // break; // } // return; //} if (PipeUpgradeUI.TryFromBytes(b, out PipeUpgradeUI pipeUpgradeUI)) { if (pipeUpgradeUI.UIImage != null) { try { using (MemoryStream ms = new MemoryStream(pipeUpgradeUI.UIImage)) { UpgradeApplication.SetUIRenderer(new UpgradeUIRenderer() { BackgroundImage = Bitmap.FromStream(ms), BackgroundColor = System.Drawing.ColorTranslator.FromHtml(pipeUpgradeUI.ColorHex), Size = new Size(pipeUpgradeUI.Width, pipeUpgradeUI.Height), Company = pipeUpgradeUI.Company, Copyright = pipeUpgradeUI.Copyright, Version = pipeUpgradeUI.Version }); } } catch (Exception ex) { } } return; } if (PipeUpgradeCheckVersion.TryFromBytes(b, out PipeUpgradeCheckVersion pipeCheckVersion)) { JsonReleaseVersion jsonReleaseVersion = await Commands.CommandUrl.CheckVersion(pipeCheckVersion.Version); if (jsonReleaseVersion != null) { if (await Commands.CommandUrl.Upgrade(jsonReleaseVersion)) { UpgradeApplication.SetMessage("升级完成"); } else { UpgradeApplication.SetMessage("升级失败"); } } else { UpgradeApplication.SetMessage("无法获取升级信息"); } await Task.Delay(1000); if (await Commands.CommandMainRestart.MainStart()) { Application.Exit(); } else { UpgradeApplication.SetMessage("无法打开主程序"); await Task.Delay(1000); Application.Exit(); } } }; }