migrated over Common.Library.Console

net6.0
Don Oerkfitz 4 years ago
parent 0c6861f38e
commit eb7f668341

@ -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"
}
}
Loading…
Cancel
Save