67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using LCU.API.Collections.RepoApi.Configuration;
|
|
using Serilog;
|
|
|
|
namespace LCU.API.Collections.RepoApi.Services.AutoIms
|
|
{
|
|
public class AutoImsDownloaderService : IAutoImsDownloaderService
|
|
{
|
|
private readonly RepoApiConfiguration _configuration;
|
|
private readonly IAuctionFtpClientService _auctionFtpClientService;
|
|
|
|
public AutoImsDownloaderService(IAuctionFtpClientService auctionFtpClientService,
|
|
RepoApiConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
_auctionFtpClientService = auctionFtpClientService;
|
|
}
|
|
|
|
public Dictionary<FileInfo, string> DownLoadAuctionFiles()
|
|
{
|
|
var fileResults = _auctionFtpClientService.Download();
|
|
return fileResults;
|
|
}
|
|
|
|
public Dictionary<FileInfo, string> CombineWithLocalFiles(Dictionary<FileInfo, string> fileResults)
|
|
{
|
|
// check if there are any files in the folder already that are not in our downloaded list.
|
|
string[] fileEntries = Directory.GetFiles(_configuration.LocalDirectoryPath);
|
|
|
|
foreach (string file in fileEntries)
|
|
{
|
|
var newFile = new FileInfo(file);
|
|
Log.Information($"Auto IMS Job Added file: {file}");
|
|
|
|
if (fileResults.Keys.All(x => x.Name != newFile.Name))
|
|
{
|
|
fileResults.Add(newFile, "success");
|
|
}
|
|
}
|
|
|
|
return fileResults;
|
|
}
|
|
|
|
public IEnumerable<FileInfo> ConvertToFileList(Dictionary<FileInfo, string> fileResults)
|
|
{
|
|
if (fileResults.Any(x => x.Value != "success"))
|
|
{
|
|
foreach (var file in fileResults.Where(x => x.Value != "success"))
|
|
{
|
|
Log.Information($"File Downloads failed: {file.Key} - {file.Value}");
|
|
}
|
|
}
|
|
|
|
if (fileResults.Any(x => x.Value == "success"))
|
|
{
|
|
var ascendingOrderOfFiles = fileResults.Where(x => x.Value == "success")
|
|
.OrderBy(x => x.Key.LastWriteTime).Select(x => x.Key).ToList();
|
|
return ascendingOrderOfFiles;
|
|
}
|
|
|
|
Log.Information("No files found from AutoIMS.");
|
|
return new List<FileInfo>();
|
|
}
|
|
}
|
|
} |