From 396b0e54108486ef4c1c3514c1e11f19d244a84c Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Thu, 23 Nov 2023 22:27:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feature=20=EF=BC=9AReport=20the=20current?= =?UTF-8?q?=20update=20status=20of=20the=20web=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/GeneralUpdateService.cs | 6 ++++++ .../Services/IUpdateService.cs | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs b/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs index 0adb99e..d65c713 100644 --- a/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs +++ b/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs @@ -63,5 +63,11 @@ namespace GeneralUpdate.AspNetCore.Services if (versions == null) throw new ArgumentNullException(@"versions cannot be null !"); if (string.IsNullOrEmpty(clientAppkey) || string.IsNullOrEmpty(appSecretKey)) throw new NullReferenceException("The APP key does not exist !"); } + + + public string Report(int clientType, string clientVersion, string clientAppkey, string appSecretKey, string meesage, string dumpBase64, string logBase64, Exception exception) => string.Empty; + + + private void ParameterVerification(int clientType, string clientVersion, string clientAppkey, string appSecretKey, string meesage, string dumpBase64, string logBase64, Exception exception) { } } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs b/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs index 82cf9a0..7e49511 100644 --- a/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs +++ b/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs @@ -1,4 +1,5 @@ using GeneralUpdate.Core.Domain.DTO; +using System; using System.Collections.Generic; namespace GeneralUpdate.AspNetCore.Services @@ -17,5 +18,21 @@ namespace GeneralUpdate.AspNetCore.Services /// /// Json object. string Update(int clientType, string clientVersion, string serverLastVersion, string clientAppKey, string appSecretKey, bool isForce, List versions); + + /// + /// When this web api is called at the end of the automatic update, it does not mean that every call is successful. + /// Failure, rollback, and success scenarios will inform the server of the result of the update through this web api. + /// If there is an exception let the decision maker decide whether to fix the problem by pushing the latest version of the update again. + /// + /// 1:ClientApp 2:UpdateApp + /// Current version of the client. + /// The appkey agreed by the client and server. + /// Appkey is stored in the database. + /// The message from the client is used to describe the current situation to the decision maker. + /// If an exception occurs, the dump file is returned. + /// If an exception occurs, the log log is returned + /// If an exception occurs, the object is returned. + /// + string Report(int clientType, string clientVersion, string clientAppkey, string appSecretKey, string meesage, string dumpBase64, string logBase64, Exception exception); } } \ No newline at end of file -- Gitee From 87fbfa716d0b962a2d941bcf5f58c5b9d37893c1 Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Fri, 24 Nov 2023 23:44:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feature=EF=BC=9AAdd=20a=20custom=20action?= =?UTF-8?q?=20method=20group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GeneralClientBootstrap.cs | 76 +++++++++++++++++-- .../GeneralUpdateBootstrap.cs | 5 +- .../PlatformWindows/WindowsStrategy.cs | 2 +- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs index b7c690e..9227e62 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs +++ b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs @@ -8,6 +8,7 @@ using GeneralUpdate.Core.Exceptions.CustomArgs; using GeneralUpdate.Core.Exceptions.CustomException; using GeneralUpdate.Core.Strategys; using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; @@ -21,11 +22,16 @@ namespace GeneralUpdate.ClientCore /// public class GeneralClientBootstrap : AbstractBootstrap { - private Func _customOption; - private Func> _customTaskOption; + private Func _customSkipOption; + private Func> _customSkipTaskOption; + + private List> _customOptions; + private List>> _customTaskOptions; public GeneralClientBootstrap() : base() { + _customOptions = new List>(); + _customTaskOptions = new List>>(); } #region Public Methods @@ -48,6 +54,8 @@ namespace GeneralUpdate.ClientCore private async Task BaseLaunch() { + //bool isSuccess = await ExecuteCustomOptions(); + //if (!isSuccess) return this; var versionService = new VersionService(); var mainResp = await versionService.ValidationVersion(Packet.MainUpdateUrl); var upgradeResp = await versionService.ValidationVersion(Packet.UpdateUrl); @@ -126,10 +134,10 @@ namespace GeneralUpdate.ClientCore /// /// Custom function ,Custom actions to let users decide whether to update. true update false do not update . /// - public GeneralClientBootstrap SetCustomOption(Func func) + public GeneralClientBootstrap SetCustomSkipOption(Func func) { if (func == null) throw new ArgumentNullException(nameof(func)); - _customOption = func; + _customSkipOption = func; return this; } @@ -139,10 +147,38 @@ namespace GeneralUpdate.ClientCore /// Custom function ,Custom actions to let users decide whether to update. true update false do not update . /// /// - public GeneralClientBootstrap SetCustomOption(Func> func) + public GeneralClientBootstrap SetCustomSkipOption(Func> func) { if (func == null) throw new ArgumentNullException(nameof(func)); - _customTaskOption = func; + _customSkipTaskOption = func; + return this; + } + + /// + /// Add an asynchronous custom operation. + /// In theory, any custom operation can be done. It is recommended to register the environment check method to ensure that there are normal dependencies and environments after the update is completed. + /// + /// + /// + /// + public GeneralClientBootstrap AddCustomOption(Func func) + { + if(func == null) throw new ArgumentNullException(nameof(func)); + _customOptions.Add(func); + return this; + } + + /// + /// Add a synchronization custom operation. + /// In theory, any custom operation can be done. It is recommended to register the environment check method to ensure that there are normal dependencies and environments after the update is completed. + /// + /// + /// + /// + public GeneralClientBootstrap AddCustomOption(Func> func) + { + if (func == null) throw new ArgumentNullException(nameof(func)); + _customTaskOptions.Add(func); return this; } @@ -173,8 +209,8 @@ namespace GeneralUpdate.ClientCore { bool isSkip = false; if (isForcibly) return false; - if (_customTaskOption != null) isSkip = await _customTaskOption.Invoke(); - if (_customOption != null) isSkip = _customOption.Invoke(); + if (_customSkipTaskOption != null) isSkip = await _customSkipTaskOption.Invoke(); + if (_customSkipOption != null) isSkip = _customSkipOption.Invoke(); return isSkip; } catch (Exception ex) @@ -183,6 +219,30 @@ namespace GeneralUpdate.ClientCore } } + /// + /// Performs all injected custom operations. + /// + /// + private async Task ExecuteCustomOptions() + { + if (_customOptions.Any()) + { + _customOptions.ForEach(option => option.Invoke()); + return true; + } + + if (_customTaskOptions.Any()) + { + foreach (var option in _customTaskOptions) + { + await option.Invoke(); + } + return true; + } + + return true; + } + #endregion Private Methods } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs index 3c90b52..10519c9 100644 --- a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs @@ -12,10 +12,7 @@ namespace GeneralUpdate.Core { public class GeneralUpdateBootstrap : AbstractBootstrap { - public GeneralUpdateBootstrap() : base() - { - Remote(); - } + public GeneralUpdateBootstrap() : base()=> Remote(); /// /// Gets values from system environment variables (ClientParameter object to base64 string). diff --git a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs index a0893a2..864a67e 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs @@ -141,7 +141,7 @@ namespace GeneralUpdate.Core.Strategys.PlatformWindows /// private void WaitForProcessToStart(string applicationPath, TimeSpan timeout, Action callbackAction = null) { - using (Process process = Process.Start(applicationPath)) + using (var process = Process.Start(applicationPath)) { var startTime = DateTime.UtcNow; while (DateTime.UtcNow - startTime < timeout) -- Gitee