1- using System . IO ;
1+ using System ;
2+ using System . IO ;
23using TicTacTubeCore . Processors . Definitions ;
34using TicTacTubeCore . Sources . Files ;
45
@@ -9,6 +10,7 @@ namespace TicTacTubeCore.Processors.Filesystem
910 /// </summary>
1011 public class SourceMover : BaseDataProcessor
1112 {
13+ private readonly Func < IFileSource , string > _processingFunction ;
1214 private readonly string _destinationPath ;
1315 private readonly bool _keepName ;
1416
@@ -33,16 +35,35 @@ public SourceMover(string destinationFolder, bool keepName)
3335 _keepName = true ;
3436 }
3537
38+ /// <summary>
39+ /// Create a source mover that moves a source to another directory. The full
40+ /// path to the new file is created by the processing function.
41+ /// </summary>
42+ /// <param name="processingFunction">The processing function returns for a given <see cref="IFileSource"/>
43+ /// a full path to the new file.
44+ /// </param>
45+ public SourceMover ( Func < IFileSource , string > processingFunction )
46+ {
47+ _processingFunction = processingFunction ?? throw new ArgumentNullException ( nameof ( processingFunction ) ) ;
48+ }
49+
3650 /// <inheritdoc />
3751 public override IFileSource Execute ( IFileSource fileSoure )
3852 {
39- string dest = _keepName ? Path . Combine ( _destinationPath , fileSoure . FileInfo . Name ) : _destinationPath ;
53+ string dest = _destinationPath ;
54+
55+ if ( _processingFunction != null )
56+ {
57+ dest = _processingFunction ( fileSoure ) ;
58+ }
59+ else if ( _keepName )
60+ {
61+ dest = Path . Combine ( _destinationPath , fileSoure . FileInfo . Name ) ;
62+ }
4063
4164 string directory = Path . GetDirectoryName ( dest ) ;
4265 if ( ! Directory . Exists ( directory ) )
43- {
4466 Directory . CreateDirectory ( directory ) ;
45- }
4667
4768 fileSoure . FileInfo . MoveTo ( dest ) ;
4869
0 commit comments