Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
134 changes: 62 additions & 72 deletions src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>()
.UseMiddlewareIf<DriverMiddleware>(_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<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>()
.UseMiddlewareIf<DriverMiddleware>(_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()
Expand All @@ -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
Expand All @@ -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;
}

/// <summary>
/// Executes the user-specified script.
/// </summary>
Expand Down
11 changes: 3 additions & 8 deletions src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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;
}

}
}