From fe29dae8f571d362922a23bd5cb62421c37ed919 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 17 Apr 2023 18:04:38 +0500 Subject: [PATCH] =?UTF-8?q?Email.BaseFactory.GetImageBase64()=20=D0=92?= =?UTF-8?q?=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D1=82=20=D0=BF?= =?UTF-8?q?=D1=83=D1=81=D1=82=D1=83=D1=8E=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D1=83=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=84=D0=B0=D0=B9=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BD=D0=B0=D0=B9=D0=B4=D0=B5=D0=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Email/BaseFactory.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs index 4e6d3084..8e44725f 100644 --- a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs +++ b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs @@ -22,16 +22,23 @@ namespace AsbCloudInfrastructure.Services.Email supportMail = configuration.GetValue("email:supportMail", "support@digitaldrilling.ru"); } - public static string GetImageBase64(string resourceFileName) + public static string GetOrEmptyImageBase64(string resourceFileName) { if (string.IsNullOrEmpty(resourceFileName)) throw new ArgumentInvalidException("ResourceFileName doesn`t exist", nameof(resourceFileName)); var baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? string.Empty; - var resoursesDir = "Res"; + var resourcesDir = "Res"; + + var logoFilePath = Path.Combine(baseDir, resourcesDir, resourceFileName); + + if (!File.Exists(logoFilePath)) + { + System.Diagnostics.Trace.TraceWarning($"GetOrEmptyImageBase64(). File {logoFilePath} not found."); + return string.Empty; + } - var logoFilePath = Path.Combine(baseDir, resoursesDir, resourceFileName); var imageBytes = File.ReadAllBytes(logoFilePath); var format = Path.GetExtension(resourceFileName).Trim('.'); return "data:image/" + format + ";base64," + Convert.ToBase64String(imageBytes); @@ -42,7 +49,7 @@ namespace AsbCloudInfrastructure.Services.Email public string MakeSignatue() { - var logo = GetImageBase64("logo_32.png"); + var logo = GetOrEmptyImageBase64("logo_32.png"); var sign = $"

---

" + $"{companyName}
" + $"Это письмо сформировано автоматически.
" +