Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ private void ApplyRuntimeOptions()
{
_configInfo.Encoding = GetOption(UpdateOption.Encoding) ?? Encoding.Default;
_configInfo.Format = GetOption(UpdateOption.Format) ?? Format.ZIP;
var downloadTimeoutOption = GetOption(UpdateOption.DownloadTimeOut);
_configInfo.DownloadTimeOut = downloadTimeoutOption ?? 60;
var downloadTimeOut = GetOption(UpdateOption.DownloadTimeOut);
_configInfo.DownloadTimeOut = downloadTimeOut == 0 ? 60 : downloadTimeOut;
_configInfo.DriveEnabled = GetOption(UpdateOption.Drive) ?? false;
_configInfo.PatchEnabled = GetOption(UpdateOption.Patch) ?? true;
}
Expand Down
127 changes: 62 additions & 65 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)
{
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));
}
finally
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)
{
await VersionService.Report(_configinfo.ReportUrl
, version.RecordId
, status
, version.AppType
, _configinfo.Scheme
, _configinfo.Token);
context.Add("DriverOutPut", StorageManager.GetTempDirectory("DriverOutPut"));
context.Add("FieldMappings", _configinfo.FieldMappings);
}
}

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 Down
Loading