Merge branch 'develop' of https://gitlab.steamware.net/steamware/mapo-core into develop
This commit is contained in:
@@ -1,5 +1,72 @@
|
||||
<h3>AlarmsMan</h3>
|
||||
|
||||
@code {
|
||||
<EgwCoreLib.Razor.PeriodoSel CurrPeriodo=CurrPeriodo E_PeriodoSel="SetPeriodo"></EgwCoreLib.Razor.PeriodoSel>
|
||||
|
||||
@if (isProcessing)
|
||||
{
|
||||
<EgwCoreLib.Razor.LoadingData></EgwCoreLib.Razor.LoadingData>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-dark table-sm table-striped">
|
||||
<thead>
|
||||
<tr class="text-start1">
|
||||
<th>
|
||||
Elenco Allarmi
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in ListPaged)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<div class="row">
|
||||
<div class="col-6 col-md-8 small">
|
||||
<div>
|
||||
Mem: <b>@($"{item.MemAddress}.{@item.MemIndex}")</b>
|
||||
</div>
|
||||
<div class="text-danger">
|
||||
<b>@item.ValDecoded</b>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 col-md-4 text-end small">
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<div class="px-1">
|
||||
<div class="text-truncate">
|
||||
@($"{item.DtRif:ddd dd.MM.yy HH:mm:ss}") <i class="fa fa-clock-o" aria-hidden="true"></i>
|
||||
</div>
|
||||
<div class="text-truncate">
|
||||
@($"{item.Duration:N2} min") <i class="fa fa-hourglass-end" aria-hidden="true"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="px-1">
|
||||
@if (!string.IsNullOrEmpty(item.UserAck))
|
||||
{
|
||||
<b>@item.UserAck</b> <i class="fa fa-user" aria-hidden="true"></i>
|
||||
}
|
||||
</div>
|
||||
<div class="px-1">
|
||||
@if (item.ReqNotify != 0)
|
||||
{
|
||||
<button class="btn btn-sm btn-primary py-0" @onclick="() => SendNotify(item)">Invia <i class="fa fa-envelope" aria-hidden="true"></i></button>
|
||||
}
|
||||
@if (item.ReqAck != 0)
|
||||
{
|
||||
<button class="btn btn-sm btn-warning py-0" @onclick="() => DoAck(item)">Set <i class="fa fa-exclamation-triangle" aria-hidden="true"></i></button>
|
||||
}
|
||||
@* <div class="text-truncate" runat="server" id="divNotify" visible='<%# getBool(Eval("ReqNotify")) %>'>
|
||||
<asp:LinkButton runat="server" ID="lbtSendNotify" CssClass="btn btn-sm btn-primary py-0" ToolTip='<%# traduci("lblSendNotify") %>' OnClick="lbtSendNotify_Click" CommandArgument='<%# Eval("AlarmLogId") %>' OnClientClick='<%# SteamWare.jsUtils.getCBE("confermaSendNotify") %>'>Invia <i class="fa fa-envelope-o" aria-hidden="true"></i></asp:LinkButton>
|
||||
</div> *@
|
||||
@* <div class="text-truncate" runat="server" id="divAck" visible='<%# getBool(Eval("ReqAck")) %>'>
|
||||
<asp:LinkButton runat="server" ID="lbkDoAck" CssClass="btn btn-sm btn-warning py-0" ToolTip='<%# traduci("lblUserAck") %>' OnClick="lbkDoAck_Click" CommandArgument='<%# Eval("AlarmLogId") %>' OnClientClick='<%# SteamWare.jsUtils.getCBE("confermaUserAck") %>'>Set <i class="fa fa-exclamation-triangle" aria-hidden="true"></i></asp:LinkButton>
|
||||
</div> *@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<EgwCoreLib.Razor.DataPager currPage="@PageNum" PageSize="@NumRecPage" totalCount="@TotalCount" numPageChanged="SavePage" numRecordChanged="SaveNumRec"></EgwCoreLib.Razor.DataPager>
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using global::Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MP.Data;
|
||||
using MP.Data.DatabaseModels;
|
||||
using MP.Data.Services;
|
||||
using static EgwCoreLib.Utils.DtUtils;
|
||||
|
||||
namespace MP_TAB_SERV.Components
|
||||
{
|
||||
public partial class AlarmsMan
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
[Parameter]
|
||||
public MappaStatoExpl? RecMSE { get; set; } = null;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorno valori produzione alla data richiesta...
|
||||
/// </summary>
|
||||
/// <param name="newDate"></param>
|
||||
public async Task doUpdate()
|
||||
{
|
||||
isProcessing = true;
|
||||
await Task.Delay(1);
|
||||
if (!string.IsNullOrEmpty(IdxMaccSel))
|
||||
{
|
||||
ListComplete = await TabDServ.AlarmLogListFilt(IdxMaccSel, CurrPeriodo.Inizio, CurrPeriodo.Fine, false);
|
||||
TotalCount = ListComplete.Count;
|
||||
// esegue paginazione
|
||||
UpdateTable();
|
||||
}
|
||||
isProcessing = false;
|
||||
await Task.Delay(1);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected bool isProcessing = false;
|
||||
protected int NumRecPage = 10;
|
||||
protected int PageNum = 1;
|
||||
|
||||
protected int TotalCount = 0;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected List<AlarmLogModel> ListComplete { get; set; } = new List<AlarmLogModel>();
|
||||
|
||||
protected List<AlarmLogModel> ListPaged { get; set; } = new List<AlarmLogModel>();
|
||||
|
||||
[Inject]
|
||||
protected TabDataService TabDServ { get; set; } = null!;
|
||||
|
||||
|
||||
[Inject]
|
||||
protected MailService MailServ { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
if (RecMSE != null)
|
||||
{
|
||||
IdxMaccSel = RecMSE.IdxMacchina;
|
||||
await doUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
protected void SaveNumRec(int newNum)
|
||||
{
|
||||
NumRecPage = newNum;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
protected void SavePage(int newNum)
|
||||
{
|
||||
PageNum = newNum;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
protected async Task SetMacc(string selIdxMacc)
|
||||
{
|
||||
isProcessing = true;
|
||||
await Task.Delay(10);
|
||||
IdxMaccSel = selIdxMacc;
|
||||
await doUpdate();
|
||||
isProcessing = false;
|
||||
await Task.Delay(10);
|
||||
}
|
||||
|
||||
protected async Task SetPeriodo(Periodo newPeriodo)
|
||||
{
|
||||
CurrPeriodo = newPeriodo;
|
||||
await doUpdate();
|
||||
}
|
||||
|
||||
protected void UpdateTable()
|
||||
{
|
||||
// esegue paginazione
|
||||
if (TotalCount > NumRecPage)
|
||||
{
|
||||
ListPaged = ListComplete.Skip((PageNum - 1) * NumRecPage).Take(NumRecPage).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
ListPaged = ListComplete;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private Periodo CurrPeriodo { get; set; } = new Periodo();
|
||||
private string IdxMaccSel { get; set; } = "";
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
protected async Task SendNotify(AlarmLogModel currAlarm)
|
||||
{
|
||||
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler inviare notifica allarme?{Environment.NewLine}[{currAlarm.ValDecoded}]"))
|
||||
return;
|
||||
|
||||
isProcessing = true;
|
||||
List<string> dest = new List<string>();
|
||||
dest.Add("samuele@steamware.net");
|
||||
string body = $"Registrato allarme {currAlarm.ValDecoded}";
|
||||
MailKitMailData mData = new MailKitMailData()
|
||||
{
|
||||
To = dest,
|
||||
Subject = "MAPO Alarm Notification",
|
||||
Body = body
|
||||
};
|
||||
await MailServ.SendAsync(mData);
|
||||
isProcessing = false;
|
||||
await Task.Delay(1);
|
||||
}
|
||||
protected async Task DoAck(AlarmLogModel currAlarm)
|
||||
{
|
||||
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler registrare ACK dell'allarme?{Environment.NewLine}[{currAlarm.ValDecoded}]"))
|
||||
return;
|
||||
await Task.Delay(1);
|
||||
}
|
||||
|
||||
[Inject]
|
||||
protected IJSRuntime JSRuntime { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<div>
|
||||
<MachineBlock RecMSE="CurrMSE" FullMode="false"></MachineBlock>
|
||||
</div>
|
||||
<AlarmsMan></AlarmsMan>
|
||||
<MachineBlock RecMSE="CurrMSE" FullMode="false"></MachineBlock>
|
||||
<AlarmsMan RecMSE="CurrMSE"></AlarmsMan>
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using MP.Data;
|
||||
using MP.Data.Services;
|
||||
using StackExchange.Redis;
|
||||
|
||||
@@ -32,6 +33,10 @@ builder.Services.AddScoped<MessageService>();
|
||||
builder.Services.AddBlazoredLocalStorage();
|
||||
builder.Services.AddBlazoredSessionStorage();
|
||||
|
||||
// gestione email
|
||||
builder.Services.Configure<MailKitMailSettings>(builder.Configuration.GetSection(nameof(MailKitMailSettings)));
|
||||
builder.Services.AddScoped<MailService>();
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
|
||||
|
||||
@@ -22,5 +22,27 @@
|
||||
"BaseUrl": "/MP/TAB3",
|
||||
"ImgBasePath": "C:\\Steamware\\macchine",
|
||||
"CodModulo": "MoonPro"
|
||||
},
|
||||
"MailKitMailSettings": {
|
||||
"DisplayName": "MAPO EgalWare Email BOT",
|
||||
"From": "steamwarebot@outlook.it",
|
||||
"Host": "smtp-mail.outlook.com",
|
||||
"Password": "siamoInViaNazionale93",
|
||||
"Port": 587,
|
||||
"UserName": "steamwarebot@outlook.it",
|
||||
"UseSSL": false,
|
||||
"UseStartTls": true
|
||||
}
|
||||
//"ExternalProviders": {
|
||||
// "MailKit": {
|
||||
// "SMTP": {
|
||||
// "Address": "smtp.gmail.com",
|
||||
// "Port": "465",
|
||||
// "Account": "steamwarebot@gmail.com",
|
||||
// "Password": "drmfsls16",
|
||||
// "SenderEmail": "steamwarebot@gmail.com",
|
||||
// "SenderName": "Steamware Email BOT"
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,33 @@ namespace MP.Data.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Elenco allarmi macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">Macchina</param>
|
||||
/// <param name="dtFrom">Inizio periodo</param>
|
||||
/// <param name="dtTo">Fine periodo</param>
|
||||
/// <param name="showMulti"></param>
|
||||
/// <returns></returns>
|
||||
public List<AlarmLogModel> AlarmLogListFilt(string idxMacchina, DateTime dtFrom, DateTime dtTo, bool showMulti)
|
||||
{
|
||||
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DtFrom = new SqlParameter("@dtFrom", dtFrom);
|
||||
var DtTo = new SqlParameter("@dtTo", dtTo);
|
||||
var ShowMulti = new SqlParameter("@showMulti", showMulti);
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetAlarmLog
|
||||
.FromSqlRaw("EXEC stp_AL_getFilt @IdxMacchina, @dtFrom, @DtTo, @showMulti", IdxMacc, DtFrom, DtTo, ShowMulti)
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce l'anagrafica EVENTI per intero
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
#nullable disable
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
namespace MP.Data.DatabaseModels
|
||||
{
|
||||
[Table("AlarmLog")]
|
||||
public partial class AlarmLogModel
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int AlarmLogId { get; set; } = 0;
|
||||
public DateTime DtRif { get; set; } = DateTime.Now;
|
||||
public decimal Duration { get; set; } = 0;
|
||||
public string MachineId { get; set; } = "";
|
||||
public string MemAddress { get; set; } = "";
|
||||
public int MemIndex { get; set; } = 0;
|
||||
public int StatusVal { get; set; } = 0;
|
||||
public string ValDecoded { get; set; } = "";
|
||||
public DateTime DtNotify { get; set; } = DateTime.Now;
|
||||
public string UserAck { get; set; } = "";
|
||||
public DateTime DtAck { get; set; } = DateTime.Now;
|
||||
|
||||
[NotMapped]
|
||||
public int ReqNotify
|
||||
{
|
||||
get => Duration > 1 && DtNotify < DtRif ? 1 : 0;
|
||||
}
|
||||
[NotMapped]
|
||||
public int ReqAck
|
||||
{
|
||||
get => DtNotify > DtRif && DtAck < DtRif ? 1 : 0;
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Remove="DatabaseModels\TurniPareto.cs" />
|
||||
<Compile Remove="DatabaseModels\TurniParetoOdl.cs" />
|
||||
<Compile Remove="MailKitEmailSender.cs" />
|
||||
<Compile Remove="MailKitEmailSenderOptions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -18,6 +20,8 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
|
||||
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
|
||||
<PackageReference Include="MailKit" Version="4.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.9" />
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data
|
||||
{
|
||||
public class MailKitMailData
|
||||
{
|
||||
// Receiver
|
||||
public List<string> To { get; set; }
|
||||
public List<string> Bcc { get; set; }
|
||||
|
||||
public List<string> Cc { get; set; }
|
||||
|
||||
// Sender
|
||||
public string? From { get; set; }
|
||||
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
public string? ReplyTo { get; set; }
|
||||
|
||||
public string? ReplyToName { get; set; }
|
||||
|
||||
// Content
|
||||
public string Subject { get; set; }
|
||||
|
||||
public string? Body { get; set; }
|
||||
|
||||
// Attach (opzionale)
|
||||
public IFormFileCollection? Attachments { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data
|
||||
{
|
||||
public class MailKitMailSettings
|
||||
{
|
||||
public string? DisplayName { get; set; }
|
||||
public string? From { get; set; }
|
||||
public string? UserName { get; set; }
|
||||
public string? Password { get; set; }
|
||||
public string? Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public bool UseSSL { get; set; }
|
||||
public bool UseStartTls { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ namespace MP.Data
|
||||
|
||||
#region Public Properties
|
||||
|
||||
|
||||
public virtual DbSet<AlarmLogModel> DbSetAlarmLog { get; set; }
|
||||
public virtual DbSet<StatsAnagArticoli> DbSetStatArticoli { get; set; }
|
||||
public virtual DbSet<AnagArticoli> DbSetArticoli { get; set; }
|
||||
public virtual DbSet<AnagEventiModel> DbSetAnagEventi { get; set; }
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
public interface IMailService
|
||||
{
|
||||
Task<bool> SendAsync(MailKitMailData mailData, CancellationToken ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
using MailKit.Net.Smtp;
|
||||
using MailKit.Security;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MimeKit;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementazione MailKit come descritto qui
|
||||
/// https://blog.christian-schou.dk/send-emails-with-asp-net-core-with-mailkit/
|
||||
/// </summary>
|
||||
public class MailService : IMailService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MailService(IOptions<MailKitMailSettings> settings)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public async Task<bool> SendAsync(MailKitMailData mailData, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Initialize a new instance of the MimeKit.MimeMessage class
|
||||
var mail = new MimeMessage();
|
||||
|
||||
#region Sender / Receiver
|
||||
|
||||
// Sender
|
||||
mail.From.Add(new MailboxAddress(_settings.DisplayName, mailData.From ?? _settings.From));
|
||||
mail.Sender = new MailboxAddress(mailData.DisplayName ?? _settings.DisplayName, mailData.From ?? _settings.From);
|
||||
|
||||
// Receiver
|
||||
foreach (string mailAddress in mailData.To)
|
||||
mail.To.Add(MailboxAddress.Parse(mailAddress));
|
||||
|
||||
// Set Reply to if specified in mail data
|
||||
if (!string.IsNullOrEmpty(mailData.ReplyTo))
|
||||
mail.ReplyTo.Add(new MailboxAddress(mailData.ReplyToName, mailData.ReplyTo));
|
||||
|
||||
// BCC Check if a BCC was supplied in the request
|
||||
if (mailData.Bcc != null)
|
||||
{
|
||||
// Get only addresses where value is not null or with whitespace. x = value of address
|
||||
foreach (string mailAddress in mailData.Bcc.Where(x => !string.IsNullOrWhiteSpace(x)))
|
||||
mail.Bcc.Add(MailboxAddress.Parse(mailAddress.Trim()));
|
||||
}
|
||||
|
||||
// CC Check if a CC address was supplied in the request
|
||||
if (mailData.Cc != null)
|
||||
{
|
||||
foreach (string mailAddress in mailData.Cc.Where(x => !string.IsNullOrWhiteSpace(x)))
|
||||
mail.Cc.Add(MailboxAddress.Parse(mailAddress.Trim()));
|
||||
}
|
||||
|
||||
#endregion Sender / Receiver
|
||||
|
||||
#region Content
|
||||
|
||||
// Add Content to Mime Message
|
||||
var body = new BodyBuilder();
|
||||
mail.Subject = mailData.Subject;
|
||||
body.HtmlBody = mailData.Body;
|
||||
mail.Body = body.ToMessageBody();
|
||||
|
||||
// Check if we got any attachments and add the to the builder for our message
|
||||
if (mailData.Attachments != null)
|
||||
{
|
||||
byte[] attachmentFileByteArray;
|
||||
|
||||
foreach (IFormFile attachment in mailData.Attachments)
|
||||
{
|
||||
// Check if length of the file in bytes is larger than 0
|
||||
if (attachment.Length > 0)
|
||||
{
|
||||
// Create a new memory stream and attach attachment to mail body
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
// Copy the attachment to the stream
|
||||
attachment.CopyTo(memoryStream);
|
||||
attachmentFileByteArray = memoryStream.ToArray();
|
||||
}
|
||||
// Add the attachment from the byte array
|
||||
body.Attachments.Add(attachment.FileName, attachmentFileByteArray, ContentType.Parse(attachment.ContentType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Content
|
||||
|
||||
#region Send Mail
|
||||
|
||||
using var smtp = new SmtpClient();
|
||||
|
||||
if (_settings.UseSSL)
|
||||
{
|
||||
await smtp.ConnectAsync(_settings.Host, _settings.Port, SecureSocketOptions.SslOnConnect, ct);
|
||||
}
|
||||
else if (_settings.UseStartTls)
|
||||
{
|
||||
await smtp.ConnectAsync(_settings.Host, _settings.Port, SecureSocketOptions.StartTls, ct);
|
||||
}
|
||||
await smtp.AuthenticateAsync(_settings.UserName, _settings.Password, ct);
|
||||
await smtp.SendAsync(mail, ct);
|
||||
await smtp.DisconnectAsync(true, ct);
|
||||
|
||||
#endregion Send Mail
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in SendAsync{Environment.NewLine}{exc}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly MailKitMailSettings _settings;
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -890,6 +890,44 @@ namespace MP.Data.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco allarmi macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">Macchina</param>
|
||||
/// <param name="dtFrom">Inizio periodo</param>
|
||||
/// <param name="dtTo">Fine periodo</param>
|
||||
/// <param name="showMulti"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<AlarmLogModel>> AlarmLogListFilt(string idxMacchina, DateTime dtFrom, DateTime dtTo, bool showMulti)
|
||||
{
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<AlarmLogModel>? result = new List<AlarmLogModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{redisBaseKey}:AlarmLog:{idxMacchina}:{dtFrom:yyyyMMdd-HHmmss}:{dtTo::yyyyMMdd-HHmmss}:{showMulti}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<AlarmLogModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.AlarmLogListFilt(idxMacchina, dtFrom, dtTo, showMulti));
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<AlarmLogModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"AlarmLogListFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Elenco PODL macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">Macchina</param>
|
||||
|
||||
Reference in New Issue
Block a user