@@ -32,47 +32,85 @@ public UnzipTask(CancellationToken token, string archiveFilePath, NPath extracte
32
32
this . estimatedDurationProgress = estimatedDurationProgress ;
33
33
}
34
34
35
- protected override void Run ( bool success )
35
+ protected void BaseRun ( bool success )
36
36
{
37
37
base . Run ( success ) ;
38
+ }
38
39
39
- Logger . Trace ( "Unzip File: {0} to Path: {1}" , archiveFilePath , extractedPath ) ;
40
+ protected override void Run ( bool success )
41
+ {
42
+ BaseRun ( success ) ;
43
+
44
+ RaiseOnStart ( ) ;
40
45
41
46
try
42
47
{
43
- zipHelper . Extract ( archiveFilePath , extractedPath , Token , zipFileProgress , estimatedDurationProgress ) ;
48
+ RunUnzip ( success ) ;
44
49
}
45
50
catch ( Exception ex )
46
51
{
47
- var message = "Error Unzipping file" ;
48
-
49
- Logger . Error ( ex , message ) ;
50
- throw new UnzipTaskException ( message ) ;
52
+ Errors = ex . Message ;
53
+ if ( ! RaiseFaultHandlers ( ex ) )
54
+ throw ;
51
55
}
56
+ finally
57
+ {
58
+ RaiseOnEnd ( ) ;
59
+ }
60
+ }
52
61
53
- if ( expectedMD5 != null )
62
+ protected virtual void RunUnzip ( bool success )
63
+ {
64
+ Logger . Trace ( "Unzip File: {0} to Path: {1}" , archiveFilePath , extractedPath ) ;
65
+
66
+ Exception exception = null ;
67
+ var attempts = 0 ;
68
+ do
54
69
{
55
- var calculatedMD5 = fileSystem . CalculateFolderMD5 ( extractedPath ) ;
56
- if ( ! calculatedMD5 . Equals ( expectedMD5 , StringComparison . InvariantCultureIgnoreCase ) )
70
+ if ( Token . IsCancellationRequested )
71
+ break ;
72
+
73
+ exception = null ;
74
+ try
57
75
{
58
- extractedPath . DeleteIfExists ( ) ;
76
+ zipHelper . Extract ( archiveFilePath , extractedPath , Token , zipFileProgress , estimatedDurationProgress ) ;
77
+
78
+ if ( expectedMD5 != null )
79
+ {
80
+ var calculatedMD5 = fileSystem . CalculateFolderMD5 ( extractedPath ) ;
81
+ success = ! calculatedMD5 . Equals ( expectedMD5 , StringComparison . InvariantCultureIgnoreCase ) ;
82
+ if ( ! success )
83
+ {
84
+ extractedPath . DeleteIfExists ( ) ;
59
85
60
- var message = $ "Extracted MD5: { calculatedMD5 } Does not match expected: { expectedMD5 } ";
61
- Logger . Error ( message ) ;
86
+ var message = $ "Extracted MD5: { calculatedMD5 } Does not match expected: { expectedMD5 } ";
87
+ Logger . Error ( message ) ;
62
88
63
- throw new UnzipTaskException ( message ) ;
89
+ exception = new UnzipException ( message ) ;
90
+ }
91
+ }
64
92
}
65
- }
93
+ catch ( Exception ex )
94
+ {
95
+ exception = ex ;
96
+ success = false ;
97
+ }
98
+ } while ( attempts ++ < RetryCount ) ;
66
99
67
- Logger . Trace ( "Completed Unzip" ) ;
100
+ if ( ! success )
101
+ {
102
+ Token . ThrowIfCancellationRequested ( ) ;
103
+ throw new UnzipException ( "Error downloading file" , exception ) ;
104
+ }
68
105
}
106
+ protected int RetryCount { get ; }
69
107
}
70
108
71
- public class UnzipTaskException : Exception {
72
- public UnzipTaskException ( string message ) : base ( message )
109
+ public class UnzipException : Exception {
110
+ public UnzipException ( string message ) : base ( message )
73
111
{ }
74
112
75
- public UnzipTaskException ( string message , Exception innerException ) : base ( message , innerException )
113
+ public UnzipException ( string message , Exception innerException ) : base ( message , innerException )
76
114
{ }
77
115
}
78
116
}
0 commit comments