代码拉取完成,页面将自动刷新
同步操作将从 General/GeneralUpdate 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
GeneralUpdate是基于.net standard开发的一款(c/s应用)自动升级程序。该组件将更新的核心部分抽离出来方便应用于多种项目当中目前适用于wpf,控制台应用,winfrom。
QQ群:580749909
(1) Example GeneralUpdate.ClientCore
private ClientParameter clientParameter;
private GeneralClientBootstrap generalClientBootstrap;
private void Button_Click(object sender, RoutedEventArgs e)
{
Task.Run(async()=>
{
//主程序信息
var mainVersion = "1.1.1";
var mianType = 1;
//该对象用于主程序客户端与更新组件进程之间交互用的对象
clientParameter = new ClientParameter();
//更新组件的版本号
clientParameter.ClientVersion = "1.1.1";
//客户端类型:1.主程序客户端 2.更新组件
clientParameter.ClientType = 2;
//更新程序exe名称
clientParameter.AppName = "AutoUpdate.ConsoleApp";
//主程序客户端exe名称
clientParameter.MainAppName = "AutoUpdate.Test";
//本机的客户端程序应用地址
clientParameter.InstallPath = @"D:\update_test";
//更新公告网页
clientParameter.UpdateLogUrl = "https://www.baidu.com/";
//更新组件请求验证更新的服务端地址
clientParameter.ValidateUrl = $"https://127.0.0.1:5001/api/update/getUpdateValidate/{ clientParameter.ClientType }/{ clientParameter.ClientVersion }";
//更新组件更新包下载地址
clientParameter.UpdateUrl = $"https://127.0.0.1:5001/api/update/getUpdateVersions/{ clientParameter.ClientType }/{ clientParameter.ClientVersion }";
//主程序客户端请求验证更新的服务端地址
clientParameter.MainValidateUrl = $"https://127.0.0.1:5001/api/update/getUpdateValidate/{ mianType }/{ mainVersion }";
//主程序客户端更新包下载地址
clientParameter.MainUpdateUrl = $"https://127.0.0.1:5001/api/update/getUpdateVersions/{ mianType }/{ mainVersion }";
generalClientBootstrap = new GeneralClientBootstrap();
//单个或多个更新包下载通知事件
generalClientBootstrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged;
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
generalClientBootstrap.MutiDownloadStatistics += OnMutiDownloadStatistics;
//单个或多个更新包下载完成
generalClientBootstrap.MutiDownloadCompleted += OnMutiDownloadCompleted;
//完成所有的下载任务通知
generalClientBootstrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted;
//下载过程出现的异常通知
generalClientBootstrap.MutiDownloadError += OnMutiDownloadError;
//整个更新过程出现的任何问题都会通过这个事件通知
generalClientBootstrap.Exception += OnException;
//ClientStrategy该更新策略将完成1.自动升级组件自更新 2.启动更新组件 3.配置好ClientParameter无需再像之前的版本写args数组进程通讯了。
generalClientBootstrap.Config(clientParameter).
Strategy<ClientStrategy>();
await generalClientBootstrap.LaunchTaskAsync();
});
}
private void OnMutiDownloadStatistics(object sender, MutiDownloadStatisticsEventArgs e)
{
//e.Remaining 剩余下载时间
//e.Speed 下载速度
//e.Version 当前下载的版本信息
}
private void OnMutiDownloadProgressChanged(object sender, MutiDownloadProgressChangedEventArgs e)
{
//e.TotalBytesToReceive 当前更新包需要下载的总大小
//e.ProgressValue 当前进度值
//e.ProgressPercentage 当前进度的百分比
//e.Version 当前下载的版本信息
//e.Type 当前正在执行的操作 1.ProgressType.Check 检查版本信息中 2.ProgressType.Donwload 正在下载当前版本 3. ProgressType.Updatefile 更新当前版本 4. ProgressType.Done更新完成 5.ProgressType.Fail 更新失败
//e.BytesReceived 已下载大小
}
(2) Example GeneralUpdate.Core
static void Main(string[] args)
{
var resultBase64 = args[0];
var bootstrap = new GeneralUpdateBootstrap();
bootstrap.Exception += OnException;
bootstrap.MutiDownloadError += OnMutiDownloadError;
bootstrap.MutiDownloadCompleted += OnMutiDownloadCompleted;
bootstrap.MutiDownloadStatistics += OnMutiDownloadStatistics;
bootstrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged;
bootstrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted;
bootstrap.Strategy<DefaultStrategy>().
Option(UpdateOption.DownloadTimeOut, 60).
RemoteAddressBase64(resultBase64).
LaunchAsync();
}
(3) Example GeneralUpdate.AspNetCore
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSingleton<IUpdateService, GeneralUpdateService>();
}
UpdateController.cs
private readonly ILogger<UpdateController> _logger;
private readonly IUpdateService _updateService;
public UpdateController(ILogger<UpdateController> logger, IUpdateService updateService)
{
_logger = logger;
_updateService = updateService;
}
/// <summary>
/// https://localhost:5001/api/update/getUpdateVersions/1/1.1.1
/// </summary>
/// <param name="clientType"> 1:ClientApp 2:UpdateApp</param>
/// <param name="clientVersion"></param>
/// <returns></returns>
[HttpGet("getUpdateVersions/{clientType}/{clientVersion}")]
public async Task<IActionResult> GetUpdateVersions(int clientType, string clientVersion)
{
_logger.LogInformation("Client request 'GetUpdateVersions'.");
var resultJson = await _updateService.UpdateVersionsTaskAsync(clientType, clientVersion, UpdateVersions);
return Ok(resultJson);
}
/// <summary>
/// https://localhost:5001/api/update/getUpdateValidate/1/1.1.1
/// </summary>
/// <param name="clientType"> 1:ClientApp 2:UpdateApp</param>
/// <param name="clientVersion"></param>
/// <returns></returns>
[HttpGet("getUpdateValidate/{clientType}/{clientVersion}")]
public async Task<IActionResult> GetUpdateValidate(int clientType, string clientVersion)
{
_logger.LogInformation("Client request 'GetUpdateValidate'.");
var lastVersion = GetLastVersion();
var resultJson = await _updateService.UpdateValidateTaskAsync(clientType, clientVersion, lastVersion, true, GetValidateInfos);
return Ok(resultJson);
}
作者:Juster.zhu & Charles.Yu
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。