Skip to content

Commit 7cef87a

Browse files
committed
Remove try from middleware
if any issues occur in the middleware, the update should be terminated immediately.
1 parent 8454197 commit 7cef87a

File tree

7 files changed

+44
-96
lines changed

7 files changed

+44
-96
lines changed

src/c#/GeneralUpdate.ClientCore/Pipeline/CompressMiddleware.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@ public Task InvokeAsync(PipelineContext? context)
1616
{
1717
return Task.Run(() =>
1818
{
19-
try
20-
{
21-
var format = context.Get<string>("Format");
22-
var sourcePath = context.Get<string>("ZipFilePath");
23-
var patchPath = context.Get<string>("PatchPath");
24-
var encoding = context.Get<Encoding>("Encoding");
25-
CompressProvider.Decompress(format,sourcePath,patchPath, encoding);
26-
}
27-
catch (Exception e)
28-
{
29-
Debug.WriteLine(e);
30-
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
31-
}
19+
var format = context.Get<string>("Format");
20+
var sourcePath = context.Get<string>("ZipFilePath");
21+
var patchPath = context.Get<string>("PatchPath");
22+
var encoding = context.Get<Encoding>("Encoding");
23+
CompressProvider.Decompress(format,sourcePath,patchPath, encoding);
3224
});
3325
}
3426
}

src/c#/GeneralUpdate.ClientCore/Pipeline/HashMiddleware.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ public class HashMiddleware : IMiddleware
1313
{
1414
public async Task InvokeAsync(PipelineContext context)
1515
{
16-
try
17-
{
18-
var path = context.Get<string>("ZipFilePath");
19-
var hash = context.Get<string>("Hash");
20-
var isVerify = await VerifyFileHash(path, hash);
21-
if (!isVerify) throw new CryptographicException("Hash verification failed .");
22-
}
23-
catch (Exception exception)
24-
{
25-
Debug.WriteLine(exception.Message);
26-
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
27-
}
16+
var path = context.Get<string>("ZipFilePath");
17+
var hash = context.Get<string>("Hash");
18+
var isVerify = await VerifyFileHash(path, hash);
19+
if (!isVerify) throw new CryptographicException("Hash verification failed .");
2820
}
2921

3022
private Task<bool> VerifyFileHash(string path, string hash)

src/c#/GeneralUpdate.ClientCore/Pipeline/PatchMiddleware.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@ public class PatchMiddleware : IMiddleware
1414
{
1515
public async Task InvokeAsync(PipelineContext context)
1616
{
17-
try
18-
{
19-
var sourcePath = context.Get<string>("SourcePath");
20-
var targetPath = context.Get<string>("PatchPath");
21-
await DifferentialCore.Instance.Dirty(sourcePath, targetPath);
22-
}
23-
catch (Exception exception)
24-
{
25-
Debug.WriteLine(exception.Message);
26-
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
27-
}
17+
var sourcePath = context.Get<string>("SourcePath");
18+
var targetPath = context.Get<string>("PatchPath");
19+
await DifferentialCore.Instance.Dirty(sourcePath, targetPath);
2820
}
2921
}

src/c#/GeneralUpdate.Core/Pipeline/CompressMiddleware.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@ public Task InvokeAsync(PipelineContext context)
1616
{
1717
return Task.Run(() =>
1818
{
19-
try
20-
{
21-
var format = context.Get<string>("Format");
22-
var sourcePath = context.Get<string>("ZipFilePath");
23-
var patchPath = context.Get<string>("PatchPath");
24-
var encoding = context.Get<Encoding>("Encoding");
25-
CompressProvider.Decompress(format, sourcePath, patchPath, encoding);
26-
}
27-
catch (Exception e)
28-
{
29-
Debug.WriteLine(e.Message);
30-
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
31-
}
19+
var format = context.Get<string>("Format");
20+
var sourcePath = context.Get<string>("ZipFilePath");
21+
var patchPath = context.Get<string>("PatchPath");
22+
var encoding = context.Get<Encoding>("Encoding");
23+
CompressProvider.Decompress(format, sourcePath, patchPath, encoding);
3224
});
3325
}
3426
}

