24.12.2023 izlediklerim
Dapper ile yardımcı queryler yazmak
CORS içinde querylere behaviour yoluyla cache dekorasyonu yapmak
_logger.LogInformation("Event Created {@Date}", context.Message.Created);
string resizeMeta = "640x480,800x600,1280x940";
MagickImageInfo imageInfo = new MagickImageInfo(context.Message.ImageFile);
List<string> resizeList = resizeMeta.Split(',').ToList();
string fileName = $"{imageInfo.Width}x{imageInfo.Height}";
resizeList.Add(fileName);
List<TestCreatedIntegrationEventWrapper> resizedImageList = new();
foreach (var resize in resizeList)
{
var width = resize.Split("x").First();
var height = resize.Split("x").Last();
using var image = new MagickImage(context.Message.ImageFile);
var size = new MagickGeometry(int.Parse(width), int.Parse(height));
// This will resize the image to a fixed size without maintaining the aspect ratio.
// Normally an image will be resized to fit inside the specified size.
size.IgnoreAspectRatio = true;
image.Resize(size);
//add resize image to the list
resizedImageList.Add(new TestCreatedIntegrationEventWrapper() { ImageFile = image.ToByteArray(), ImageFileName = $"Test.{width}x{height}.{imageInfo.Format}"});
// Save the result
//image.Write($"Snakeware.{width}x{height}.{imageInfo.Format}");
//_logger.LogInformation($"Snakeware.{width}x{height}.{imageInfo.Format} file created");
}
//gelen datayı sftp yaparak kaydet
DoSftp(resizedImageList);
return Task.CompletedTask;
private void DoSftp(List<TestCreatedIntegrationEventWrapper> resizedImageList)
{
//SSH.NET kütüphanesi yüklendi
//https://tahsinmete.com/windows-server-sftp-kurulumu/
//https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell
//Bitwise Ssh client yükledim
//https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell
//https://code-maze.com/dotnet-sftp-secure-file-upload/
//hp burada benim oluşturduğum user
using SftpClient client = new("localhost", 22, "HP", "1");
try
{
client.Connect();
if (client.IsConnected)
{
if(!client.Exists("/cropimages"))
{
client.CreateDirectory("/cropimages");
}
foreach (var item in resizedImageList)
{
MemoryStream stream = new MemoryStream(item.ImageFile);
client.UploadFile(stream, $"/cropimages/{item.ImageFileName}");
_logger.LogInformation("Directory listing:");
foreach (var sftpFile in client.ListDirectory("/cropimages"))
{
_logger.LogInformation($"\t{sftpFile.FullName}");
}
}
client.Disconnect();
}
}
catch (Exception e) when (e is SshConnectionException || e is SocketException || e is ProxyException)
{
_logger.LogInformation($"Error connecting to server: {e.Message}");
}
catch (SshAuthenticationException e)
{
_logger.LogInformation($"Failed to authenticate: {e.Message}");
}
catch (SftpPermissionDeniedException e)
{
_logger.LogInformation($"Operation denied by the server: {e.Message}");
}
catch (SshException e)
{
_logger.LogInformation($"Sftp Error: {e.Message}");
}
}
Yorumlar
Yorum Gönder