Ejemplo n.º 1
0
        /// <summary>
        /// 升级
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BtnUpdate_Click(object sender, EventArgs e)
        {
            UpdateClient client = null;

            try
            {
                var updateFiles = bindingSource.DataSource as List <UpdateFileInfo>;
                if (updateFiles.Count == 0)
                {
                    MessageBox.Show("没有需要升级的文件");
                    return;
                }

                if (updateFiles.Any(x => string.IsNullOrEmpty(x.FtpPath)))
                {
                    MessageBox.Show("请先将文件上传至FTP");
                    return;
                }

                txtLog.Text = string.Empty;

                var data = new UpdateData {
                    Config = this.Config, Files = updateFiles.ToArray()
                };
                UpdaterClientHandler handler = new UpdaterClientHandler();
                handler.ReceiveMessage += Handler_ReceiveMessage;
                client = new UpdateClient(handler);
                await client.Connect(this.Config.ServerAddress);

                await client.Send(JsonHelper.ToJson(data));
            }
            catch (Exception ex)
            {
                client?.Stop();
                MessageBox.Show("上传文件到FTP异常:" + ex.Message);
            }
        }
Ejemplo n.º 2
0
 public UpdateClient(UpdaterClientHandler handler)
 {
     this.ClientHandler = handler;
 }