コード例 #1
0
 static UpgradeOperation()
 {
     pipeClient = new PipeClient(pipe);
     pipeClient.ReceivePipeData += (b) =>
     {
         if (PipeUpgradeCheckVersion.TryFromBytes(b, out PipeUpgradeCheckVersion pipeCheckVersion))
         {
             return;
         }
         if (PipeUpgradeCommand.TryFromBytes(b, out PipeUpgradeCommand pipeCommand))
         {
             return;
         }
         if (PipeUpgradeComplete.TryFromBytes(b, out PipeUpgradeComplete pipeUpgradeComplete))
         {
             Console.WriteLine("Success:" + pipeUpgradeComplete.Success);
             return;
         }
         if (PipeUpgradeContent.TryFromBytes(b, out PipeUpgradeContent pipeUpgradeContent))
         {
             Console.WriteLine("Content:" + pipeUpgradeContent.Content);
             return;
         }
         if (PipeUpgradeError.TryFromBytes(b, out PipeUpgradeError pipeUpgradeError))
         {
             Console.WriteLine("Error:" + pipeUpgradeError.Error);
             return;
         }
         if (PipeUpgradeMessage.TryFromBytes(b, out PipeUpgradeMessage pipeUpgradeMessage))
         {
             Console.WriteLine("Msg:" + pipeUpgradeMessage.Message);
             return;
         }
         if (PipeUpgradeProgress.TryFromBytes(b, out PipeUpgradeProgress pipeUpgradeProgress))
         {
             Console.WriteLine("R:" + pipeUpgradeProgress.Read + "|L:" + pipeUpgradeProgress.Loaded + "|T:" + pipeUpgradeProgress.Total);
             return;
         }
         //if (PipeUpgradeProgress.TryFromBytes(b, out PipeUpgradeProgress pipeUpgradeProgress))
         //{
         //    Console.WriteLine("R:" + pipeUpgradeProgress.Read + "|L:" + pipeUpgradeProgress.Loaded + "|T:" + pipeUpgradeProgress.Total);
         //}
     };
 }
コード例 #2
0
ファイル: CommandPipe.cs プロジェクト: radtek/UpgradeService
        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();
                    }
                }
            };
        }