@@ -16,52 +16,44 @@ public class FtpDownloader : IFtpDownloader
1616 {
1717 private static readonly Logger log = LogManager . GetCurrentClassLogger ( ) ;
1818
19- private readonly HostInformation camera ;
20-
21- private readonly FtpConfig config ;
19+ private readonly HostTracking tracking ;
2220
2321 private readonly IDestination destination ;
2422
2523 private readonly Regex maskRegex ;
2624
2725 private readonly IPredicate predicate ;
2826
29- private DateTime ? lastScan ;
30-
3127 public FtpDownloader (
32- FtpConfig config ,
33- HostInformation camera ,
28+ HostTracking tracking ,
3429 IDestination destination ,
3530 IPredicate predicate )
3631 {
37- Guard . NotNull ( ( ) => config , config ) ;
38- Guard . NotNull ( ( ) => camera , camera ) ;
32+ Guard . NotNull ( ( ) => tracking , tracking ) ;
3933 Guard . NotNull ( ( ) => destination , destination ) ;
4034 Guard . NotNull ( ( ) => predicate , predicate ) ;
41- maskRegex = FileMask . GenerateFitMask ( config . FileMask ) ;
35+ maskRegex = FileMask . GenerateFitMask ( tracking . Config . FileMask ) ;
4236 log . Debug ( "Generated mask: {0}" , maskRegex ) ;
43- this . camera = camera ;
37+ this . tracking = tracking ;
4438 this . destination = destination ;
4539 this . predicate = predicate ;
46- this . config = config ;
4740 }
4841
4942 public async Task < DateTime > Download ( )
5043 {
5144 // Get the object used to communicate with the server.
52- using ( var client = new FtpClient ( camera . Address . ToString ( ) ) )
45+ using ( var client = new FtpClient ( tracking . Host . Address . ToString ( ) ) )
5346 {
54- log . Info ( "Connecting: {0}" , camera . Address ) ;
47+ log . Info ( "Connecting: {0}" , tracking . Host . Address ) ;
5548 client . Credentials = new NetworkCredential (
56- config . Login ,
57- config . Password ) ;
49+ tracking . Config . Login ,
50+ tracking . Config . Password ) ;
5851 client . Connect ( ) ;
59- log . Info ( "Connected: {0}!" , camera . Address ) ;
60- await Retrieve ( client , config . Path ) . ConfigureAwait ( false ) ;
52+ log . Info ( "Connected: {0}!" , tracking . Host . Address ) ;
53+ await Retrieve ( client , tracking . Config . Path ) . ConfigureAwait ( false ) ;
6154 }
6255
63- var now = DateTime . Now ;
64- lastScan = now ;
56+ var now = tracking . Scanned ( ) ;
6557 return now ;
6658 }
6759
@@ -70,10 +62,10 @@ private async Task ProcessFile(FtpClient client, FtpListItem item)
7062 Stream stream = null ;
7163 try
7264 {
73- var header = new VideoHeader ( camera , item . FullName ) ;
65+ var header = new VideoHeader ( tracking . Host , item . FullName ) ;
7466 if ( ! destination . IsDownloaded ( header ) )
7567 {
76- log . Info ( "Downloading <{0}> from [{1}]" , item . FullName , camera . Name ) ;
68+ log . Info ( "Downloading <{0}> from [{1}]" , item . FullName , tracking . Host . Name ) ;
7769 stream = await client . OpenReadAsync ( item . FullName ) . ConfigureAwait ( false ) ;
7870 await destination . Transfer ( header , stream ) . ConfigureAwait ( false ) ;
7971 var reply = await client . GetReplyAsync ( ) . ConfigureAwait ( false ) ;
@@ -85,7 +77,7 @@ private async Task ProcessFile(FtpClient client, FtpListItem item)
8577 reply . Message ,
8678 reply . Type ,
8779 reply . Code ,
88- camera . Name ) ;
80+ tracking . Host . Name ) ;
8981 }
9082 else
9183 {
@@ -94,12 +86,12 @@ private async Task ProcessFile(FtpClient client, FtpListItem item)
9486 reply . ErrorMessage ,
9587 reply . Type ,
9688 reply . Code ,
97- camera . Name ) ;
89+ tracking . Host . Name ) ;
9890 }
9991 }
10092 else
10193 {
102- log . Info ( "File is already downloaded - <{0}> {1}" , item . FullName , camera . Name ) ;
94+ log . Info ( "File is already downloaded - <{0}> {1}" , item . FullName , tracking . Host . Name ) ;
10395 }
10496 }
10597 catch ( Exception ex )
@@ -119,7 +111,7 @@ private async Task Retrieve(FtpClient client, string path)
119111 if ( item . Type == FtpFileSystemObjectType . File )
120112 {
121113 if ( maskRegex . IsMatch ( item . FullName ) &&
122- predicate . CanDownload ( lastScan , item . FullName , item . Modified ) )
114+ predicate . CanDownload ( tracking . LastScanned , item . FullName , item . Modified ) )
123115 {
124116 if ( item . Modified < DateTime . Now . AddMinutes ( 1 ) )
125117 {
0 commit comments