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+ }
0 commit comments