diff --git a/Disco.BI/BI/Extensions/JobExtensions.cs b/Disco.BI/BI/Extensions/JobExtensions.cs index 478b4e25..f9c6d219 100644 --- a/Disco.BI/BI/Extensions/JobExtensions.cs +++ b/Disco.BI/BI/Extensions/JobExtensions.cs @@ -13,13 +13,6 @@ namespace Disco.BI.Extensions { public static class JobExtensions { - - public static void BroadcastUpdate(this Job j) - { - if (j.UserId != null) - Interop.SignalRHandlers.UserHeldDevices.UserJobUpdated(j.UserId); - } - public static JobAttachment CreateAttachment(this Job Job, DiscoDataContext dbContext, User CreatorUser, string Filename, string MimeType, string Comments, Stream Content, DocumentTemplate DocumentTemplate = null, byte[] PdfThumbnail = null) { if (string.IsNullOrEmpty(MimeType) || MimeType.Equals("unknown/unknown", StringComparison.InvariantCultureIgnoreCase)) diff --git a/Disco.BI/BI/Interop/SignalRHandlers/UserHeldDevices.cs b/Disco.BI/BI/Interop/SignalRHandlers/UserHeldDevices.cs index 9d7c2efd..5fdfeb11 100644 --- a/Disco.BI/BI/Interop/SignalRHandlers/UserHeldDevices.cs +++ b/Disco.BI/BI/Interop/SignalRHandlers/UserHeldDevices.cs @@ -3,19 +3,39 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.AspNet.SignalR; +using System.Reactive.Linq; +using Disco.Data.Repository.Monitor; +using Disco.Models.Repository; namespace Disco.BI.Interop.SignalRHandlers { public class UserHeldDevices : PersistentConnection { + private static bool subscribed = false; + private static object subscribeLock = new object(); - internal static void UserJobUpdated(string JobUserId) + static UserHeldDevices() { - var connectionManager = GlobalHost.ConnectionManager; - var connectionContext = connectionManager.GetConnectionContext(); - if (connectionContext != null) - connectionContext.Connection.Broadcast(JobUserId); + if (!subscribed) + lock (subscribeLock) + if (!subscribed) + { + Disco.Data.Repository.Monitor.RepositoryMonitor.StreamAfterCommit.Where(e => e.EntityType == typeof(Job)).Subscribe(UserJobUpdated); + subscribed = true; + } } + private static void UserJobUpdated(RepositoryMonitorEvent e) + { + Job j = (Job)e.Entity; + + if (j.UserId != null) + { + var connectionManager = GlobalHost.ConnectionManager; + var connectionContext = connectionManager.GetConnectionContext(); + if (connectionContext != null) + connectionContext.Connection.Broadcast(j.UserId); + } + } } } diff --git a/Disco.BI/Properties/AssemblyInfo.cs b/Disco.BI/Properties/AssemblyInfo.cs index e3d4667a..afb25697 100644 --- a/Disco.BI/Properties/AssemblyInfo.cs +++ b/Disco.BI/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0506.1904")] -[assembly: AssemblyFileVersion("1.2.0506.1904")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0506.2022")] +[assembly: AssemblyFileVersion("1.2.0506.2022")] \ No newline at end of file diff --git a/Disco.Client/Properties/AssemblyInfo.cs b/Disco.Client/Properties/AssemblyInfo.cs index 5879be71..389ae726 100644 --- a/Disco.Client/Properties/AssemblyInfo.cs +++ b/Disco.Client/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0506.1845")] -[assembly: AssemblyFileVersion("1.2.0506.1845")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0506.2004")] +[assembly: AssemblyFileVersion("1.2.0506.2004")] \ No newline at end of file diff --git a/Disco.Models/Properties/AssemblyInfo.cs b/Disco.Models/Properties/AssemblyInfo.cs index 0a1ac8fe..3e6a91ce 100644 --- a/Disco.Models/Properties/AssemblyInfo.cs +++ b/Disco.Models/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0506.1904")] -[assembly: AssemblyFileVersion("1.2.0506.1904")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0506.2022")] +[assembly: AssemblyFileVersion("1.2.0506.2022")] \ No newline at end of file diff --git a/Disco.Services/Properties/AssemblyInfo.cs b/Disco.Services/Properties/AssemblyInfo.cs index 9d07a7e6..8a969675 100644 --- a/Disco.Services/Properties/AssemblyInfo.cs +++ b/Disco.Services/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0506.1904")] -[assembly: AssemblyFileVersion("1.2.0506.1904")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0506.2022")] +[assembly: AssemblyFileVersion("1.2.0506.2022")] \ No newline at end of file diff --git a/Disco.Web.Extensions/Properties/AssemblyInfo.cs b/Disco.Web.Extensions/Properties/AssemblyInfo.cs index b50f1cab..b748dd66 100644 --- a/Disco.Web.Extensions/Properties/AssemblyInfo.cs +++ b/Disco.Web.Extensions/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0506.1904")] -[assembly: AssemblyFileVersion("1.2.0506.1904")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0506.2022")] +[assembly: AssemblyFileVersion("1.2.0506.2022")] \ No newline at end of file diff --git a/Disco.Web/Areas/API/Controllers/JobController.cs b/Disco.Web/Areas/API/Controllers/JobController.cs index 41da195b..44ab685f 100644 --- a/Disco.Web/Areas/API/Controllers/JobController.cs +++ b/Disco.Web/Areas/API/Controllers/JobController.cs @@ -443,7 +443,6 @@ namespace Disco.Web.Areas.API.Controllers job.ExpectedClosedDate = null; } dbContext.SaveChanges(); - job.BroadcastUpdate(); } private void UpdateDeviceHeldLocation(Job job, string DeviceHeldLocation) { @@ -577,7 +576,6 @@ namespace Disco.Web.Areas.API.Controllers } job.JobMetaNonWarranty.AccountingChargeRequiredUserId = DiscoApplication.CurrentUser.Id; dbContext.SaveChanges(); - job.BroadcastUpdate(); return new Models.Job._DateChangeModel() { Id = job.Id, @@ -612,7 +610,6 @@ namespace Disco.Web.Areas.API.Controllers } job.JobMetaNonWarranty.AccountingChargeAddedUserId = DiscoApplication.CurrentUser.Id; dbContext.SaveChanges(); - job.BroadcastUpdate(); return new Models.Job._DateChangeModel() { Id = job.Id, @@ -647,7 +644,6 @@ namespace Disco.Web.Areas.API.Controllers } job.JobMetaNonWarranty.AccountingChargePaidUserId = DiscoApplication.CurrentUser.Id; dbContext.SaveChanges(); - job.BroadcastUpdate(); return new Models.Job._DateChangeModel() { Id = job.Id, @@ -1462,7 +1458,6 @@ namespace Disco.Web.Areas.API.Controllers job.OnWaitingForUserAction(dbContext, DiscoApplication.CurrentUser, Reason); dbContext.SaveChanges(); - job.BroadcastUpdate(); if (redirect.HasValue && redirect.Value) return RedirectToAction(MVC.Job.Show(job.Id)); else @@ -1492,7 +1487,6 @@ namespace Disco.Web.Areas.API.Controllers job.OnNotWaitingForUserAction(dbContext, DiscoApplication.CurrentUser, Resolution); dbContext.SaveChanges(); - job.BroadcastUpdate(); if (redirect.HasValue && redirect.Value) return RedirectToAction(MVC.Job.Show(job.Id)); else @@ -1540,7 +1534,6 @@ namespace Disco.Web.Areas.API.Controllers j.OnDeviceReadyForReturn(DiscoApplication.CurrentUser); dbContext.SaveChanges(); - j.BroadcastUpdate(); if (redirect) return RedirectToAction(MVC.Job.Show(id)); else @@ -1563,7 +1556,6 @@ namespace Disco.Web.Areas.API.Controllers j.OnDeviceHeld(DiscoApplication.CurrentUser); dbContext.SaveChanges(); - j.BroadcastUpdate(); if (redirect) return RedirectToAction(MVC.Job.Show(id)); else @@ -1586,7 +1578,6 @@ namespace Disco.Web.Areas.API.Controllers j.OnDeviceReturned(DiscoApplication.CurrentUser); dbContext.SaveChanges(); - j.BroadcastUpdate(); if (redirect) return RedirectToAction(MVC.Job.Show(id)); else @@ -1655,7 +1646,6 @@ namespace Disco.Web.Areas.API.Controllers j.OnReopen(); dbContext.SaveChanges(); - j.BroadcastUpdate(); if (redirect) return RedirectToAction(MVC.Job.Show(id)); else diff --git a/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.cshtml b/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.cshtml index 753e40f2..eaedc92e 100644 --- a/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.cshtml +++ b/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.cshtml @@ -453,10 +453,20 @@ }; var updatedModel = function (id) { - var UserId = id.toString(); - $.getJSON('@(Url.Action(MVC.Public.UserHeldDevices.UserHeldDevice()))', { id: UserId }, function (data) { - processModel(UserId, data, false); - }); + var userId = id.toString(); + + $.ajax({ + dataType: 'json', + url: '@(Url.Action(MVC.Public.UserHeldDevices.UserHeldDevice()))', + data: { id: userId }, + success: function (data) { + processModel(userId, data, false); + }, + error: function(jqXHR, textStatus, errorThrown){ + if (textStatus == 'parsererror') // null Result + processModel(userId, null, false); + } + }) }; var connectionError = function () { diff --git a/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.generated.cs b/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.generated.cs index 67f98f38..f866bcff 100644 --- a/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.generated.cs +++ b/Disco.Web/Areas/Public/Views/UserHeldDevices/Noticeboard.generated.cs @@ -2,7 +2,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17929 +// Runtime Version:4.0.30319.18033 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -31,9 +31,9 @@ namespace Disco.Web.Areas.Public.Views.UserHeldDevices using Disco.Web; using Disco.Web.Extensions; - [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "1.5.0.0")] + [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "1.5.4.0")] [System.Web.WebPages.PageVirtualPathAttribute("~/Areas/Public/Views/UserHeldDevices/Noticeboard.cshtml")] - public class Noticeboard : System.Web.Mvc.WebViewPage + public partial class Noticeboard : System.Web.Mvc.WebViewPage { public Noticeboard() { @@ -412,19 +412,26 @@ WriteLiteral(">\r\n $(function () {\r\n var models = {};\r\n " (model.htmlLi && model.IsAlert) {\r\n model.htmlLi.addClas" + "s(\'alert\');\r\n }\r\n scheduleModelUpdate(mode" + "l);\r\n }\r\n };\r\n\r\n var updatedModel = functio" + -"n (id) {\r\n var UserId = id.toString();\r\n $.getJSON" + -"(\'"); +"n (id) {\r\n var userId = id.toString();\r\n\r\n $.ajax(" + +"{\r\n dataType: \'json\',\r\n url: \'"); - #line 457 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" - Write(Url.Action(MVC.Public.UserHeldDevices.UserHeldDevice())); + #line 460 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" + Write(Url.Action(MVC.Public.UserHeldDevices.UserHeldDevice())); #line default #line hidden -WriteLiteral(@"', { id: UserId }, function (data) { - processModel(UserId, data, false); - }); +WriteLiteral(@"', + data: { id: userId }, + success: function (data) { + processModel(userId, data, false); + }, + error: function(jqXHR, textStatus, errorThrown){ + if (textStatus == 'parsererror') // null Result + processModel(userId, null, false); + } + }) }; var connectionError = function () { @@ -435,7 +442,7 @@ WriteLiteral(@"', { id: UserId }, function (data) { window.location.href = '"); - #line 467 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" + #line 477 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" Write(Url.Action(MVC.Public.UserHeldDevices.Noticeboard())); @@ -446,7 +453,7 @@ WriteLiteral("\';\r\n }, 10000);\r\n }\r\n "rsistantConnection = $.connection(\'"); - #line 474 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" + #line 484 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" Write(Url.Content("~/Public/UserHeldDevices/Notifications")); @@ -457,7 +464,7 @@ WriteLiteral("\');\r\n persistantConnection.received(updatedModel "tion.start(function () {\r\n $.getJSON(\'"); - #line 478 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" + #line 488 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" Write(Url.Action(MVC.Public.UserHeldDevices.UserHeldDevices())); @@ -482,14 +489,14 @@ WriteLiteral(">\r\n (Links.ClientSource.Style.Images.Icon32_png + #line 500 "..\..\Areas\Public\Views\UserHeldDevices\Noticeboard.cshtml" + , Tuple.Create(Tuple.Create("", 23901), Tuple.Create(Links.ClientSource.Style.Images.Icon32_png #line default #line hidden -, 23521), false) +, 23901), false) ); WriteLiteral(" alt=\"Disco Logo\"");