private void btnRefresh_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; lvFileList.Items.Clear(); RestRequest req = new RestRequest("GetListFiles", Method.GET); if (ckbDefault.Checked) { req.AddParameter("prefix", AutoUpdatePath); } var res = AutoUpdateServiceClient.Execute <List <string> >(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } foreach (string name in res.Data) { ListViewItem itm = new ListViewItem(name); lvFileList.Items.Add(itm); } } catch (Exception ex) { MessageBox.Show("出错:" + ex.Message); } finally { this.Cursor = Cursors.Default; } }
public AutoUpdateService(string urlWebService) { try { _AutoUpdateService = new AutoUpdateServiceClient(); Initialize(urlWebService); } catch (Exception ex) { _AutoUpdateService = null; throw new RMSAppException(this, "0500", "AutoUpdateService failed. " + ex.Message, ex, false); } }
private void Upload() { try { string key = tbUploadName.Text.Trim(); string filePath = tbFilePath.Text.Trim(); RestRequest req = new RestRequest("GetUploadToken", Method.GET); req.AddParameter("key", key); var res = AutoUpdateServiceClient.Execute(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } string token = res.Content.Trim(new char[] { '"' }); Config config = new Config(); // 设置上传区域 config.Zone = Zone.ZONE_CN_South; // 设置 http 或者 https 上传 config.UseHttps = true; config.UseCdnDomains = true; config.ChunkSize = ChunkUnit.U1024K;//.U512K; ResumableUploader target = new ResumableUploader(config); PutExtra extra = new PutExtra(); extra.ProgressHandler = new UploadProgressHandler(UploadProgress); //设置断点续传进度记录文件 //extra.ResumeRecordFile = ResumeHelper.GetDefaultRecordKey(filePath, key); extra.ResumeRecordFile = key + ".progress"; HttpResult result = target.UploadFile(filePath, AutoUpdatePath + key, token, extra); if (result.Code != (int)HttpCode.OK) { MessageBox.Show("上传失败!" + result.ToString()); } else { MessageBox.Show("上传成功!"); } } catch (Exception ex) { MessageBox.Show("出错:" + ex.Message); } finally { btnUpload.Enabled = true; } }
private bool Verify() { if (string.IsNullOrEmpty(tbVer.Text.Trim())) { MessageBox.Show("版本号不能为空!"); return(false); } if (!IsUpload(AutoUpdatePath + tbUploadName.Text.Trim())) { MessageBox.Show("服务器未上传该文件:" + tbUploadName.Text.Trim()); return(false); } if (rdbClient.Checked)//提交更新客户端 { RestRequest req = new RestRequest("ExistVer/" + tbVer.Text.Trim(), Method.GET); var res = AutoUpdateServiceClient.Execute(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } string result = res.Content; if (result.ToLower().Contains("true")) { MessageBox.Show("该版本号已经存在!请检查!"); return(false); } } else//提交更新更新App { RestRequest req = new RestRequest("ExistAutoUpdateAppVer/" + tbVer.Text.Trim(), Method.GET); var res = AutoUpdateServiceClient.Execute(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } string result = res.Content; if (result.ToLower().Contains("true")) { MessageBox.Show("该版本号已经存在!请检查!"); return(false); } } return(true); }
private bool IsUpload(string filename) { RestRequest req = new RestRequest("GetListFiles", Method.GET); req.AddParameter("prefix", filename); var res = AutoUpdateServiceClient.Execute <List <string> >(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } foreach (string name in res.Data) { if (filename.Equals(name)) { return(true); } } return(false); }
private void btnRefreshCDN_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (string.IsNullOrEmpty(tbUploadName.Text.Trim())) { MessageBox.Show("服务器文件名不能为空!"); return; } string key = tbUploadName.Text.Trim(); RestRequest req = new RestRequest("RefreshCDNUrl", Method.GET); if (ckbDefault.Checked) { key = AutoUpdatePath + key; } req.AddParameter("key", key); var res = AutoUpdateServiceClient.Execute(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } string result = res.Content; if (result.ToLower().Contains("true")) { MessageBox.Show("刷新CDN成功!"); } else { MessageBox.Show("刷新CDN失败!"); } } catch (Exception ex) { MessageBox.Show("出错:" + ex.Message); } finally { this.Cursor = Cursors.Default; } }
private void btnDel_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (lvFileList.SelectedItems.Count <= 0) { MessageBox.Show("请选中要删除的文件!"); return; } string key = lvFileList.SelectedItems[0].Text; RestRequest req = new RestRequest("DelFile", Method.GET); req.AddParameter("key", key); var res = AutoUpdateServiceClient.Execute(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } string result = res.Content; if (result.ToLower().Contains("true")) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } } catch (Exception ex) { MessageBox.Show("出错:" + ex.Message); } finally { this.Cursor = Cursors.Default; } }
private void btnUpdateSubmit_Click(object sender, EventArgs e) { try { if (rdbClient.Checked)//提交更新客户端 { if (!tbUploadName.Text.Trim().ToLower().EndsWith(".rar")) { MessageBox.Show("提交更新客户端,服务器文件名后辍需要为 .rar 格式!"); return; } if (!Verify()) { return; } RestRequest req = new RestRequest("AddVer", Method.POST); UpdateVerDto model = new UpdateVerDto(); model.Ver = tbVer.Text.Trim(); model.UpdatePackName = tbUploadName.Text.Trim(); model.Remark = rtbRemark.Text.Trim(); req.AddObject(model); var res = AutoUpdateServiceClient.Execute(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } int re = int.Parse(res.Content); if (re > 0) { MessageBox.Show("提交成功!"); } else { MessageBox.Show("提交失败!"); } } else//提交更新更新App { if (!tbUploadName.Text.Trim().ToLower().EndsWith(".exe")) { MessageBox.Show("提交更新App,服务器文件名后辍需要为 .exe 格式!"); return; } if (!Verify()) { return; } RestRequest req = new RestRequest("AddAutoUpdateAppVer", Method.POST); AppUpdateVerDto model = new AppUpdateVerDto(); model.Ver = tbVer.Text.Trim(); model.UpdatePackName = tbUploadName.Text.Trim(); model.Remark = rtbRemark.Text.Trim(); req.AddObject(model); var res = AutoUpdateServiceClient.Execute(req); if (res.ErrorMessage != null) { throw new Exception(res.ErrorMessage); } int re = int.Parse(res.Content); if (re > 0) { MessageBox.Show("提交成功!"); } else { MessageBox.Show("提交失败!"); } } } catch (Exception ex) { MessageBox.Show("出错:" + ex.Message); } }