Feature: Held Devices Noticeboard
Provides a noticeboard for all devices, not just those assigned to users.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Disco.BI.Interop.SignalRHandlers
|
||||
{
|
||||
private static bool subscribed = false;
|
||||
private static object subscribeLock = new object();
|
||||
private static IPersistentConnectionContext notificationContext;
|
||||
|
||||
static UserHeldDeviceNotifications()
|
||||
{
|
||||
@@ -20,22 +21,62 @@ namespace Disco.BI.Interop.SignalRHandlers
|
||||
lock (subscribeLock)
|
||||
if (!subscribed)
|
||||
{
|
||||
Disco.Data.Repository.Monitor.RepositoryMonitor.StreamAfterCommit.Where(e => e.EntityType == typeof(Job)).Subscribe(UserJobUpdated);
|
||||
notificationContext = GlobalHost.ConnectionManager.GetConnectionContext<UserHeldDeviceNotifications>();
|
||||
|
||||
Disco.Data.Repository.Monitor.RepositoryMonitor.StreamAfterCommit.Where(e => e.EntityType == typeof(Job)).Subscribe(JobUpdated);
|
||||
|
||||
Disco.Data.Repository.Monitor.RepositoryMonitor.StreamBeforeCommit.Where(e =>
|
||||
e.EntityType == typeof(Device) &&
|
||||
(e.ModifiedProperties.Contains("DeviceModelId") ||
|
||||
e.ModifiedProperties.Contains("DeviceProfileId") ||
|
||||
e.ModifiedProperties.Contains("DeviceBatchId") ||
|
||||
e.ModifiedProperties.Contains("AssignedUserId"))
|
||||
).Subscribe(DeviceUpdated);
|
||||
|
||||
Disco.Data.Repository.Monitor.RepositoryMonitor.StreamAfterCommit.Where(e =>
|
||||
e.EntityType == typeof(User) &&
|
||||
e.ModifiedProperties.Contains("DisplayName")
|
||||
).Subscribe(UserUpdated);
|
||||
|
||||
subscribed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UserJobUpdated(RepositoryMonitorEvent e)
|
||||
private static void JobUpdated(RepositoryMonitorEvent e)
|
||||
{
|
||||
Job j = (Job)e.Entity;
|
||||
|
||||
if (j.UserId != null)
|
||||
if (j.DeviceSerialNumber != null)
|
||||
{
|
||||
var connectionManager = GlobalHost.ConnectionManager;
|
||||
var connectionContext = connectionManager.GetConnectionContext<UserHeldDeviceNotifications>();
|
||||
if (connectionContext != null)
|
||||
connectionContext.Connection.Broadcast(j.UserId);
|
||||
var jobDevice = e.dbContext.Devices.Where(d => d.SerialNumber == j.DeviceSerialNumber).FirstOrDefault();
|
||||
|
||||
if (jobDevice.AssignedUserId != null)
|
||||
notificationContext.Connection.Broadcast(jobDevice.AssignedUserId);
|
||||
}
|
||||
}
|
||||
private static void DeviceUpdated(RepositoryMonitorEvent e)
|
||||
{
|
||||
Device d = (Device)e.Entity;
|
||||
|
||||
string previouslyAssignedUserId = null;
|
||||
|
||||
if (e.ModifiedProperties.Contains("AssignedUserId"))
|
||||
previouslyAssignedUserId = e.GetPreviousPropertyValue<string>("AssignedUserId");
|
||||
|
||||
e.ExecuteAfterCommit(me =>
|
||||
{
|
||||
if (previouslyAssignedUserId != null)
|
||||
notificationContext.Connection.Broadcast(previouslyAssignedUserId);
|
||||
|
||||
if (d.AssignedUserId != null)
|
||||
notificationContext.Connection.Broadcast(d.AssignedUserId);
|
||||
});
|
||||
}
|
||||
private static void UserUpdated(RepositoryMonitorEvent e)
|
||||
{
|
||||
User u = (User)e.Entity;
|
||||
|
||||
notificationContext.Connection.Broadcast(u.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user