src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,30 @@ public Task InvokeAsync(PipelineContext context)
2525
{
2626
return Task.Run(() =>
2727
{
28-
try
29-
{
30-
var outPutPath = context.Get<string>("DriverOutPut");
31-
if (string.IsNullOrWhiteSpace(outPutPath))
32-
return;
28+
var outPutPath = context.Get<string>("DriverOutPut");
29+
if (string.IsNullOrWhiteSpace(outPutPath))
30+
return;
3331

34-
var patchPath = context.Get<string>("PatchPath");
35-
if (string.IsNullOrWhiteSpace(patchPath))
36-
return;
32+
var patchPath = context.Get<string>("PatchPath");
33+
if (string.IsNullOrWhiteSpace(patchPath))
34+
return;
3735

38-
var fieldMappings = context.Get<Dictionary<string, string>>("FieldMappings");
39-
if (fieldMappings == null || fieldMappings.Count == 0)
40-
return;
36+
var fieldMappings = context.Get<Dictionary<string, string>>("FieldMappings");
37+
if (fieldMappings == null || fieldMappings.Count == 0)
38+
return;
4139

42-
var information = new DriverInformation.Builder()
43-
.SetDriverFileExtension(FileExtension)
44-
.SetOutPutDirectory(outPutPath)
45-
.SetDriverDirectory(patchPath)
46-
.SetFieldMappings(fieldMappings)
47-
.Build();
40+
var information = new DriverInformation.Builder()
41+
.SetDriverFileExtension(FileExtension)
42+
.SetOutPutDirectory(outPutPath)
43+
.SetDriverDirectory(patchPath)
44+
.SetFieldMappings(fieldMappings)
45+
.Build();
4846

49-
var processor = new DriverProcessor();
50-
processor.AddCommand(new BackupDriverCommand(information));
51-
processor.AddCommand(new DeleteDriverCommand(information));
52-
processor.AddCommand(new InstallDriverCommand(information));
53-
processor.ProcessCommands();
54-
}
55-
catch (Exception exception)
56-
{
57-
Debug.WriteLine(exception.Message);
58-
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
59-
}
47+
var processor = new DriverProcessor();
48+
processor.AddCommand(new BackupDriverCommand(information));
49+
processor.AddCommand(new DeleteDriverCommand(information));
50+
processor.AddCommand(new InstallDriverCommand(information));
51+
processor.ProcessCommands();
6052
});
6153
}
6254
}

src/c#/GeneralUpdate.Core/Pipeline/HashMiddleware.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ public class HashMiddleware : IMiddleware
1313
{
1414
public async Task InvokeAsync(PipelineContext context)
1515
{
16-
try
16+
var path = context.Get<string>("ZipFilePath");
17+
var hash = context.Get<string>("Hash");
18+
19+
if (!string.IsNullOrWhiteSpace(hash))
1720
{
18-
var path = context.Get<string>("ZipFilePath");
19-
var hash = context.Get<string>("Hash");
2021
var isVerify = await VerifyFileHash(path, hash);
2122
if (!isVerify) throw new CryptographicException("Hash verification failed !");
2223
}
23-
catch (Exception exception)
24-
{
25-
Debug.WriteLine(exception.Message);
26-
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
27-
}
2824
}
2925

3026
private Task<bool> VerifyFileHash(string path, string hash)

src/c#/GeneralUpdate.Core/Pipeline/PatchMiddleware.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@ public class PatchMiddleware : IMiddleware
1414
{
1515
public async Task InvokeAsync(PipelineContext context)
1616
{
17-
try
18-
{
19-
var sourcePath = context.Get<string>("SourcePath");
20-
var targetPath = context.Get<string>("PatchPath");
21-
await DifferentialCore.Instance?.Dirty(sourcePath, targetPath);
22-
}
23-
catch (Exception exception)
24-
{
25-
Debug.WriteLine(exception.Message);
26-
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
27-
}
17+
var sourcePath = context.Get<string>("SourcePath");
18+
var targetPath = context.Get<string>("PatchPath");
19+
await DifferentialCore.Instance?.Dirty(sourcePath, targetPath);
2820
}
2921
}

0 commit comments

Comments
 (0)