public async Task <bool> Upgrade(JsonReleaseVersion jsonReleaseVersion)
 {
     if (await this.CreateVersion(jsonReleaseVersion))
     {
         this.clientUpload.UploadFileNameAppendBefore = jsonReleaseVersion.Version;
         this.currentProgress = 0;
         this.totalProgress   = jsonReleaseVersion.Files.Sum(f => f.Length);
         bool success = true;
         foreach (JsonFileDetail jsonFileDetail in jsonReleaseVersion.Files)
         {
             string path = Path.Combine(this.root, jsonFileDetail.Name);
             if (!(success &= await this.clientUpload.UploadTaskAsync(path)))
             {
                 break;
             }
         }
         this.clientUpload.UploadFileNameAppendBefore = null;
         this.OnUpgradeCompleted(new CompletedArgs(success));
         return(success);
     }
     else
     {
         this.OnUpgradeCompleted(new CompletedArgs(false));
         return(false);
     }
 }
        /// <summary> 新增版本
        /// </summary>
        /// <param name="version">版本号</param>
        public async Task <bool> CreateVersion(JsonReleaseVersion jsonReleaseVersion)
        {
            using (HttpClient client = new HttpClient(new HttpClientHandler()
            {
                UseCookies = false
            }))                                                                                       //若想手动设置Cookie则必须设置UseCookies = false
            {
                StringContent stringContent = new StringContent(JsonConvert.SerializeObject(jsonReleaseVersion));
                stringContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                try
                {
                    var result = await client.PostAsync(new Uri(this.url + "/createVersion"), stringContent);

                    if (result.IsSuccessStatusCode)
                    {
                        RespondResult respondResult = JsonConvert.DeserializeObject <RespondResult>(await result.Content.ReadAsStringAsync());
                        if (!respondResult.Result)
                        {
                            this.OnUpgradeError(new ErrorArgs(respondResult.Message));
                        }
                        return(respondResult.Result);
                    }
                }
                catch (Exception ex)
                {
                    this.OnUpgradeError(new ErrorArgs(ex.Message));
                    return(false);
                }
            }
            return(true);
        }
 public async Task <IActionResult> CreateVersion(JsonReleaseVersion jsonReleaseVersion)
 {
     return(await Task <IActionResult> .Run(() =>
     {
         return Json(upgradeServer.CreateVersion(jsonReleaseVersion));
     }));
 }
Exemple #4
0
        protected async override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            JsonReleaseVersion jsonReleaseVersion = await Commands.CommandUrl.CheckVersion("2.0.7089.20904");

            if (jsonReleaseVersion != null)
            {
                if (await Commands.CommandUrl.Upgrade(jsonReleaseVersion))
                {
                    MessageBox.Show("完成");
                }
            }
        }
        public RespondResult CreateVersion(JsonReleaseVersion jsonReleaseVersion)
        {
            JsonReleaseVersion[] jsonReleaseVersions = this.GetVersionList();
            if (jsonReleaseVersions.Length > 0)
            {
                jsonReleaseVersion += jsonReleaseVersions[jsonReleaseVersions.Length - 1];
            }
            string dir  = GetServerFilePath(jsonReleaseVersion.Version);
            string path = dir + ".json";

            try
            {
                if (!File.Exists(path))
                {
                    File.WriteAllText(path, JsonConvert.SerializeObject(jsonReleaseVersion));
                }
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                if (File.Exists(path) && Directory.Exists(dir))
                {
                    return(new RespondResult()
                    {
                        Message = "新增版本" + jsonReleaseVersion.Version
                    });
                }
                return(new RespondResult()
                {
                    Result = false, Message = "版本" + jsonReleaseVersion.Version + "新增失败"
                });
            }
            catch (Exception ex)
            {
                return(new RespondResult()
                {
                    Result = false, Message = ex.Message
                });
            }
        }
Exemple #6
0
        private async void BtnRelease_Click(object sender, EventArgs e)
        {
            this.btnRelease.Enabled = false;
            if (this.Check())
            {
                JsonReleaseVersion jsonReleaseVersion = new JsonReleaseVersion()
                {
                    Version = this.currentVersion.ToString(),
                    Files   = this.FileScans
                              .Where(f => f.Result == FileScan.CompareResult.Add || f.Result == FileScan.CompareResult.Update)
                              .Select(f => new JsonFileDetail()
                    {
                        Name = f.Name, MD5 = f.MD5, Length = f.Length, Version = this.currentVersion.ToString()
                    })
                              .ToArray(),
                    Deletes = this.FileScans
                              .Where(f => f.Result == FileScan.CompareResult.Remove)
                              .Select(f => f.Name)
                              .ToArray(),
                    Type          = this.ReleaseType,
                    UpdateContent = this.tbxUpdateContent.Text
                };
                if (await this.upgradeClient.Upgrade(jsonReleaseVersion))
                {
                    await this.RefreshVersions();

                    await this.RefreshfileScans();

                    MessageBox.Show("版本:" + jsonReleaseVersion.Version + "发布成功!");
                }
                else
                {
                    MessageBox.Show("发布失败!");
                }
            }
            this.btnRelease.Enabled = true;
        }
Exemple #7
0
        public async Task <bool> Upgrade(string root, JsonReleaseVersion jsonReleaseVersion)
        {
            this.currentProgress = 0;
            this.totalProgress   = jsonReleaseVersion.Files.Sum(f => f.Length);
            bool success = true;

            foreach (JsonFileDetail jsonFileDetail in jsonReleaseVersion.Files)
            {
                if (!(success &= await this.clientUpload.UploadTaskAsync(Path.Combine(root, jsonFileDetail.Name), Path.Combine(jsonReleaseVersion.Version, jsonFileDetail.Name.Replace(Path.GetFileName(jsonFileDetail.Name), "")).Replace(Path.DirectorySeparatorChar, '/'))))
                {
                    break;
                }
            }
            if (await this.CreateVersion(jsonReleaseVersion))
            {
                this.OnUpgradeCompleted(new CompletedArgs(success));
                return(success);
            }
            else
            {
                this.OnUpgradeCompleted(new CompletedArgs(false));
                return(false);
            }
        }
Exemple #8
0
        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();
                    }
                }
            };
        }