Skip to content

Commit 08b2294

Browse files
committed
test demo
1 parent dcc0a44 commit 08b2294

2 files changed

Lines changed: 149 additions & 0 deletions

File tree

src/dotnet10_scripts/client.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#:package GeneralUpdate.ClientCore @9.5.10
2+
3+
using System.Text;
4+
using GeneralUpdate.ClientCore;
5+
using GeneralUpdate.Common.Download;
6+
using GeneralUpdate.Common.Internal;
7+
using GeneralUpdate.Common.Internal.Bootstrap;
8+
using GeneralUpdate.Common.Shared.Object;
9+
10+
try
11+
{
12+
Console.WriteLine($"主程序初始化,{DateTime.Now}!");
13+
Console.WriteLine("当前运行目录:" + Environment.CurrentDirectory);
14+
var configinfo = new Configinfo
15+
{
16+
//configinfo.UpdateLogUrl = "https://www.baidu.com";
17+
ReportUrl = "http://127.0.0.1:5000/Upgrade/Report",
18+
UpdateUrl = "http://127.0.0.1:5000/Upgrade/Verification",
19+
AppName = "upgrade.cs",
20+
MainAppName = "TCPUDPDbg.exe",
21+
InstallPath = Environment.CurrentDirectory,
22+
//configinfo.Bowl = "Generalupdate.CatBowl.exe";
23+
//当前客户端的版本号
24+
ClientVersion = "1.0.0.0",
25+
//当前升级端的版本号
26+
UpgradeClientVersion = "1.0.0.0",
27+
//产品id
28+
ProductId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a",
29+
//应用密钥
30+
AppSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6",
31+
//BlackFiles = new List<string> { "123.exe" },
32+
//BlackFormats = new List<string> { "123.dll" },
33+
//BlackDirectories = new List<string> { "123" },
34+
//Scheme = "Bearer",
35+
//Token = "..."
36+
};
37+
_ = await new GeneralClientBootstrap() //单个或多个更新包下载通知事件
38+
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
39+
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
40+
//单个或多个更新包下载完成
41+
.AddListenerMultiDownloadCompleted(OnMultiDownloadCompleted)
42+
//完成所有的下载任务通知
43+
.AddListenerMultiAllDownloadCompleted(OnMultiAllDownloadCompleted)
44+
//下载过程出现的异常通知
45+
.AddListenerMultiDownloadError(OnMultiDownloadError)
46+
//整个更新过程出现的任何问题都会通过这个事件通知
47+
.AddListenerException(OnException)
48+
.SetConfig(configinfo)
49+
.Option(UpdateOption.DownloadTimeOut, 60)
50+
.Option(UpdateOption.Encoding, Encoding.Default)
51+
.LaunchAsync();
52+
Console.WriteLine($"主程序已启动,{DateTime.Now}!");
53+
await Task.Delay(2000);
54+
}
55+
catch (Exception e)
56+
{
57+
Console.WriteLine(e.Message + "\n" + e.StackTrace);
58+
}
59+
60+
void OnMultiDownloadError(object arg1, MultiDownloadErrorEventArgs arg2)
61+
{
62+
var version = arg2.Version as VersionInfo;
63+
Console.WriteLine($"{version.Version} {arg2.Exception}");
64+
}
65+
66+
void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs arg2)
67+
{
68+
Console.WriteLine(arg2.IsAllDownloadCompleted ? "所有的下载任务已完成!" : $"下载任务已失败!{arg2.FailedVersions.Count}");
69+
}
70+
71+
void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
72+
{
73+
var version = arg2.Version as VersionInfo;
74+
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version.Version}, 下载完成!" : $"当前下载版本:{version.Version}, 下载失败!");
75+
}
76+
77+
void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)
78+
{
79+
var version = arg2.Version as VersionInfo;
80+
Console.WriteLine(
81+
$"当前下载版本:{version.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
82+
}
83+
84+
void OnException(object arg1, ExceptionEventArgs arg2)
85+
{
86+
Console.WriteLine($"{arg2.Exception}");
87+
}

src/dotnet10_scripts/upgrade.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#:package GeneralUpdate.Core @9.5.10
2+
3+
using GeneralUpdate.Common.Download;
4+
using GeneralUpdate.Common.Internal;
5+
using GeneralUpdate.Common.Shared.Object;
6+
using GeneralUpdate.Core;
7+
8+
try
9+
{
10+
Console.WriteLine($"升级程序初始化,{DateTime.Now}!");
11+
Console.WriteLine("当前运行目录:" + Context.ScriptDirectory);
12+
_ = await new GeneralUpdateBootstrap()
13+
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
14+
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
15+
//单个或多个更新包下载完成
16+
.AddListenerMultiDownloadCompleted(OnMultiDownloadCompleted)
17+
//完成所有的下载任务通知
18+
.AddListenerMultiAllDownloadCompleted(OnMultiAllDownloadCompleted)
19+
//下载过程出现的异常通知
20+
.AddListenerMultiDownloadError(OnMultiDownloadError)
21+
//整个更新过程出现的任何问题都会通过这个事件通知
22+
.AddListenerException(OnException)
23+
//设置字段映射表,用于解析所有驱动包的信息的字符串
24+
//.SetFieldMappings(fieldMappingsCN)
25+
//是否开启驱动更新
26+
//.Option(UpdateOption.Drive, true)
27+
.LaunchAsync();
28+
Console.WriteLine($"升级程序已启动,{DateTime.Now}!");
29+
await Task.Delay(2000);
30+
}
31+
catch (Exception e)
32+
{
33+
Console.WriteLine(e.Message + "\n" + e.StackTrace);
34+
}
35+
36+
void OnMultiDownloadError(object arg1, MultiDownloadErrorEventArgs arg2)
37+
{
38+
var version = arg2.Version as VersionInfo;
39+
Console.WriteLine($"{version.Version} {arg2.Exception}");
40+
}
41+
42+
void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs arg2)
43+
{
44+
Console.WriteLine(arg2.IsAllDownloadCompleted ? "所有的下载任务已完成!" : $"下载任务已失败!{arg2.FailedVersions.Count}");
45+
}
46+
47+
void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
48+
{
49+
var version = arg2.Version as VersionInfo;
50+
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version.Version}, 下载完成!" : $"当前下载版本:{version.Version}, 下载失败!");
51+
}
52+
53+
void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)
54+
{
55+
var version = arg2.Version as VersionInfo;
56+
Console.WriteLine($"当前下载版本:{version.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
57+
}
58+
59+
void OnException(object arg1, ExceptionEventArgs arg2)
60+
{
61+
Console.WriteLine($"{arg2.Exception}");
62+
}

0 commit comments

Comments
 (0)