From b1d16ae87ccd81939d1dfd4814385331196bbc87 Mon Sep 17 00:00:00 2001 From: Gary Sharp Date: Thu, 4 Jul 2013 15:28:53 +1000 Subject: [PATCH] Update: SignalR AddToGroups at Query String Use OnConnection query string to add group membership rather than making an additional call after connection. --- .../SignalRHandlers/LogNotifications.cs | 16 ++++ .../RepositoryMonitorNotifications.cs | 16 ++++ .../ScheduledTasksStatusNotifications.cs | 16 ++++ .../DocumentTemplate/ImportStatus.cshtml | 41 +++------ .../ImportStatus.generated.cs | 92 +++++++++---------- .../Config/Views/Enrolment/Status.cshtml | 6 +- .../Views/Enrolment/Status.generated.cs | 20 ++-- .../Config/Views/Logging/TaskStatus.cshtml | 5 +- .../Views/Logging/TaskStatus.generated.cs | 5 +- .../Config/Views/Shared/LogEvents.cshtml | 8 +- .../Views/Shared/LogEvents.generated.cs | 8 +- Disco.Web/Views/Job/JobParts/Resources.cshtml | 6 +- .../Views/Job/JobParts/Resources.generated.cs | 6 +- Disco.Web/Views/Update/Index.cshtml | 3 +- Disco.Web/Views/Update/Index.generated.cs | 3 +- 15 files changed, 137 insertions(+), 114 deletions(-) diff --git a/Disco.BI/BI/Interop/SignalRHandlers/LogNotifications.cs b/Disco.BI/BI/Interop/SignalRHandlers/LogNotifications.cs index a8ba7c23..2c297851 100644 --- a/Disco.BI/BI/Interop/SignalRHandlers/LogNotifications.cs +++ b/Disco.BI/BI/Interop/SignalRHandlers/LogNotifications.cs @@ -22,6 +22,22 @@ namespace Disco.BI.Interop.SignalRHandlers } } + protected override Task OnConnected(IRequest request, string connectionId) + { + string addToGroups = request.QueryString["addToGroups"]; + + if (!string.IsNullOrWhiteSpace(addToGroups)) + { + var groups = addToGroups.Split(','); + foreach (var g in groups) + { + this.Groups.Add(connectionId, g); + } + } + + return base.OnConnected(request, connectionId); + } + protected override System.Threading.Tasks.Task OnReceived(IRequest request, string connectionId, string data) { // Add to Group diff --git a/Disco.BI/BI/Interop/SignalRHandlers/RepositoryMonitorNotifications.cs b/Disco.BI/BI/Interop/SignalRHandlers/RepositoryMonitorNotifications.cs index 7a193f66..e50742d9 100644 --- a/Disco.BI/BI/Interop/SignalRHandlers/RepositoryMonitorNotifications.cs +++ b/Disco.BI/BI/Interop/SignalRHandlers/RepositoryMonitorNotifications.cs @@ -15,6 +15,22 @@ namespace Disco.BI.Interop.SignalRHandlers RepositoryMonitor.StreamAfterCommit.Subscribe(AfterCommit); } + protected override Task OnConnected(IRequest request, string connectionId) + { + string addToGroups = request.QueryString["addToGroups"]; + + if (!string.IsNullOrWhiteSpace(addToGroups)) + { + var groups = addToGroups.Split(','); + foreach (var g in groups) + { + this.Groups.Add(connectionId, g); + } + } + + return base.OnConnected(request, connectionId); + } + protected override Task OnReceived(IRequest request, string connectionId, string data) { // Add to Group diff --git a/Disco.BI/BI/Interop/SignalRHandlers/ScheduledTasksStatusNotifications.cs b/Disco.BI/BI/Interop/SignalRHandlers/ScheduledTasksStatusNotifications.cs index 96fbcd62..45389d75 100644 --- a/Disco.BI/BI/Interop/SignalRHandlers/ScheduledTasksStatusNotifications.cs +++ b/Disco.BI/BI/Interop/SignalRHandlers/ScheduledTasksStatusNotifications.cs @@ -21,6 +21,22 @@ namespace Disco.BI.Interop.SignalRHandlers } } + protected override Task OnConnected(IRequest request, string connectionId) + { + string addToGroups = request.QueryString["addToGroups"]; + + if (!string.IsNullOrWhiteSpace(addToGroups)) + { + var groups = addToGroups.Split(','); + foreach (var g in groups) + { + this.Groups.Add(connectionId, g); + } + } + + return base.OnConnected(request, connectionId); + } + protected override System.Threading.Tasks.Task OnReceived(IRequest request, string connectionId, string data) { // Add to Group diff --git a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml index c86606a5..1a031161 100644 --- a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml +++ b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml @@ -3,15 +3,13 @@ Html.BundleDeferred("~/ClientScripts/Modules/Knockout"); Html.BundleDeferred("~/ClientScripts/Modules/jQuery-SignalR"); } -

- Documents Imported Today +

Documents Imported Today

-

- No imported documents today

+

No imported documents today

- -
-
+
+
-

-

+

Disco QR-Code not found
- Manually Assign Page + Manually Assign Page
- Document: - + Document:
- Target: - + Target:

@@ -58,11 +53,9 @@ - - @@ -75,11 +68,9 @@
-   +   - Message + Message
- - + @@ -309,13 +300,11 @@ ko.applyBindings(vm); // Init Persistent Connection - liveConnection = $.connection('@(Url.Content("~/API/Logging/Notifications"))'); + liveConnection = $.connection('@(Url.Content("~/API/Logging/Notifications"))', { addToGroups: '@(Disco.BI.DocumentTemplateBI.Importer.DocumentImporterLog.Current.LiveLogGroupName)' }); liveConnection.received(parseLog); liveConnection.error(function (e) { if (e.status != 200) alert('Live-Log Error: ' + e.statusText + ': ' + e.responseText); }); isLive = true; - liveConnection.start(function () { - liveConnection.send('/addToGroups:@(Disco.BI.DocumentTemplateBI.Importer.DocumentImporterLog.Current.LiveLogGroupName)'); - }); + liveConnection.start(); } init(); }); diff --git a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs index 402d6e7f..6c833d70 100644 --- a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs +++ b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs @@ -50,7 +50,7 @@ namespace Disco.Web.Areas.Config.Views.DocumentTemplate #line default #line hidden -WriteLiteral("\r\n

\r\n Documents Imported Today\r\n

\r\nDocuments Imported Today\r\n\r\n\r\n

\r\n No imported documents today

\r\n
\r\n \r\n

No imported documents today

\r\n
\r\n \r\n
\r\n
\r\n WriteLiteral(" class=\"sessionPages clearfix\""); -WriteLiteral(" data-bind=\"foreach: {data: sessionPages}\""); +WriteLiteral(" data-bind=\"foreach: { data: sessionPages }\""); WriteLiteral(">\r\n \r\n \r\n \r\n \r\n \r\n \r\n Disco QR-Code not found
\r\n WriteLiteral(" target=\"_blank\""); -WriteLiteral(" data-bind=\"attr: {href: manuallyAssignUrl}, visible: $parent.sessionEnded\""); +WriteLiteral(" data-bind=\"attr: { href: manuallyAssignUrl }, visible: $parent.sessionEnded\""); WriteLiteral(">Manually Assign Page\r\n
\r\n " + " \r\n Document: \r\n \r\n
\r\n " + -" Target: \r\n
\r\n Target: \r\n \r\n
\r\n " + -" \r\n
\r\n \r\n \r\n \r WriteLiteral(" class=\"icon\""); -WriteLiteral(">\r\n  \r\n \r\n " + -"  \r\n \r\n \r\n Message\r\n \r\n " + -" \r\n \r\n \r\n Message\r\n \r\n \r\n " + +" \r\n \r\n \r\n \r\n WriteLiteral(" class=\"icon\""); -WriteLiteral(" data-bind=\"attr: {title: FormattedTimestamp}, css: {information: EventTypeSeveri" + -"ty == 0, warning: EventTypeSeverity == 1, error: EventTypeSeverity == 2}\""); +WriteLiteral(" data-bind=\"attr: { title: FormattedTimestamp }, css: { information: EventTypeSev" + +"erity == 0, warning: EventTypeSeverity == 1, error: EventTypeSeverity == 2 }\""); -WriteLiteral(">\r\n  \r\n \r\n  \r\n \r\n <" + +"td"); WriteLiteral(" class=\"message\""); -WriteLiteral(" data-bind=\"text: FormattedMessage, attr: {title: EventTypeName}\""); +WriteLiteral(" data-bind=\"text: FormattedMessage, attr: { title: EventTypeName }\""); -WriteLiteral(">\r\n \r\n \r\n " + -" \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\n \r\n " + +" \r\n \r\n \r\n \r\n \r\n\r\n\r\n $(function () {\r\n var vm;\r\n var host = " var urlDeviceShow = \'"); - #line 111 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 102 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Action(MVC.Device.Show())); @@ -274,7 +270,7 @@ WriteLiteral(">\r\n $(function () {\r\n var vm;\r\n var host = WriteLiteral("/\'\r\n var urlJobShow = \'"); - #line 112 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 103 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Action(MVC.Job.Show())); @@ -283,7 +279,7 @@ WriteLiteral("/\'\r\n var urlJobShow = \'"); WriteLiteral("/\'\r\n var urlUserShow = \'"); - #line 113 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 104 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Action(MVC.User.Show())); @@ -292,7 +288,7 @@ WriteLiteral("/\'\r\n var urlUserShow = \'"); WriteLiteral("/\'\r\n var urlPageThumbnail = \'"); - #line 114 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 105 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Action(MVC.API.DocumentTemplate.ImporterThumbnail())); @@ -301,7 +297,7 @@ WriteLiteral("/\'\r\n var urlPageThumbnail = \'"); WriteLiteral("/\'\r\n var urlDocumentTemplate = \'"); - #line 115 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 106 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Action(MVC.Config.DocumentTemplate.Index())); @@ -310,7 +306,7 @@ WriteLiteral("/\'\r\n var urlDocumentTemplate = \'"); WriteLiteral("/\';\r\n var urlManuallyAssign = \'"); - #line 116 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 107 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Action(MVC.Config.DocumentTemplate.UndetectedPages())); @@ -319,7 +315,7 @@ WriteLiteral("/\';\r\n var urlManuallyAssign = \'"); WriteLiteral("\';\r\n var iconErrorUrl = \'url("); - #line 117 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 108 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Links.ClientSource.Style.Images.Status.fail32_png); @@ -427,7 +423,7 @@ WriteLiteral(")\';\r\n var isLive = false;\r\n\r\n function pageVi " url: \'"); - #line 292 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 283 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Action(MVC.API.Logging.RetrieveEvents())); @@ -456,27 +452,31 @@ WriteLiteral(@"', liveConnection = $.connection('"); - #line 312 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + #line 303 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" Write(Url.Content("~/API/Logging/Notifications")); #line default #line hidden -WriteLiteral(@"'); - liveConnection.received(parseLog); - liveConnection.error(function (e) { if (e.status != 200) alert('Live-Log Error: ' + e.statusText + ': ' + e.responseText); }); - isLive = true; - liveConnection.start(function () { - liveConnection.send('/addToGroups:"); +WriteLiteral("\', { addToGroups: \'"); - #line 317 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" - Write(Disco.BI.DocumentTemplateBI.Importer.DocumentImporterLog.Current.LiveLogGroupName); + #line 303 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" + Write(Disco.BI.DocumentTemplateBI.Importer.DocumentImporterLog.Current.LiveLogGroupName); #line default #line hidden -WriteLiteral("\');\r\n });\r\n }\r\n init();\r\n });\r\n\r\n"); +WriteLiteral(@"' }); + liveConnection.received(parseLog); + liveConnection.error(function (e) { if (e.status != 200) alert('Live-Log Error: ' + e.statusText + ': ' + e.responseText); }); + isLive = true; + liveConnection.start(); + } + init(); + }); + +"); } } diff --git a/Disco.Web/Areas/Config/Views/Enrolment/Status.cshtml b/Disco.Web/Areas/Config/Views/Enrolment/Status.cshtml index a4684032..d2eddb06 100644 --- a/Disco.Web/Areas/Config/Views/Enrolment/Status.cshtml +++ b/Disco.Web/Areas/Config/Views/Enrolment/Status.cshtml @@ -357,12 +357,10 @@ vm.isotopeInited = true; // Init Persistent Connection - liveConnection = $.connection('@(Url.Content("~/API/Logging/Notifications"))'); + liveConnection = $.connection('@(Url.Content("~/API/Logging/Notifications"))', { addToGroups: '@(Disco.BI.DeviceBI.EnrolmentLog.Current.LiveLogGroupName)' }); liveConnection.received(parseLog); liveConnection.error(function (e) { if (e.status != 200) alert('Live-Log Error: ' + e.statusText + ': ' + e.responseText); }); - liveConnection.start(function () { - liveConnection.send('/addToGroups:@(Disco.BI.DeviceBI.EnrolmentLog.Current.LiveLogGroupName)'); - }); + liveConnection.start(); } init(); }); diff --git a/Disco.Web/Areas/Config/Views/Enrolment/Status.generated.cs b/Disco.Web/Areas/Config/Views/Enrolment/Status.generated.cs index 906271cd..6e54defa 100644 --- a/Disco.Web/Areas/Config/Views/Enrolment/Status.generated.cs +++ b/Disco.Web/Areas/Config/Views/Enrolment/Status.generated.cs @@ -519,20 +519,24 @@ WriteLiteral(@"', #line default #line hidden -WriteLiteral(@"'); - liveConnection.received(parseLog); - liveConnection.error(function (e) { if (e.status != 200) alert('Live-Log Error: ' + e.statusText + ': ' + e.responseText); }); - liveConnection.start(function () { - liveConnection.send('/addToGroups:"); +WriteLiteral("\', { addToGroups: \'"); - #line 364 "..\..\Areas\Config\Views\Enrolment\Status.cshtml" - Write(Disco.BI.DeviceBI.EnrolmentLog.Current.LiveLogGroupName); + #line 360 "..\..\Areas\Config\Views\Enrolment\Status.cshtml" + Write(Disco.BI.DeviceBI.EnrolmentLog.Current.LiveLogGroupName); #line default #line hidden -WriteLiteral("\');\r\n });\r\n }\r\n init();\r\n });\r\n\r\n"); +WriteLiteral(@"' }); + liveConnection.received(parseLog); + liveConnection.error(function (e) { if (e.status != 200) alert('Live-Log Error: ' + e.statusText + ': ' + e.responseText); }); + liveConnection.start(); + } + init(); + }); + +"); } } diff --git a/Disco.Web/Areas/Config/Views/Logging/TaskStatus.cshtml b/Disco.Web/Areas/Config/Views/Logging/TaskStatus.cshtml index 139cc808..a1e4a90e 100644 --- a/Disco.Web/Areas/Config/Views/Logging/TaskStatus.cshtml +++ b/Disco.Web/Areas/Config/Views/Logging/TaskStatus.cshtml @@ -29,7 +29,7 @@ - + @@ -240,11 +240,10 @@ }); } function updateWithLive() { - liveConnection = $.connection('@(Url.Content("~/API/Logging/TaskStatusNotifications"))'); + liveConnection = $.connection('@(Url.Content("~/API/Logging/TaskStatusNotifications"))', { addToGroups: sessionId }); liveConnection.received(update_Received); liveConnection.error(function (e) { if (e.status != 200) alert('Live-Status Error: ' + e.statusText + ': ' + e.responseText); }); liveConnection.start(function () { - liveConnection.send('/addToGroups:' + sessionId); updateWithAjax(); }); } diff --git a/Disco.Web/Areas/Config/Views/Logging/TaskStatus.generated.cs b/Disco.Web/Areas/Config/Views/Logging/TaskStatus.generated.cs index 3e9642c5..fecae69c 100644 --- a/Disco.Web/Areas/Config/Views/Logging/TaskStatus.generated.cs +++ b/Disco.Web/Areas/Config/Views/Logging/TaskStatus.generated.cs @@ -122,7 +122,7 @@ WriteLiteral(">\r\n \r\n