GZUpdate自动升级服务 .NET C/S Winform客户端程序自动升级演示


GZUpdate自动升级服务 .NET C/S Winform客户端程序自动升级演示

新建一个winform项目

GZUpdate自动升级程序客户端演示

添加Nuget包 GZUpdate.Client

nuget包名:GZUpdate.Client

GZUpdate自动升级程序客户端演示

GZUpdate自动升级程序 支持.net framework 和 .net core平台

GZUpdate自动升级程序客户端演示

客户端升级配置

GZUpdate自动升级程序客户端演示

获得当前版本

C# 全选
private void Form1_Load(object sender, EventArgs e)
{
	// 当前版本
	txt_CurrentVersion.Text = UpdateClient.getCurrentVersion();

	// 删除上个版本的备份文件
	UpdateServices.deleteBak();
}

初始化更新服务

C# 全选
/// <summary>
/// 初始化更新服务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_init_Click(object sender, EventArgs e)
{
	// 版本更新服务器
	string updateServer = txt_update_server.Text;
	// 产品ID
	string productID = txt_ProductID.Text;
	// 版本类型
	EnumVersionType updateVersionType = (EnumVersionType)Enum.Parse(typeof(EnumVersionType), cmb_VersionType.Text, true);


	if (String.IsNullOrEmpty(updateServer))
	{
		MessageBox.Show("请填写更新服务器!");
	}
	if (String.IsNullOrEmpty(productID))
	{
		MessageBox.Show("请填写产品编号!");
	}

	UpdateServices.Regsiter(updateServer, productID, updateVersionType);

	btn_CheckUpdate.Enabled = true;

}

检查更新

C# 全选
        private void btn_CheckUpdate_Click(object sender, EventArgs e)
        {
            var data = UpdateServices.doCheckVersion();
            if (data != null && data.Count > 0)
            {
                string newVersion = data.OrderByDescending(o => o.version).Select(s => s.versionTxt).FirstOrDefault();
                if (MessageBox.Show($"发现新版本[{newVersion}],是否立即更新?", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Cancel)
                    return;
 
 
                lbl_updateMessage.Visible = true;
                progressBar1.Visible = true;
 
                UpdateProcess updateHandle = new UpdateProcess();
 
                // 通知消息
                updateHandle.OnUpdateMessage += (message) =>
                {
                    lbl_updateMessage.Text = message;
                };
                // 更新进度
                updateHandle.OnUpdateProcess += (total, current) =>
                {
                    progressBar1.Maximum = total;
                    progressBar1.Value = current;
                };
                updateHandle.OnComplate += (versionInfo) =>
                {
                    MessageBox.Show($"升级完成,当前版本[{versionInfo.versionTxt}],重启系统后可看效果!");
                };
                updateHandle.OnFail += (message, ex) =>
                {
                    MessageBox.Show("更新失败:" + ex.Message);
                };
 
                updateHandle.DoUpdate();
            }
            else
            {
                MessageBox.Show("当前已经是最新版本");
            }
        }

 

测试

制作升级包

先编译一个初始的版本备份起来,然后修改窗体的背景色

GZUpdate自动升级程序客户端演示

再次编译,把生成新的exe打包为一个zip文件

GZUpdate自动升级程序客户端演示

GZUpdate自动升级程序客户端演示

目前只支持打包为zip格式的压缩包

压缩包的内容截图

GZUpdate自动升级程序客户端演示

上传升级包

GZUpdate自动升级程序客户端演示

GZUpdate自动升级程序客户端演示

压缩包文件为上一步制作的压缩包 zip文件

版本采用《(yy)(MM)(dd)序号(两位数字) 》的方式

保存后如图

GZUpdate自动升级程序客户端演示

升级测试

GZUpdate自动升级程序客户端演示

升级服务器:升级服务的服务器信息 https://www.***.com

产品标识:由于升级服务器支持多个产品,用产品标识来区分不同的应用升级

版本类型:支持多种版本类型,发布版本/测试版本,互不干扰

点击检查更新按钮后,系统从服务器检索是否有新版本,如果存在新版本,会提示更新,点击是(Y),系统进行更新

GZUpdate自动升级程序客户端演示

为了安全考虑,动态图片中对版本服务器做了*处理,实际使用中,这里需要是实际的服务器地址

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
管理员
上一篇:没有了
评论列表

发表评论

评论内容
昵称:
关联文章