1- // See https://aka.ms/new-console-template for more information
2- Console . WriteLine ( "Hello, World!" ) ;
1+ using System . Text ;
2+ using GeneralUpdate . Core ;
3+ using GeneralUpdate . Core . Bootstrap ;
4+ using GeneralUpdate . Core . Domain . Enum ;
5+ using GeneralUpdate . Core . Events . CommonArgs ;
6+ using GeneralUpdate . Core . Events . MultiEventArgs ;
7+ using GeneralUpdate . Core . Strategys . PlatformWindows ;
8+
9+ Task . Run ( async ( ) =>
10+ {
11+ var bootStrap = await new GeneralUpdateBootstrap ( )
12+ //单个或多个更新包下载通知事件
13+ . AddListenerMultiDownloadProgress ( OnMultiDownloadProgressChanged )
14+ //单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
15+ . AddListenerMultiDownloadStatistics ( OnMultiDownloadStatistics )
16+ //单个或多个更新包下载完成
17+ . AddListenerMultiDownloadCompleted ( OnMultiDownloadCompleted )
18+ //完成所有的下载任务通知
19+ . AddListenerMultiAllDownloadCompleted ( OnMultiAllDownloadCompleted )
20+ //下载过程出现的异常通知
21+ . AddListenerMultiDownloadError ( OnMultiDownloadError )
22+ //整个更新过程出现的任何问题都会通过这个事件通知
23+ . AddListenerException ( OnException )
24+ . Strategy < WindowsStrategy > ( )
25+ . Option ( UpdateOption . Encoding , Encoding . Default )
26+ . Option ( UpdateOption . DownloadTimeOut , 60 )
27+ . Option ( UpdateOption . Format , Format . ZIP )
28+ . LaunchTaskAsync ( ) ;
29+ } ) ;
30+
31+ static void OnMultiDownloadStatistics ( object sender , MultiDownloadStatisticsEventArgs e )
32+ {
33+ Console . WriteLine ( $ " { e . Speed } , { e . Remaining . ToShortTimeString ( ) } ") ;
34+ }
35+
36+ static void OnMultiDownloadProgressChanged ( object sender , MultiDownloadProgressChangedEventArgs e )
37+ {
38+ switch ( e . Type )
39+ {
40+ case ProgressType . Check :
41+ break ;
42+
43+ case ProgressType . Download :
44+ Console . WriteLine ( $ " { Math . Round ( e . ProgressValue * 100 , 2 ) } % , Receivedbyte:{ e . BytesReceived } M ,Totalbyte:{ e . TotalBytesToReceive } M") ;
45+ break ;
46+
47+ case ProgressType . Updatefile :
48+ break ;
49+
50+ case ProgressType . Done :
51+ break ;
52+
53+ case ProgressType . Fail :
54+ break ;
55+ }
56+ }
57+
58+ static void OnMultiDownloadCompleted ( object sender , MultiDownloadCompletedEventArgs e )
59+ {
60+ //var info = e.Version as GeneralUpdate.Core.Domain.Entity.VersionInfo;
61+ //Console.WriteLine($"{info.Name} download completed.");
62+ }
63+
64+ static void OnMultiAllDownloadCompleted ( object sender , MultiAllDownloadCompletedEventArgs e )
65+ {
66+ Console . WriteLine ( $ "AllDownloadCompleted { e . IsAllDownloadCompleted } ") ;
67+ }
68+
69+ static void OnMultiDownloadError ( object sender , MultiDownloadErrorEventArgs e )
70+ {
71+ //var info = e.Version as GeneralUpdate.Core.Domain.Entity.VersionInfo;
72+ //Console.WriteLine($"{info.Name},{e.Exception.Message}.");
73+ }
74+
75+ static void OnException ( object sender , ExceptionEventArgs e )
76+ {
77+ Console . WriteLine ( $ "{ e . Exception . Message } ") ;
78+ }
0 commit comments