Merge remote-tracking branch 'upstream/master'

net6.0
Don Oerkfitz 3 years ago
commit d900d15c91

@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
<PackageReference Include="System.Console" Version="4.3.1" />
<PackageReference Include="TextCopy" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Library\Common.Library.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Text;
using Common.Library.SQL.MySQL;
using Microsoft.Extensions.Configuration;
using Common.Library.ImageHandling;
using Common.Library.Settings;
using MySql.Data.MySqlClient;
namespace Common.Library.Console.Image.Uploader
{
public class ImageUploader : MySQL
{
private readonly string _patoToImage;
public ImageUploader(string pathToImage) : base(SettingsLoader.DBHost, SettingsLoader.DBName, SettingsLoader.DBUserName, SettingsLoader.DBPassword)
{
_patoToImage = pathToImage;
}
public void UploadImage(int testimonialID)
{
ImageHandler imageHandler = new ImageHandler();
KeyValuePair<string, byte[]> imageData = imageHandler.ConvertImageFromFile(_patoToImage);
InitConnection();
try
{
DBCommand.CommandType = CommandType.StoredProcedure;
DBCommand.CommandText = "Testimonial_Images_Insert";
DBCommand.Parameters.AddWithValue("@testimonialID", testimonialID);
DBCommand.Parameters.AddWithValue("@imageType", imageData.Key);
//DBCommand.Parameters.AddWithValue("@imageData", imageData.Value);
MySqlParameter image = new MySqlParameter("@imageData", MySqlDbType.MediumBlob, imageData.Value.Length);
image.Value = imageData.Value;
DBCommand.Parameters.Add(image);
DBCommand.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
DisposeConnection();
}
}
}
}

@ -0,0 +1,34 @@
using Microsoft.Extensions.Configuration;
using Common.Library.Settings;
namespace Common.Library.Console.Image.Uploader
{
class Program
{
static void Main(string[] args)
{
SettingsLoader.Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
.Build();
System.Console.Write("Path to Image for Uploading: ");
string pathToFile = System.Console.ReadLine().Replace("\"", string.Empty).Trim();
System.Console.WriteLine();
System.Console.Write("TestimonialID to tie image to: ");
if(int.TryParse(System.Console.ReadLine().Trim(), out int testimonialID) == false)
{
throw new System.Exception("Cannot parse TestimonalID - it is not a number");
}
ImageUploader uploader = new ImageUploader(pathToFile);
uploader.UploadImage(testimonialID);
System.Console.WriteLine("Complete");
System.Console.ReadKey();
}
}
}

@ -0,0 +1,16 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Database": {
"DBName": "dmcdynamics",
"Host": "10.0.3.6",
"Password": "Iu5I03ZDYjtYtqfD",
"UserName": "dmcdynamics"
}
}

@ -30,7 +30,6 @@ namespace Common.Library.DataLayer.DAO.Websites.DMCDynamics.LLC
DBCommand.Parameters.Add(new MySqlParameter("GUID", MySqlDbType.VarChar, 255, ParameterDirection.Input, false, 0, 0, string.Empty, DataRowVersion.Proposed, guid));
DBCommand.Parameters.Add(new MySqlParameter("IsValid", MySqlDbType.Bit, 1, ParameterDirection.InputOutput, false, 0, 0, string.Empty, DataRowVersion.Proposed, isValid));
DBCommand.ExecuteNonQuery();
isValid = Convert.ToBoolean(DBCommand.Parameters["IsValid"].Value);

@ -8,10 +8,9 @@ namespace Common.Library.DataLayer.DAO.Websites.DMCDynamics.LLC
{
public class TestimonialImagesDAO : MySQL
{
public TestimonialImagesDAO(string server, string database, string username, string password) : base(server, database, username, password)
{
public TestimonialImagesDAO(string server, string database, string username, string password) : base(server, database, username, password) { }
}
public TestimonialImagesDAO(DBConnectionInformation dBConnectionInformation) : base(dBConnectionInformation) { }
public TestimonialImagesDTO SelectOne(int testimonialID)
{

@ -9,10 +9,9 @@ namespace Common.Library.DataLayer.DAO.Websites.DMCDynamics.LLC
{
public class TestimonialsDAO : MySQL
{
public TestimonialsDAO(string server, string database, string username, string password) : base(server, database, username, password)
{
public TestimonialsDAO(string server, string database, string username, string password) : base(server, database, username, password) { }
}
public TestimonialsDAO(DBConnectionInformation dBConnectionInformation) : base(dBConnectionInformation) { }
public TestimonialsDTOCollection SelectAll()
{
@ -65,7 +64,13 @@ namespace Common.Library.DataLayer.DAO.Websites.DMCDynamics.LLC
DBCommand.CommandText = "Testimonials_Insert";
//> Add parameters
DBCommand.Parameters.Add(GetParameter("companyName", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanyName));
DBCommand.Parameters.Add(GetParameter("companySpokesPerson", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanySpokesPerson));
DBCommand.Parameters.Add(GetParameter("companyTitle", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanyTitle));
DBCommand.Parameters.Add(GetParameter("testimonialText", MySqlDbType.Text, 65535, ParameterDirection.Input, testimonial.Testimonial));
DBCommand.Parameters.Add(GetParameter("companyWebsite", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanyWebsite));
DBCommand.Parameters.Add(GetParameter("testimonialGUID", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.TestimonialGUID));
DBCommand.Parameters.Add(GetParameter("testimonialID", MySqlDbType.Int32, 0, ParameterDirection.Output, testimonial.TestimonialID));
DBCommand.ExecuteNonQuery();

@ -89,20 +89,22 @@ namespace Common.Library.SQL.MySQL
if (!DBReader.IsDBNull(columnID))
{
const int CHUNK_SIZE = 2 * 1024;
byte[] buffer = new byte[CHUNK_SIZE];
long bytesRead;
long fieldOffset = 0;
// const int CHUNK_SIZE = 2 * 1024;
// byte[] buffer = new byte[CHUNK_SIZE];
// long bytesRead;
// long fieldOffset = 0;
using (var stream = new MemoryStream())
{
while ((bytesRead = DBReader.GetBytes(columnID, fieldOffset, buffer, 0, buffer.Length)) == buffer.Length)
{
stream.Write(buffer, 0, (int)bytesRead);
fieldOffset += bytesRead;
}
rv = stream.ToArray();
}
// using (var stream = new MemoryStream())
// {
// while ((bytesRead = DBReader.GetBytes(columnID, fieldOffset, buffer, 0, buffer.Length)) == buffer.Length)
// {
// stream.Write(buffer, 0, (int)bytesRead);
// fieldOffset += bytesRead;
// }
// rv = stream.ToArray();
// }
rv = (byte[])DBReader[columnID];
}
return rv;
@ -214,5 +216,17 @@ namespace Common.Library.SQL.MySQL
{
return GetDateTime(GetOrdinal(columnName));
}
//new MySqlParameter("GUID", MySqlDbType.VarChar, 255, ParameterDirection.Input, false, 0, 0, string.Empty, DataRowVersion.Proposed, guid)
protected MySqlParameter GetParameter(string columnName, MySqlDbType dataType, ParameterDirection direction, object data)
{
return null;
}
protected MySqlParameter GetParameter(string columnName, MySqlDbType dataType, int size, ParameterDirection direction, object data)
{
return new MySqlParameter(columnName, dataType, size, direction, false, 0, 0, string.Empty, DataRowVersion.Proposed, data);
}
}
}

Loading…
Cancel
Save