SignalR.Client => SelfHost
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Adaptation.FileHandlers.MoveAllFiles.ApiController;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
public class BarcodeController : System.Web.Http.ApiController
|
||||
{
|
||||
|
||||
#nullable enable
|
||||
|
||||
#pragma warning disable CA1822
|
||||
public string Get()
|
||||
#pragma warning restore CA1822
|
||||
{
|
||||
string results = "record";
|
||||
return results;
|
||||
}
|
||||
|
||||
private static string? GetJson(System.Net.Http.HttpContent? httpContent)
|
||||
{
|
||||
string? result;
|
||||
if (httpContent is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
Task<string> task = httpContent.ReadAsStringAsync();
|
||||
task.Wait();
|
||||
result = task.Result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Write(string barcodeHostFileShare, string cellInstanceConnectionName, Notification notification)
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||
string directory = Path.Combine(barcodeHostFileShare, weekOfYear, dateTime.ToString("yyyy-MM-dd_HH"));
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
File.WriteAllText(Path.Combine(directory, $"{cellInstanceConnectionName}.csv"), notification.LastScanServiceResultValue);
|
||||
}
|
||||
|
||||
[Route("{id}")]
|
||||
#pragma warning disable CA1822
|
||||
public void Post(string id)
|
||||
#pragma warning restore CA1822
|
||||
{
|
||||
string? json = GetJson(Request.Content);
|
||||
if (json is not null)
|
||||
{
|
||||
Notification? notification = JsonSerializer.Deserialize<Notification>(json);
|
||||
if (notification is not null)
|
||||
Write(FileRead.BarcodeHostFileShare, id, notification.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user