Skip to content

Commit 9a4b704

Browse files
committed
Fixing issues with tracking last scan
1 parent d30042a commit 9a4b704

18 files changed

Lines changed: 85 additions & 53 deletions

src/Wikiled.YiScanner.Tests/Client/VideoHeaderExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class VideoHeaderExtensionsTests
1414
[TestCase(@"c:\Dir2\Dir\file", @"c:\out\Camera\Dir\file")]
1515
public void GetPath(string fileName, string expected)
1616
{
17-
VideoHeader header = new VideoHeader(new HostInformation("Camera", IPAddress.Any), fileName);
17+
VideoHeader header = new VideoHeader(new Host("Camera", IPAddress.Any), fileName);
1818
var result = header.GetPath(@"c:\out");
1919
Assert.AreEqual(expected, result);
2020
}

src/Wikiled.YiScanner.Tests/Client/VideoHeaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace Wikiled.YiScanner.Tests.Client
99
[TestFixture]
1010
public class VideoHeaderTests
1111
{
12-
private HostInformation cameraDescription;
12+
private Host cameraDescription;
1313

1414
private VideoHeader instance;
1515

1616
[SetUp]
1717
public void Setup()
1818
{
19-
cameraDescription = new HostInformation("Test", IPAddress.None);
19+
cameraDescription = new Host("Test", IPAddress.None);
2020
instance = CreateVideoHeader();
2121
}
2222

src/Wikiled.YiScanner.Tests/Destinations/ChainedActionDestinationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ChainedActionDestinationTests
2626
[SetUp]
2727
public void SetUp()
2828
{
29-
header = new VideoHeader(new HostInformation("Camera", IPAddress.Any), "test.mov");
29+
header = new VideoHeader(new Host("Camera", IPAddress.Any), "test.mov");
3030
mockDestination = new Mock<IDestination>();
3131
mockAction = new Mock<IPriorAction>();
3232
stream = new Mock<Stream>();

src/Wikiled.YiScanner.Tests/Destinations/ChainedPostActionDestinationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ChainedPostActionDestinationTests
2626
[SetUp]
2727
public void SetUp()
2828
{
29-
header = new VideoHeader(new HostInformation("Camera", IPAddress.Any), "test.mov");
29+
header = new VideoHeader(new Host("Camera", IPAddress.Any), "test.mov");
3030
stream = new Mock<Stream>();
3131
mockDestination = new Mock<IDestination>();
3232
mockPostAction = new Mock<IPostAction>();

src/Wikiled.YiScanner.Tests/Destinations/CompressedDestinationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void Setup()
3434
public async Task Transfer()
3535
{
3636
Assert.IsFalse(File.Exists(outFile));
37-
VideoHeader header = new VideoHeader(new HostInformation("Camera", IPAddress.Any), "test.txt");
37+
VideoHeader header = new VideoHeader(new Host("Camera", IPAddress.Any), "test.txt");
3838
using (StreamReader reader = new StreamReader(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "Test.txt")))
3939
{
4040
await instance.Transfer(header, reader.BaseStream).ConfigureAwait(false);

src/Wikiled.YiScanner.Tests/Destinations/FileDestinationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class FileDestinationTests
2323
[SetUp]
2424
public void SetUp()
2525
{
26-
header = new VideoHeader(new HostInformation("Camera", IPAddress.Any), "test.mov");
26+
header = new VideoHeader(new Host("Camera", IPAddress.Any), "test.mov");
2727
outPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Out");
2828
if (Directory.Exists(outPath))
2929
{

src/Wikiled.YiScanner.Tests/Destinations/PictureFileDestinationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void SetUp()
2929
Directory.Delete(outPath, true);
3030
}
3131

32-
header = new VideoHeader(new HostInformation("Camera", IPAddress.Any), "test.mov");
32+
header = new VideoHeader(new Host("Camera", IPAddress.Any), "test.mov");
3333
instance = CreatePictureFileDestination();
3434
stream = File.OpenRead(Path.Combine(TestContext.CurrentContext.TestDirectory, "data", "centaur_1.mpg"));
3535
}

src/Wikiled.YiScanner.Tests/Destinations/TransformedDestinationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class TransformedDestinationTests
2626
[SetUp]
2727
public void SetUp()
2828
{
29-
header = new VideoHeader(new HostInformation("Test", IPAddress.Any), "test.mov");
29+
header = new VideoHeader(new Host("Test", IPAddress.Any), "test.mov");
3030
mockDestination = new Mock<IDestination>();
3131
renameFunc = name => "test";
3232
stream = new Mock<Stream>();

src/YiScanner/Client/FtpDownloader.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

src/YiScanner/Client/VideoHeader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace Wikiled.YiScanner.Client
55
{
66
public class VideoHeader
77
{
8-
public VideoHeader(HostInformation camera, string fileName)
8+
public VideoHeader(Host camera, string fileName)
99
{
1010
Guard.NotNull(() => camera, camera);
1111
Guard.NotNullOrEmpty(() => fileName, fileName);
1212
Camera = camera;
1313
FileName = fileName;
1414
}
1515

16-
public HostInformation Camera { get; }
16+
public Host Camera { get; }
1717

1818
public string FileName { get; }
1919
}

0 commit comments

Comments
 (0)