Initial commit
This commit is contained in:
42
PartSource.Automation/Services/EmailService.cs
Normal file
42
PartSource.Automation/Services/EmailService.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using PartSource.Automation.Models.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PartSource.Automation.Services
|
||||
{
|
||||
public class EmailService
|
||||
{
|
||||
private readonly EmailConfiguration _emailConfiguration;
|
||||
|
||||
public EmailService(EmailConfiguration emailConfiguration)
|
||||
{
|
||||
_emailConfiguration = emailConfiguration;
|
||||
}
|
||||
|
||||
public void Send(string subject, string body)
|
||||
{
|
||||
using (SmtpClient smtpClient = new SmtpClient { Host = _emailConfiguration.SmtpHost })
|
||||
{
|
||||
MailMessage mailMessage = new MailMessage
|
||||
{
|
||||
From = new MailAddress(_emailConfiguration.From),
|
||||
Subject = subject,
|
||||
Body = body,
|
||||
IsBodyHtml = true
|
||||
};
|
||||
|
||||
foreach (string address in _emailConfiguration.To.Split(','))
|
||||
{
|
||||
mailMessage.To.Add(address);
|
||||
}
|
||||
|
||||
smtpClient.Send(mailMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
PartSource.Automation/Services/FtpService.cs
Normal file
35
PartSource.Automation/Services/FtpService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using PartSource.Automation.Models.Configuration;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PartSource.Automation.Services
|
||||
{
|
||||
public class FtpService
|
||||
{
|
||||
private readonly FtpConfiguration _ftpConfiguration;
|
||||
|
||||
public FtpService(FtpConfiguration ftpConfiguration)
|
||||
{
|
||||
_ftpConfiguration = ftpConfiguration;
|
||||
}
|
||||
|
||||
public void Download(string filename)
|
||||
{
|
||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{_ftpConfiguration.Url}/{filename}");
|
||||
request.Credentials = new NetworkCredential(_ftpConfiguration.Username, _ftpConfiguration.Password);
|
||||
request.Method = WebRequestMethods.Ftp.DownloadFile;
|
||||
|
||||
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
|
||||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
using (FileStream fileStream = new FileStream($"{_ftpConfiguration.Destination}\\{filename}", FileMode.Create))
|
||||
{
|
||||
responseStream.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
66
PartSource.Automation/Services/SsisService.cs
Normal file
66
PartSource.Automation/Services/SsisService.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PartSource.Automation.Models.Configuration;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PartSource.Automation.Services
|
||||
{
|
||||
public class SsisService
|
||||
{
|
||||
private readonly SsisConfiguration _ssisConfiguration;
|
||||
|
||||
public SsisService(SsisConfiguration ssisConfiguration)
|
||||
{
|
||||
_ssisConfiguration = ssisConfiguration;
|
||||
}
|
||||
|
||||
public bool Execute(string packageName)
|
||||
{
|
||||
try
|
||||
{
|
||||
using Process process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "dtexec",
|
||||
Arguments = $"/file \"{_ssisConfiguration.Directory}\\{packageName}\"",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
process.Start();
|
||||
|
||||
//process.WaitForExit();
|
||||
|
||||
string stdout = process.StandardOutput.ReadToEnd();
|
||||
string stderr = process.StandardError.ReadToEnd();
|
||||
|
||||
Console.WriteLine(stdout);
|
||||
Console.WriteLine(stderr);
|
||||
|
||||
// Application application = new Application();
|
||||
//Package package = application.LoadPackage($"{_ssisConfiguration.Directory}\\{packageName}", null);
|
||||
|
||||
//DTSExecResult result = package.Execute();
|
||||
|
||||
return true; //result == DTSExecResult.Success;
|
||||
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
141
PartSource.Automation/Services/VehicleCacheService.cs
Normal file
141
PartSource.Automation/Services/VehicleCacheService.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using PartSource.Automation.Models.Cache;
|
||||
using PartSource.Data.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PartSource.Automation.Services
|
||||
{
|
||||
public class VehicleCacheService
|
||||
{
|
||||
private readonly ConcurrentBag<VehicleCacheItem> _vehicleCache;
|
||||
private readonly ConcurrentBag<BaseVehicle> _sorryNotCanadianCache;
|
||||
|
||||
private readonly NexpartService _nexpartService;
|
||||
|
||||
public VehicleCacheService(NexpartService nexpartService)
|
||||
{
|
||||
_vehicleCache = new ConcurrentBag<VehicleCacheItem>();
|
||||
_sorryNotCanadianCache = new ConcurrentBag<BaseVehicle>();
|
||||
|
||||
_nexpartService = nexpartService;
|
||||
}
|
||||
|
||||
public VehicleCacheItem Get(int baseVehicleId, int engineConfigId)
|
||||
{
|
||||
return _vehicleCache.FirstOrDefault(v => v.BaseVehicle.BaseVehicleId == baseVehicleId && v.BaseVehicle.EngineConfigId == engineConfigId);
|
||||
}
|
||||
|
||||
public void Add(VehicleCacheItem vehicle)
|
||||
{
|
||||
_vehicleCache.Add(vehicle);
|
||||
}
|
||||
|
||||
public bool TryAdd(int baseVehicleId, int engineConfigId)
|
||||
{
|
||||
BaseVehicle sorryNotCanadian = _sorryNotCanadianCache.FirstOrDefault(b => b.BaseVehicleId == baseVehicleId && b.EngineConfigId == engineConfigId);
|
||||
if (sorryNotCanadian != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
VehicleIdSearch vehicleIdSearch = new VehicleIdSearch
|
||||
{
|
||||
VehicleIdentifier = new VehicleIdentifier
|
||||
{
|
||||
BaseVehicleId = baseVehicleId,
|
||||
EngineConfigId = engineConfigId
|
||||
},
|
||||
ResultOption = new ResultOption[2]
|
||||
{
|
||||
new ResultOption { Value = "BASE_VEHICLE" },
|
||||
new ResultOption { Value = "BASE_VEHICLE_DESC" }
|
||||
},
|
||||
RegionId = new RegionId
|
||||
{
|
||||
Value = 2
|
||||
}
|
||||
};
|
||||
|
||||
VehicleIdSearchResponse response = _nexpartService.SendRequest<VehicleIdSearch, VehicleIdSearchResponse>(vehicleIdSearch).Result;
|
||||
if (response.ResponseBody?.BaseVehicle == null)
|
||||
{
|
||||
BaseVehicle vehicle = new BaseVehicle
|
||||
{
|
||||
BaseVehicleId = baseVehicleId,
|
||||
EngineConfigId = engineConfigId
|
||||
};
|
||||
|
||||
_sorryNotCanadianCache.Add(vehicle);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
BaseVehicle baseVehicle = response.ResponseBody.BaseVehicle;
|
||||
baseVehicle.EngineConfigId = engineConfigId;
|
||||
|
||||
SubModelSearch smSearch = new SubModelSearch()
|
||||
{
|
||||
MakeId = baseVehicle.MakeId,
|
||||
ModelId = baseVehicle.ModelId,
|
||||
Year = baseVehicle.Year,
|
||||
RegionId = 2
|
||||
};
|
||||
SubModelSearchResponse smResponse = _nexpartService.SendRequest<SubModelSearch, SubModelSearchResponse>(smSearch).Result;
|
||||
|
||||
SubModel[] subModels = smResponse.ResponseBody?.SubModel;
|
||||
if (subModels == null)
|
||||
{
|
||||
_sorryNotCanadianCache.Add(baseVehicle);
|
||||
return false;
|
||||
}
|
||||
|
||||
IList<int> vehicleIds = new List<int>();
|
||||
|
||||
foreach (SubModel submodel in subModels)
|
||||
{
|
||||
VehicleIdSearch vidSearch = new VehicleIdSearch
|
||||
{
|
||||
VehicleIdentifier = new VehicleIdentifier()
|
||||
{
|
||||
BaseVehicleId = baseVehicle.BaseVehicleId,
|
||||
EngineConfigId = baseVehicle.EngineConfigId
|
||||
},
|
||||
Criterion = new Criterion[1]
|
||||
{
|
||||
new Criterion
|
||||
{
|
||||
Attribute = "SUB_MODEL",
|
||||
Id = int.Parse(submodel.Id)
|
||||
}
|
||||
},
|
||||
RegionId = new RegionId
|
||||
{
|
||||
Value = 2
|
||||
},
|
||||
};
|
||||
|
||||
VehicleIdSearchResponse vidResponse = _nexpartService.SendRequest<VehicleIdSearch, VehicleIdSearchResponse>(vidSearch).Result;
|
||||
|
||||
int? vehicleId = vidResponse.ResponseBody?.VehicleToEngineConfigId;
|
||||
if (vehicleId != null && vehicleId > 0)
|
||||
{
|
||||
vehicleIds.Add((int)vehicleId);
|
||||
}
|
||||
}
|
||||
|
||||
VehicleCacheItem cacheItem = new VehicleCacheItem
|
||||
{
|
||||
BaseVehicle = baseVehicle,
|
||||
VehicleIds = vehicleIds
|
||||
};
|
||||
|
||||
_vehicleCache.Add(cacheItem);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user