diff --git a/src/c#/GeneralUpdate.Common/Internal/Strategy/AbstractStrategy.cs b/src/c#/GeneralUpdate.Common/Internal/Strategy/AbstractStrategy.cs index dacb0d97..e06f5bed 100644 --- a/src/c#/GeneralUpdate.Common/Internal/Strategy/AbstractStrategy.cs +++ b/src/c#/GeneralUpdate.Common/Internal/Strategy/AbstractStrategy.cs @@ -42,5 +42,12 @@ protected static void Clear(string path) if (Directory.Exists(path)) StorageManager.DeleteDirectory(path); } + + protected static string CheckPath(string path, string name) + { + if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name)) return string.Empty; + var tempPath = Path.Combine(path, name); + return File.Exists(tempPath) ? tempPath : string.Empty; + } } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs index 5bb961db..393a75be 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs @@ -21,82 +21,79 @@ public class LinuxStrategy : AbstractStrategy public override void Create(GlobalConfigInfo parameter) => _configinfo = parameter; - public override void Execute() + public override async Task ExecuteAsync() { - Task.Run(async () => + try { - try + var status = ReportType.None; + var patchPath = StorageManager.GetTempDirectory(Patchs); + foreach (var version in _configinfo.UpdateVersions) { - var status = ReportType.None; - var patchPath = StorageManager.GetTempDirectory(Patchs); - foreach (var version in _configinfo.UpdateVersions) + try { - try - { - var context = new PipelineContext(); - //Common - context.Add("ZipFilePath", - Path.Combine(_configinfo.TempPath, $"{version.Name}{_configinfo.Format}")); - //Hash middleware - context.Add("Hash", version.Hash); - //Zip middleware - context.Add("Format", _configinfo.Format); - context.Add("Name", version.Name); - context.Add("Encoding", _configinfo.Encoding); - //Patch middleware - context.Add("SourcePath", _configinfo.InstallPath); - context.Add("PatchPath", patchPath); - context.Add("PatchEnabled", _configinfo.PatchEnabled); - //Driver middleware - if (_configinfo.DriveEnabled == true) - { - context.Add("DriverOutPut", StorageManager.GetTempDirectory("DriverOutPut")); - context.Add("FieldMappings", _configinfo.FieldMappings); - } - - var pipelineBuilder = new PipelineBuilder(context) - .UseMiddlewareIf(_configinfo.PatchEnabled) - .UseMiddleware() - .UseMiddleware() - .UseMiddlewareIf(_configinfo.DriveEnabled); - await pipelineBuilder.Build(); - status = ReportType.Success; - } - catch (Exception e) + var context = new PipelineContext(); + //Common + context.Add("ZipFilePath", + Path.Combine(_configinfo.TempPath, $"{version.Name}{_configinfo.Format}")); + //Hash middleware + context.Add("Hash", version.Hash); + //Zip middleware + context.Add("Format", _configinfo.Format); + context.Add("Name", version.Name); + context.Add("Encoding", _configinfo.Encoding); + //Patch middleware + context.Add("SourcePath", _configinfo.InstallPath); + context.Add("PatchPath", patchPath); + context.Add("PatchEnabled", _configinfo.PatchEnabled); + //Driver middleware + if (_configinfo.DriveEnabled == true) { - status = ReportType.Failure; - GeneralTracer.Error( - "The Execute method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", - e); - EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message)); + context.Add("DriverOutPut", StorageManager.GetTempDirectory("DriverOutPut")); + context.Add("FieldMappings", _configinfo.FieldMappings); } - finally - { - await VersionService.Report(_configinfo.ReportUrl - , version.RecordId - , status - , version.AppType - , _configinfo.Scheme - , _configinfo.Token); - } - } - if (!string.IsNullOrEmpty(_configinfo.UpdateLogUrl)) + var pipelineBuilder = new PipelineBuilder(context) + .UseMiddlewareIf(_configinfo.PatchEnabled) + .UseMiddleware() + .UseMiddleware() + .UseMiddlewareIf(_configinfo.DriveEnabled); + await pipelineBuilder.Build(); + status = ReportType.Success; + } + catch (Exception e) { - OpenBrowser(_configinfo.UpdateLogUrl); + status = ReportType.Failure; + GeneralTracer.Error( + "The ExecuteAsync method in the GeneralUpdate.Core.LinuxStrategy class throws an exception.", + e); + EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message)); + } + finally + { + await VersionService.Report(_configinfo.ReportUrl + , version.RecordId + , status + , version.AppType + , _configinfo.Scheme + , _configinfo.Token); } - - Clear(patchPath); - Clear(_configinfo.TempPath); - StartApp(); } - catch (Exception e) + + if (!string.IsNullOrEmpty(_configinfo.UpdateLogUrl)) { - GeneralTracer.Error( - "The Execute method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e); - EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message)); + OpenBrowser(_configinfo.UpdateLogUrl); } - }); + + Clear(patchPath); + Clear(_configinfo.TempPath); + StartApp(); + } + catch (Exception e) + { + GeneralTracer.Error( + "The ExecuteAsync method in the GeneralUpdate.Core.LinuxStrategy class throws an exception.", e); + EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message)); + } } public override void StartApp() @@ -113,7 +110,7 @@ public override void StartApp() catch (Exception e) { GeneralTracer.Error( - "The StartApp method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e); + "The StartApp method in the GeneralUpdate.Core.LinuxStrategy class throws an exception.", e); EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message)); } finally @@ -123,13 +120,6 @@ public override void StartApp() } } - private string CheckPath(string path, string name) - { - if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name)) return string.Empty; - var tempPath = Path.Combine(path, name); - return File.Exists(tempPath) ? tempPath : string.Empty; - } - /// /// Executes the user-specified script. /// diff --git a/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs index 9c123154..b9e8e999 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs @@ -68,7 +68,7 @@ public override async Task ExecuteAsync() { status = ReportType.Failure; GeneralTracer.Error( - "The Execute method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", + "The ExecuteAsync method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e); EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message)); } @@ -95,7 +95,7 @@ await VersionService.Report(_configinfo.ReportUrl catch (Exception e) { GeneralTracer.Error( - "The Execute method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e); + "The ExecuteAsync method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e); EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message)); } } @@ -128,11 +128,6 @@ public override void StartApp() } } - private string CheckPath(string path,string name) - { - if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name)) return string.Empty; - var tempPath = Path.Combine(path, name); - return File.Exists(tempPath) ? tempPath : string.Empty; - } + } } \ No newline at end of file