From 8d511776b8957663d167e8a69133c0aad99fbf8a Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Sat, 13 Jan 2024 16:51:16 +0800 Subject: [PATCH 1/2] test: drive --- src/c#/GeneralUpdate.Api/Program.cs | 4 ++-- src/c#/GeneralUpdate.Client/MySample.cs | 4 ++-- .../Bootstrap/AbstractBootstrap.cs | 19 +++++++++++++------ .../Bootstrap/UpdateOption.cs | 4 ++-- .../Driver/CommandExecutor.cs | 5 +++-- .../Driver/DriverInformation.cs | 5 +++-- .../Driver/DriverProcessor.cs | 2 +- .../Driver/InstallDriverCommand.cs | 5 +++-- .../Driver/RestoreDriverCommand.cs | 3 ++- .../Exceptions/ThrowExceptionUtility.cs | 6 +++++- .../Middleware/MiddlewareExtensions.cs | 2 +- .../Domain/Entity/.gitkeep | 0 .../GeneralUpdate.Differential.csproj | 3 +++ 13 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/.gitkeep diff --git a/src/c#/GeneralUpdate.Api/Program.cs b/src/c#/GeneralUpdate.Api/Program.cs index 6e8fa59..16c966a 100644 --- a/src/c#/GeneralUpdate.Api/Program.cs +++ b/src/c#/GeneralUpdate.Api/Program.cs @@ -36,7 +36,7 @@ var app = builder.Build(); app.MapGet("/versions/{clientType}/{clientVersion}/{clientAppKey}", (int clientType, string clientVersion, string clientAppKey, IUpdateService updateService) => { var versions = new List(); - var hash = "415eed05eb310f480d1e4d15516fa00e484ddb9f416908b217f17b782ded2030";//生成好的更新包文件的MD5码,因为返回给客户端的时候需要同这个来验证是否可用 + var hash = "28d10f1fc2a23dd1afe0af40d132b25c72ea56005963f653c27889f03d381c8d";//生成好的更新包文件的MD5码,因为返回给客户端的时候需要同这个来验证是否可用 var pubTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); string version = null; if (clientType == AppType.ClientApp) @@ -51,7 +51,7 @@ app.MapGet("/versions/{clientType}/{clientVersion}/{clientAppKey}", (int clientT version = "0.0.0.0"; //version = "9.9.9.9"; //这里设置为9是让程序认为需要更新 } - var url = $"http://127.0.0.1/WpfClient_1_24.1.5.1218.zip";//更新包的下载地址 + var url = $"http://192.168.1.7/WpfClient_1_24.1.5.1218.zip";//更新包的下载地址 var name = "update"; versions.Add(new VersionDTO(hash, pubTime, version, url, name)); return updateService.Update(clientType, clientVersion, version, clientAppKey, GetAppSecretKey(), false, versions); diff --git a/src/c#/GeneralUpdate.Client/MySample.cs b/src/c#/GeneralUpdate.Client/MySample.cs index 0488921..e8fc0b8 100644 --- a/src/c#/GeneralUpdate.Client/MySample.cs +++ b/src/c#/GeneralUpdate.Client/MySample.cs @@ -19,7 +19,7 @@ namespace GeneralUpdate.Client { #region 鎺ㄩ佸姛鑳 - private const string baseUrl = @"http://127.0.0.1:5001"; + private const string baseUrl = @"http://127.0.0.1:5000"; private const string hubName = "versionhub"; internal MySample() @@ -74,7 +74,7 @@ namespace GeneralUpdate.Client //寮鍚┍鍔ㄦ洿鏂 .Option(UpdateOption.Drive, true) //寮鍚仐瑷鍔熻兘锛岄渶瑕侀儴缃睪eneralUpdate.SystemService Windows鏈嶅姟銆 - .Option(UpdateOption.WillMessage, true) + //.Option(UpdateOption.WillMessage, false) .Strategy() //娉ㄥ叆涓涓猣unc璁╃敤鎴峰喅瀹氭槸鍚﹁烦杩囨湰娆℃洿鏂帮紝濡傛灉鏄己鍒舵洿鏂板垯涓嶇敓鏁 //.SetCustomSkipOption(ShowCustomOption) diff --git a/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs b/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs index 2062880..9b45207 100644 --- a/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs @@ -63,8 +63,8 @@ namespace GeneralUpdate.Core.Bootstrap Packet.DownloadTimeOut = GetOption(UpdateOption.DownloadTimeOut); Packet.AppName = $"{Packet.AppName ?? GetOption(UpdateOption.MainApp)}{EXECUTABLE_FILE}"; Packet.TempPath = $"{FileUtil.GetTempDirectory(Packet.LastVersion)}{Path.DirectorySeparatorChar}"; - Packet.DriveEnabled = GetOption(UpdateOption.Drive); - Packet.WillMessageEnabled = GetOption(UpdateOption.WillMessage); + Packet.DriveEnabled = GetOption(UpdateOption.Drive) ?? false; + Packet.WillMessageEnabled = GetOption(UpdateOption.WillMessage) ?? false; var manager = new DownloadManager(Packet.TempPath, Packet.Format, Packet.DownloadTimeOut); manager.MultiAllDownloadCompleted += OnMultiAllDownloadCompleted; manager.MultiDownloadCompleted += OnMultiDownloadCompleted; @@ -156,10 +156,17 @@ namespace GeneralUpdate.Core.Bootstrap public virtual T GetOption(UpdateOption option) { - if (_options == null || _options.Count == 0) return default(T); - var val = _options[option]; - if (val != null) return (T)val.GetValue(); - return default(T); + try + { + if (_options == null || _options.Count == 0) return default(T); + var val = _options[option]; + if (val != null) return (T)val.GetValue(); + return default(T); + } + catch + { + return default(T); + } } #endregion Config option. diff --git a/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs b/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs index f093e35..46e3c09 100644 --- a/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs +++ b/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs @@ -42,12 +42,12 @@ namespace GeneralUpdate.Core.Bootstrap /// /// Whether to enable the driver upgrade function. /// - public static readonly UpdateOption Drive = ValueOf("DRIVE"); + public static readonly UpdateOption Drive = ValueOf("DRIVE"); /// /// Whether open note function, if you want to start needs to be synchronized to deploy 'GeneralUpdate. SystemService' service. /// - public static readonly UpdateOption WillMessage = ValueOf("WILLMESSAGE"); + public static readonly UpdateOption WillMessage = ValueOf("WILLMESSAGE"); #endregion parameter configuration diff --git a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs b/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs index 20055e5..55faa1d 100644 --- a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs +++ b/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs @@ -1,4 +1,5 @@ -锘縰sing System; +锘縰sing GeneralUpdate.Core.Exceptions; +using System; using System.Diagnostics; namespace GeneralUpdate.Core.Driver @@ -38,7 +39,7 @@ If possible, use pre-tested drivers that are proven to work. process.WaitForExit(); if (process.ExitCode != 0) - throw new Exception($"Operation failed code: {process.ExitCode}"); + ThrowExceptionUtility.Throw($"Operation failed code: {process.ExitCode}"); } } } diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs index be975aa..bf442b9 100644 --- a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs +++ b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs @@ -1,4 +1,5 @@ -锘縰sing System; +锘縰sing GeneralUpdate.Core.Exceptions; +using System; using System.Collections.Generic; using System.Linq; @@ -59,7 +60,7 @@ namespace GeneralUpdate.Core.Driver string.IsNullOrWhiteSpace(_information.OutPutDirectory) || !_information.Drivers.Any()) { - throw new InvalidOperationException("Cannot create DriverInformation, not all fields are set."); + ThrowExceptionUtility.ThrowIfNull("Cannot create DriverInformation, not all fields are set."); } return _information; diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs b/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs index 88b2546..8923af2 100644 --- a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs +++ b/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs @@ -8,7 +8,7 @@ namespace GeneralUpdate.Core.Driver /// public class DriverProcessor { - private List _commands = new List(); + private readonly List _commands = new List(); public void AddCommand(IDriverCommand command) { diff --git a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs index 41c3f53..74e7a05 100644 --- a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs +++ b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs @@ -1,4 +1,5 @@ -锘縰sing System; +锘縰sing GeneralUpdate.Core.Exceptions; +using System; using System.IO; using System.Text; @@ -38,7 +39,7 @@ namespace GeneralUpdate.Core.Driver { //restore all the drivers in the backup directory. new RestoreDriverCommand(_information).Execute(); - throw new Exception($"Failed to execute install command for {_information.InstallDirectory}", ex); + ThrowExceptionUtility.Throw($"Failed to execute install command for {_information.InstallDirectory}", ex); } } } diff --git a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs index b2c5d83..f36486c 100644 --- a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs +++ b/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs @@ -1,6 +1,7 @@ 锘縰sing System.IO; using System; using System.Text; +using GeneralUpdate.Core.Exceptions; namespace GeneralUpdate.Core.Driver { @@ -26,7 +27,7 @@ namespace GeneralUpdate.Core.Driver } catch (Exception ex) { - throw new Exception($"Failed to execute restore command for {_information.OutPutDirectory}", ex); + ThrowExceptionUtility.Throw($"Failed to execute restore command for {_information.OutPutDirectory}", ex); } } } diff --git a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs b/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs index 088cd35..a8bbea5 100644 --- a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs +++ b/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs @@ -13,7 +13,11 @@ namespace GeneralUpdate.Core.Exceptions public static void ThrowFileNotFound(string file) => Throw($"File cannot be accessed {file}!"); - public static void ThrowIfNull()=> Throw("Parameter cannot be null"); + public static void ThrowIfNull(string errorMessage = null) + { + errorMessage = errorMessage ?? "Parameter cannot be null"; + Throw(errorMessage); + } /// /// Checks if an object is empty and throws an exception if it is diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs index 4ffa3b1..0fd5687 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs @@ -17,7 +17,7 @@ namespace GeneralUpdate.Core.Pipelines.Middleware public static IPipelineBuilder UseMiddleware<[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline) => pipeline.UseMiddleware(typeof(TMiddleware),true); - public static IPipelineBuilder UseMiddlewareIf<[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline,bool condition) => pipeline.UseMiddleware(typeof(TMiddleware), condition); + public static IPipelineBuilder UseMiddlewareIf<[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline,bool condition = false) => pipeline.UseMiddleware(typeof(TMiddleware), condition); public static IPipelineBuilder UseMiddleware( this IPipelineBuilder pipeline, diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/.gitkeep b/src/c#/GeneralUpdate.Differential/Domain/Entity/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj b/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj index b396901..00fffc8 100644 --- a/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj +++ b/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj @@ -15,6 +15,7 @@ + @@ -27,6 +28,8 @@ + + -- Gitee From 30f3270746405d5dd3facaebc3208559026c1d5e Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Sat, 13 Jan 2024 17:03:12 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- README_en.md | 2 +- src/c#/GeneralUpdate.Client/MySample.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ab53a21..19c96c8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ | 鍥炴粴 | 寰呮祴璇 | 閫愮増鏈洿鏂版椂浼氬浠芥瘡涓増鏈紝濡傛灉鏇存柊澶辫触鍒欓愮増鏈洖婊氥 | | 椹卞姩鏇存柊 | 鏀寔 | 閫愮増鏈洿鏂版椂浼氬浠芥瘡涓増鏈殑椹卞姩鏂囦欢锛.inf锛夛紝濡傛灉鏇存柊澶辫触鍒欓愮増鏈洖婊氥 | | 閬楄█ | 寰呮祴璇 | 寮鏈烘椂鍜屽崌绾ф椂浼氭鏌ュ崌绾ф槸鍚︽垚鍔燂紝濡傛灉澶辫触鍒欐牴鎹仐瑷杩樺師涔嬪墠鐨勫浠姐傞仐瑷鏄洿鏂颁箣鍓嶅氨宸茬粡鑷姩鍒涘缓鍦–:\generalupdate_willmessages鐩綍涓嬬殑will_message.json鏂囦欢銆倃ill_message.json鐨勫唴瀹规槸鎸佷箙鍖栧洖婊氬浠界殑鏂囦欢鐩綍鐩稿叧淇℃伅銆傦紙闇瑕侀儴缃睪eneralUpdate.SystemService绯荤粺鏈嶅姟锛 | -| 鑷畾涔夋柟娉曞垪琛 | 寰呮祴璇 | 娉ㄥ叆涓涓嚜瀹氫箟鏂规硶闆嗗悎锛岃闆嗗悎浼氬湪鏇存柊鍚姩鍓嶆墽琛屻傛墽琛岃嚜瀹氫箟鏂规硶鍒楄〃濡傛灉鍑虹幇浠讳綍寮傚父锛屽皢閫氳繃寮傚父璁㈤槄閫氱煡銆傦紙鎺ㄨ崘鍦ㄦ洿鏂颁箣鍓嶆鏌ュ綋鍓嶈蒋浠剁幆澧冿級 | +| 鑷畾涔夋柟娉曞垪琛 | 鏀寔 | 娉ㄥ叆涓涓嚜瀹氫箟鏂规硶闆嗗悎锛岃闆嗗悎浼氬湪鏇存柊鍚姩鍓嶆墽琛屻傛墽琛岃嚜瀹氫箟鏂规硶鍒楄〃濡傛灉鍑虹幇浠讳綍寮傚父锛屽皢閫氳繃寮傚父璁㈤槄閫氱煡銆傦紙鎺ㄨ崘鍦ㄦ洿鏂颁箣鍓嶆鏌ュ綋鍓嶈蒋浠剁幆澧冿級 | diff --git a/README_en.md b/README_en.md index a3b1c71..ed1fc80 100644 --- a/README_en.md +++ b/README_en.md @@ -29,7 +29,7 @@ | Restore | test | Each version is backed up during a version-by-version update and rolled back version-by-version if the update fails. | | Driver upgrade | yes | The driver file (.INF) of each version is backed up during the version-by-version update and is rolled back version-by-version if the update fails. | | Will message | test | The upgrade is checked for success at boot and upgrade, and if it fails, the previous backup is restored according to the last word. The last word is that the will_message.json file in the C:\generalupdate_willmessages directory was automatically created before the update. will_message.json is about the file directory of the persistent rollback backup.(need to deploy GeneralUpdate. SystemService system service) | -| A list of custom methods | test | Inject a custom collection of methods that are executed before the update starts. Execute a custom method list, and if there are any exceptions, you will be notified by exception subscription.(It is recommended to check the current software environment before updating) | +| A list of custom methods | 鏀寔 | Inject a custom collection of methods that are executed before the update starts. Execute a custom method list, and if there are any exceptions, you will be notified by exception subscription.(It is recommended to check the current software environment before updating) | diff --git a/src/c#/GeneralUpdate.Client/MySample.cs b/src/c#/GeneralUpdate.Client/MySample.cs index e8fc0b8..c84093f 100644 --- a/src/c#/GeneralUpdate.Client/MySample.cs +++ b/src/c#/GeneralUpdate.Client/MySample.cs @@ -72,9 +72,9 @@ namespace GeneralUpdate.Client .Option(UpdateOption.Encoding, Encoding.Default) .Option(UpdateOption.Format, Format.ZIP) //寮鍚┍鍔ㄦ洿鏂 - .Option(UpdateOption.Drive, true) + //.Option(UpdateOption.Drive, true) //寮鍚仐瑷鍔熻兘锛岄渶瑕侀儴缃睪eneralUpdate.SystemService Windows鏈嶅姟銆 - //.Option(UpdateOption.WillMessage, false) + .Option(UpdateOption.WillMessage, true) .Strategy() //娉ㄥ叆涓涓猣unc璁╃敤鎴峰喅瀹氭槸鍚﹁烦杩囨湰娆℃洿鏂帮紝濡傛灉鏄己鍒舵洿鏂板垯涓嶇敓鏁 //.SetCustomSkipOption(ShowCustomOption) -- Gitee