2
2
using System . Threading ;
3
3
using Paillave . Etl . Core ;
4
4
5
- namespace Paillave . Etl . Zip
5
+ namespace Paillave . Etl . Zip ;
6
+
7
+ public class ZipAdapterConnectionParameters
6
8
{
7
- public class ZipAdapterConnectionParameters
8
- {
9
- public string Password { get ; set ; }
10
- }
11
- public class ZipAdapterProcessorParameters
12
- {
13
- public string FileNamePattern { get ; set ; }
14
- }
15
- public class ZipProviderProcessorAdapter : ProviderProcessorAdapterBase < ZipAdapterConnectionParameters , object , ZipAdapterProcessorParameters >
16
- {
17
- public override string Description => "Handle zip files" ;
18
- public override string Name => "Zip" ;
19
- protected override IFileValueProvider CreateProvider ( string code , string name , string connectionName , ZipAdapterConnectionParameters connectionParameters , object inputParameters )
20
- => null ;
21
- protected override IFileValueProcessor CreateProcessor ( string code , string name , string connectionName , ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters outputParameters )
22
- => new ZipFileValueProcessor ( code , name , connectionName , connectionParameters , outputParameters ) ;
23
- }
24
- public class ZipFileValueProcessor : FileValueProcessorBase < ZipAdapterConnectionParameters , ZipAdapterProcessorParameters >
9
+ public string Password { get ; set ; }
10
+ }
11
+ public enum ZipDirection
12
+ {
13
+ Unzip ,
14
+ Zip
15
+ }
16
+ public class ZipAdapterProcessorParameters
17
+ {
18
+ public ZipDirection Direction { get ; set ; } = ZipDirection . Unzip ;
19
+ public string FileNamePattern { get ; set ; }
20
+ }
21
+ public class ZipProviderProcessorAdapter : ProviderProcessorAdapterBase < ZipAdapterConnectionParameters , object , ZipAdapterProcessorParameters >
22
+ {
23
+ public override string Description => "Handle zip files" ;
24
+ public override string Name => "Zip" ;
25
+ protected override IFileValueProvider CreateProvider ( string code , string name , string connectionName , ZipAdapterConnectionParameters connectionParameters , object inputParameters )
26
+ => null ;
27
+ protected override IFileValueProcessor CreateProcessor ( string code , string name , string connectionName , ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters outputParameters )
28
+ => new ZipFileValueProcessor ( code , name , connectionName , connectionParameters , outputParameters ) ;
29
+ }
30
+ public class ZipFileValueProcessor : FileValueProcessorBase < ZipAdapterConnectionParameters , ZipAdapterProcessorParameters >
31
+ {
32
+ public ZipFileValueProcessor ( string code , string name , string connectionName , ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters processorParameters )
33
+ : base ( code , name , connectionName , connectionParameters , processorParameters ) { }
34
+ public override ProcessImpact PerformanceImpact => ProcessImpact . Heavy ;
35
+ public override ProcessImpact MemoryFootPrint => ProcessImpact . Average ;
36
+ protected override void Process ( IFileValue fileValue , ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters processorParameters , Action < IFileValue > push , CancellationToken cancellationToken , IExecutionContext context )
25
37
{
26
- public ZipFileValueProcessor ( string code , string name , string connectionName , ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters processorParameters )
27
- : base ( code , name , connectionName , connectionParameters , processorParameters ) { }
28
- public override ProcessImpact PerformanceImpact => ProcessImpact . Heavy ;
29
- public override ProcessImpact MemoryFootPrint => ProcessImpact . Average ;
30
- protected override void Process ( IFileValue fileValue , ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters processorParameters , Action < IFileValue > push , CancellationToken cancellationToken , IExecutionContext context )
38
+ switch ( processorParameters . Direction )
31
39
{
32
- new UnzipFileProcessorValuesProvider ( new UnzipFileProcessorParams
33
- {
34
- FileNamePattern = processorParameters . FileNamePattern ,
35
- Password = connectionParameters . Password
36
- } ) . PushValues ( fileValue , push , cancellationToken , context ) ;
40
+ case ZipDirection . Unzip :
41
+ new UnzipFileProcessorValuesProvider ( new UnzipFileProcessorParams
42
+ {
43
+ FileNamePattern = processorParameters . FileNamePattern ,
44
+ Password = connectionParameters . Password
45
+ } ) . PushValues ( fileValue , push , cancellationToken , context ) ;
46
+ break ;
47
+ case ZipDirection . Zip :
48
+ new ZipFileProcessorValuesProvider ( new ZipFileProcessorParams
49
+ {
50
+ Password = connectionParameters . Password
51
+ } ) . PushValues ( fileValue , push , cancellationToken , context ) ;
52
+ break ;
37
53
}
38
-
39
- protected override void Test ( ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters processorParameters ) { }
40
54
}
41
- }
55
+
56
+ protected override void Test ( ZipAdapterConnectionParameters connectionParameters , ZipAdapterProcessorParameters processorParameters ) { }
57
+ }
0 commit comments