50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
#if SignalR
|
|
|
|
using System;
|
|
|
|
#nullable enable
|
|
|
|
#pragma warning disable CA1822
|
|
|
|
namespace Adaptation.FileHandlers.Priority;
|
|
|
|
public class WeightedShortestJobFirstHub : Microsoft.AspNet.SignalR.Hub
|
|
{
|
|
|
|
// public async Task Send(int n)
|
|
// {
|
|
// await Clients.All.send(n);
|
|
// }
|
|
|
|
public void Send(string name, string message)
|
|
{
|
|
Console.WriteLine($"{name}:{message};");
|
|
Console.WriteLine(Context?.ConnectionId);
|
|
Clients.All.addMessage(name, message);
|
|
}
|
|
|
|
public void NotifyAll(Notification notification)
|
|
{
|
|
try
|
|
{
|
|
WorkItem workItem = GetWorkItem(notification);
|
|
Clients.All.updateWorkItem(notification.Page, workItem);
|
|
}
|
|
catch (Exception ex)
|
|
{ Console.WriteLine($"{ex.Message}{Environment.NewLine}{ex.StackTrace}"); }
|
|
}
|
|
|
|
private static WorkItem GetWorkItem(Notification notification)
|
|
{
|
|
WorkItem? result;
|
|
lock (FileRead.WorkItems)
|
|
{
|
|
if (!FileRead.WorkItems.TryGetValue(notification.Id, out result))
|
|
throw new Exception();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
#endif |