forked from ddrilling/AsbCloudServer
56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
|
using AsbCloudApp.Data;
|
|||
|
using Microsoft.Extensions.Configuration;
|
|||
|
using System;
|
|||
|
using System.IO;
|
|||
|
|
|||
|
namespace AsbCloudInfrastructure.Services.Email
|
|||
|
{
|
|||
|
public class BaseFactory
|
|||
|
{
|
|||
|
private readonly string platformName;
|
|||
|
private readonly string platformUrl;
|
|||
|
private readonly string companyName;
|
|||
|
private readonly string supportMail;
|
|||
|
|
|||
|
public BaseFactory(IConfiguration configuration)
|
|||
|
{
|
|||
|
platformName = configuration.GetValue("email:platformName", "Цифровое бурение");
|
|||
|
platformUrl = configuration.GetValue("email:platformUrl", "https://cloud.digitaldrilling.ru/");
|
|||
|
companyName = configuration.GetValue("email:companyName", "ООО \"Цифровое бурение\"");
|
|||
|
supportMail = configuration.GetValue("email:supportMail", "support@digitaldrilling.ru");
|
|||
|
}
|
|||
|
|
|||
|
public static string GetImageBase64(string resourceFileName)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(resourceFileName))
|
|||
|
return null;
|
|||
|
|
|||
|
var baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|||
|
var resoursesDir = "Res";
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
public static string MakeHref(string url, string text)
|
|||
|
=> $"<a href=\"{url}\">{text}</a>";
|
|||
|
|
|||
|
public string MakeSignatue()
|
|||
|
{
|
|||
|
var logo = GetImageBase64("logo_32.png");
|
|||
|
var sign = $"<br><br>---<br><img src=\"{logo}\"/><br>" +
|
|||
|
$"{companyName}<br>" +
|
|||
|
$"Это письмо сформировано автоматически.<br>" +
|
|||
|
$"Для получения помощи по работе на портале {platformName}" +
|
|||
|
$"обращайтесь по адресу {supportMail}";
|
|||
|
return sign;
|
|||
|
}
|
|||
|
|
|||
|
public virtual string MakeSubject(WellDto well, string action)
|
|||
|
=> $"{well.Deposit}, {well.Cluster}, {well.Caption}. {action}";
|
|||
|
}
|
|||
|
}
|