PostService
This commit is contained in:
@ -6,6 +6,7 @@ using Barcode.Host.Shared.Models;
|
||||
using Barcode.Host.Shared.Models.Stateless;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Serilog.Context;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Barcode.Host.Server.HostedService;
|
||||
|
||||
@ -15,28 +16,36 @@ public class TimedHostedService : IHostedService, IAggregateInputReader, IDispos
|
||||
public event InputReader.RaiseKeyPress? OnKeyPress;
|
||||
|
||||
private readonly int _ExecutionCount;
|
||||
protected readonly Calendar _Calendar;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IFileService _FileService;
|
||||
private readonly IPostService _PostService;
|
||||
private readonly ISerialService _SerialService;
|
||||
private readonly ILastScanService _LastScanService;
|
||||
private readonly ILogger<TimedHostedService> _Logger;
|
||||
private readonly IHttpClientFactory _HttpClientFactory;
|
||||
private readonly ILinuxGroupManager _LinuxGroupManager;
|
||||
private readonly IHubContext<NotificationHub> _HubContext;
|
||||
private readonly Dictionary<string, InputReader> _Readers;
|
||||
private readonly Dictionary<EventCode, char> _CharToEventCodes;
|
||||
private readonly List<(string MethodName, Timer Timer)> _Timers;
|
||||
|
||||
public TimedHostedService(ILogger<TimedHostedService> logger, AppSettings appSettings, ILinuxGroupManager linuxGroupManager, ILastScanService lastScanService, ISerialService serialService, IHubContext<NotificationHub> hubContext)
|
||||
public TimedHostedService(ILogger<TimedHostedService> logger, AppSettings appSettings, ILinuxGroupManager linuxGroupManager, ILastScanService lastScanService, ISerialService serialService, IHttpClientFactory httpClientFactory, IHubContext<NotificationHub> hubContext, IFileService fileService, IPostService postService)
|
||||
{
|
||||
_Timers = new();
|
||||
_Readers = new();
|
||||
_Logger = logger;
|
||||
_Readers = new();
|
||||
_ExecutionCount = 0;
|
||||
_HubContext = hubContext;
|
||||
_CharToEventCodes = new();
|
||||
_AppSettings = appSettings;
|
||||
_FileService = fileService;
|
||||
_PostService = postService;
|
||||
_SerialService = serialService;
|
||||
_LastScanService = lastScanService;
|
||||
_HttpClientFactory = httpClientFactory;
|
||||
_LinuxGroupManager = linuxGroupManager;
|
||||
_Calendar = new CultureInfo("en-US").Calendar;
|
||||
Timer writeTimer = new(Write, null, Timeout.Infinite, Timeout.Infinite);
|
||||
Timer scanForNewInputsTimer = new(ScanForNewInputs, null, Timeout.Infinite, Timeout.Infinite);
|
||||
if (!string.IsNullOrEmpty(_AppSettings.SerialPortName))
|
||||
@ -122,6 +131,13 @@ public class TimedHostedService : IHostedService, IAggregateInputReader, IDispos
|
||||
{
|
||||
Notification notification = new(e, result.Results);
|
||||
_ = _HubContext.Clients.All.SendAsync(nameof(NotificationHub.NotifyAll), notification);
|
||||
if (!string.IsNullOrEmpty(_AppSettings.FileShare))
|
||||
_FileService.Write(_AppSettings.EquipmentName, _AppSettings.FileShare, _Calendar, notification);
|
||||
if (!string.IsNullOrEmpty(_AppSettings.PostTo))
|
||||
{
|
||||
HttpClient httpClient = _HttpClientFactory.CreateClient(nameof(TimedHostedService));
|
||||
_ = _PostService.PostAsync(_AppSettings.PostTo, httpClient, notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user