Current state, whatever that means

This commit is contained in:
2022-03-17 20:04:12 -04:00
parent fb6dbdfaa7
commit 60edbee0b8
22 changed files with 1087 additions and 156 deletions

View File

@@ -3,6 +3,7 @@ using PartSource.Automation.Models.Configuration;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text;
@@ -19,7 +20,7 @@ namespace PartSource.Automation.Services
_emailConfiguration = configuration.GetSection("emailConfiguration").Get<EmailConfiguration>();
}
public void Send(string subject, string body)
public void Send(string subject, string body, Attachment attachment = null)
{
using SmtpClient smtpClient = new SmtpClient
{
@@ -31,15 +32,20 @@ namespace PartSource.Automation.Services
From = new MailAddress(_emailConfiguration.From),
Subject = subject,
Body = body,
IsBodyHtml = true
IsBodyHtml = true,
};
if (attachment != null)
{
mailMessage.Attachments.Add(attachment);
}
foreach (string address in _emailConfiguration.To.Split(','))
{
mailMessage.To.Add(address);
}
// smtpClient.Send(mailMessage);
smtpClient.Send(mailMessage);
}
public void Send(string to, string subject, string body)
@@ -54,7 +60,7 @@ namespace PartSource.Automation.Services
From = new MailAddress(_emailConfiguration.From),
Subject = subject,
Body = body,
IsBodyHtml = false
IsBodyHtml = false,
};
foreach (string address in _emailConfiguration.To.Split(','))
@@ -62,7 +68,7 @@ namespace PartSource.Automation.Services
mailMessage.To.Add(to);
}
// smtpClient.Send(mailMessage);
smtpClient.Send(mailMessage);
}
}
}

View File

@@ -41,7 +41,7 @@ namespace PartSource.Automation.Services
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri($"{_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.Replace("/", "\\")}", FileMode.Create);

View File

@@ -35,7 +35,7 @@ namespace PartSource.Automation.Services
foreach (string file in files)
{
if (file.EndsWith("csv.gz"))
if (file.Contains(".csv"))
{
try
{
@@ -53,7 +53,16 @@ namespace PartSource.Automation.Services
}
}
public void Truncate()
public void TruncateVehicleTable()
{
using SqlConnection connection = new SqlConnection(_connectionString);
connection.Open();
using SqlCommand command = new SqlCommand($"truncate table dbo.Vehicle", connection);
command.ExecuteNonQuery();
}
public void TruncateFitmentTables()
{
using SqlConnection connection = new SqlConnection(_connectionString);
connection.Open();
@@ -62,11 +71,36 @@ namespace PartSource.Automation.Services
command.ExecuteNonQuery();
}
public void BulkCopy(SeoDataType seoDataType, DataTable dataTable, string tableName)
public void SaveNotes(IDictionary<string, string> notes)
{
using DataTable dataTable = new DataTable();
dataTable.Columns.Add("NoteText", typeof(string));
dataTable.Columns.Add("Hash", typeof(string));
foreach (KeyValuePair<string, string> note in notes)
{
dataTable.Rows.Add(new string[] { note.Value, note.Key });
}
using SqlConnection connection = new SqlConnection(_connectionString);
connection.Open();
using SqlBulkCopy bulk = new SqlBulkCopy(connection)
{
DestinationTableName = $"FitmentNote",
BulkCopyTimeout = 14400
};
bulk.WriteToServer(dataTable);
}
public void BulkCopyFitment(DataTable dataTable, string tableName)
{
using SqlConnection connection = new SqlConnection(_connectionString);
connection.Open();
string sql = string.Empty;
using SqlCommand command = new SqlCommand($"EXEC CreateFitmentTempTable @tableName = '{tableName}'", connection);
command.ExecuteNonQuery();
@@ -74,6 +108,25 @@ namespace PartSource.Automation.Services
using SqlBulkCopy bulk = new SqlBulkCopy(connection)
{
DestinationTableName = $"FitmentTemp.{tableName}",
BulkCopyTimeout = 1
};
bulk.WriteToServer(dataTable);
}
public void BulkCopyVehicle(DataTable dataTable, string tableName)
{
using SqlConnection connection = new SqlConnection(_connectionString);
connection.Open();
string sql = string.Empty;
using SqlCommand command = new SqlCommand($"EXEC CreateVehicleTempTable @tableName = '{tableName}'", connection);
command.ExecuteNonQuery();
using SqlBulkCopy bulk = new SqlBulkCopy(connection)
{
DestinationTableName = $"VehicleTemp.{tableName}",
BulkCopyTimeout = 14400
};
@@ -97,6 +150,21 @@ namespace PartSource.Automation.Services
using SqlCommand command = new SqlCommand($"exec CreateFitmentView", connection);
command.ExecuteNonQuery();
using SqlCommand command2 = new SqlCommand($"exec CreateFitmentIndexes", connection);
command2.ExecuteNonQuery();
}
public void CreateVehicleTable()
{
return;
using SqlConnection connection = new SqlConnection(_connectionString);
connection.Open();
using SqlCommand command = new SqlCommand($"exec CreateVehicleTable", connection);
command.CommandTimeout = 1800;
command.ExecuteNonQuery();
}
}
}