diff --git a/src/Umbraco.Web.UI.Client/src/canvasdesigner.loader.js b/src/Umbraco.Web.UI.Client/src/canvasdesigner.loader.js index 59d5a4bef5..bf3ca601da 100644 --- a/src/Umbraco.Web.UI.Client/src/canvasdesigner.loader.js +++ b/src/Umbraco.Web.UI.Client/src/canvasdesigner.loader.js @@ -1,7 +1,8 @@ LazyLoad.js([ '../lib/jquery/jquery.min.js', - '../lib/jquery-ui/jquery-ui.min.js', + //'../lib/jquery-ui/jquery-ui.min.js', + '/Scripts/jquery-1.6.4.min.js', '../lib/angular/1.1.5/angular.min.js', '../lib/underscore/underscore-min.js', '../lib/umbraco/Extensions.js', @@ -11,6 +12,8 @@ LazyLoad.js([ '../js/umbraco.security.js', '../ServerVariables', '../lib/spectrum/spectrum.js', + '/Scripts/jquery.signalR-2.2.0.min.js', + '/signalr/hubs', '../js/canvasdesigner.panel.js', ], function () { diff --git a/src/Umbraco.Web.UI.Client/src/canvasdesigner/canvasdesigner.controller.js b/src/Umbraco.Web.UI.Client/src/canvasdesigner/canvasdesigner.controller.js index d23fdcbf84..1a1ad6b325 100644 --- a/src/Umbraco.Web.UI.Client/src/canvasdesigner/canvasdesigner.controller.js +++ b/src/Umbraco.Web.UI.Client/src/canvasdesigner/canvasdesigner.controller.js @@ -482,6 +482,26 @@ var app = angular.module("Umbraco.canvasdesigner", ['colorpicker', 'ui.slider', }, 100); }, true); + // signalr hub + var previewHub = $.connection.previewHub; + + previewHub.client.refreshed = function (message, sender) { + console.log("Notified by SignalR preview hub (" + message+ ")."); + + if ($scope.pageId != message) { + console.log("Not a notification for us (" + $scope.pageId + ")."); + return; + } + + var resultFrame = document.getElementById("resultFrame"); + var iframe = (resultFrame.contentWindow || resultFrame.contentDocument); + //setTimeout(function() { iframe.location.reload(); }, 1000); + iframe.location.reload(); + }; + + $.connection.hub.start() + .done(function () { console.log("Connected to SignalR preview hub (ID=" + $.connection.hub.id + ")"); }) + .fail(function () { console.log("Could not connect to SignalR preview hub."); }); }) .directive('onFinishRenderFilters', function ($timeout) { diff --git a/src/Umbraco.Web.UI/SignalRStartup.cs b/src/Umbraco.Web.UI/SignalRStartup.cs deleted file mode 100644 index 310b3253bd..0000000000 --- a/src/Umbraco.Web.UI/SignalRStartup.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Linq; -using Microsoft.AspNet.SignalR; -using Microsoft.Owin; -using Owin; -using Umbraco.Core.Services; - -[assembly: OwinStartup("SignalRStartup", typeof(Umbraco.Web.UI.SignalRStartup))] -namespace Umbraco.Web.UI -{ - public class SignalRStartup : UmbracoDefaultOwinStartup - { - private IHubContext _hub; - - public void Configuration(IAppBuilder app) - { - base.Configuration(app); - - app.MapSignalR(); - - _hub = GlobalHost.ConnectionManager.GetHubContext(); - - ContentService.Published += (sender, args) => - { - var entity = args.PublishedEntities.FirstOrDefault(); - if (entity != null) - { - _hub.Clients.All.someEventName(sender.GetType().Name.ToString(), entity.Name); - } - }; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web.UI/StephansHub.cs b/src/Umbraco.Web.UI/StephansHub.cs deleted file mode 100644 index 1c27600c65..0000000000 --- a/src/Umbraco.Web.UI/StephansHub.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Microsoft.AspNet.SignalR; - -namespace Umbraco.Web.UI -{ - public class StephansHub : Hub - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index ce883534ba..cdee47e84f 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -196,14 +196,6 @@ False ..\packages\Microsoft.AspNet.Identity.Owin.2.2.1\lib\net45\Microsoft.AspNet.Identity.Owin.dll - - ..\packages\Microsoft.AspNet.SignalR.Core.2.2.0\lib\net45\Microsoft.AspNet.SignalR.Core.dll - True - - - ..\packages\Microsoft.AspNet.SignalR.SystemWeb.2.2.0\lib\net45\Microsoft.AspNet.SignalR.SystemWeb.dll - True - ..\packages\Microsoft.CodeAnalysis.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.dll True @@ -387,8 +379,6 @@ Properties\SolutionInfo.cs - - loadStarterKits.ascx ASPXCodeBehind @@ -558,7 +548,6 @@ - diff --git a/src/Umbraco.Web.UI/client.html b/src/Umbraco.Web.UI/client.html deleted file mode 100644 index 0e347003c2..0000000000 --- a/src/Umbraco.Web.UI/client.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - signalr - - - - - - - - -

events:

-
    - -
- - diff --git a/src/Umbraco.Web.UI/packages.config b/src/Umbraco.Web.UI/packages.config index 7ad8f362a9..0c3b2ef71e 100644 --- a/src/Umbraco.Web.UI/packages.config +++ b/src/Umbraco.Web.UI/packages.config @@ -2,8 +2,8 @@ - + @@ -15,9 +15,7 @@ - - diff --git a/src/Umbraco.Web/SignalR/PreviewHub.cs b/src/Umbraco.Web/SignalR/PreviewHub.cs new file mode 100644 index 0000000000..9ccafc389f --- /dev/null +++ b/src/Umbraco.Web/SignalR/PreviewHub.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNet.SignalR; +using Umbraco.Core.Sync; +using Umbraco.Web.Cache; + +namespace Umbraco.Web.SignalR +{ + public class PreviewHub : Hub + { + internal static void Initialize(IHubContext hubContext) + { + // ContentService.Saved is too soon - the content cache is not ready yet + // try using the content cache refresher event, because when it triggers + // the cache has already been notified of the changes + //ContentService.Saved += (sender, args) => + //{ + // var entity = args.SavedEntities.FirstOrDefault(); + // if (entity != null) + // _previewHub.Clients.All.refreshed(entity.Id); + //}; + + ContentCacheRefresher.CacheUpdated += (sender, args) => + { + if (args.MessageType != MessageType.RefreshByPayload) return; + var payloads = (ContentCacheRefresher.JsonPayload[]) args.MessageObject; + foreach (var payload in payloads) + { + var id = payload.Id; // keep it simple for now, ignore ChangeTypes + hubContext.Clients.All.refreshed(id); + } + }; + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index dd1392fd28..ca95cfddbf 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -254,6 +254,7 @@ + diff --git a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs index 046b2167d5..addcfea651 100644 --- a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs +++ b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs @@ -1,5 +1,7 @@ using System; +using System.Linq; using System.Web; +using Microsoft.AspNet.SignalR; using Microsoft.Owin; using Microsoft.Owin.Extensions; using Microsoft.Owin.Logging; @@ -7,8 +9,12 @@ using Owin; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Security; +using Umbraco.Core.Services; +using Umbraco.Core.Sync; using Umbraco.Web; +using Umbraco.Web.Cache; using Umbraco.Web.Security.Identity; +using Umbraco.Web.SignalR; [assembly: OwinStartup("UmbracoDefaultOwinStartup", typeof(UmbracoDefaultOwinStartup))] @@ -32,6 +38,7 @@ namespace Umbraco.Web ConfigureServices(app); ConfigureMiddleware(app); + ConfigureSignalR(app); } /// @@ -42,7 +49,7 @@ namespace Umbraco.Web { app.SetUmbracoLoggerFactory(); - //Configure the Identity user manager for use with Umbraco Back office + //Configure the Identity user manager for use with Umbraco Back office // (EXPERT: an overload accepts a custom BackOfficeUserStore implementation) app.ConfigureUserManagerForUmbracoBackOffice( ApplicationContext, @@ -64,20 +71,27 @@ namespace Umbraco.Web .FinalizeMiddlewareConfiguration(); } - /// - /// Raised when the middelware has been configured - /// - public static event EventHandler MiddlewareConfigured; + private IHubContext _previewHubContext; - protected virtual ApplicationContext ApplicationContext + /// + /// Configures SignalR. + /// + /// + protected virtual void ConfigureSignalR(IAppBuilder app) { - get { return ApplicationContext.Current; } + app.MapSignalR(); + + _previewHubContext = GlobalHost.ConnectionManager.GetHubContext(); + PreviewHub.Initialize(_previewHubContext); } + protected virtual ApplicationContext ApplicationContext => ApplicationContext.Current; + + public static event EventHandler MiddlewareConfigured; + internal static void OnMiddlewareConfigured(OwinMiddlewareConfiguredEventArgs args) { - var handler = MiddlewareConfigured; - if (handler != null) handler(null, args); + MiddlewareConfigured?.Invoke(null, args); } } } diff --git a/src/Umbraco.Web/project.json b/src/Umbraco.Web/project.json index 88c0b263cc..f2ba6dd674 100644 --- a/src/Umbraco.Web/project.json +++ b/src/Umbraco.Web/project.json @@ -2,6 +2,7 @@ "dependencies": { "AutoMapper": "4.2.*", "ClientDependency": "1.8.*", + "CSharpTest.Net.Collections": "14.906.1403.1082", "dotless": "1.4.1.0", "Examine": "2.0.0-beta2", "HtmlAgilityPack": "1.4.9.5", @@ -17,6 +18,8 @@ "Microsoft.AspNet.Identity.Owin": "2.2.1", "Microsoft.AspNet.Mvc": "5.2.3", "Microsoft.AspNet.Razor": "3.2.3", + "Microsoft.AspNet.SignalR.Core": "2.2.0", + "Microsoft.AspNet.SignalR.SystemWeb": "2.2.0", "Microsoft.AspNet.WebApi": "5.2.3", "Microsoft.AspNet.WebApi.Client": "5.2.3", "Microsoft.AspNet.WebApi.Core": "5.2.3", @@ -35,8 +38,7 @@ "semver": "1.*", "SharpZipLib": "0.86.0", "UrlRewritingNet.UrlRewriter": "2.0.7", - "xmlrpcnet": "2.5.0", - "CSharpTest.Net.Collections": "14.906.1403.1082" + "xmlrpcnet": "2.5.0" }, "frameworks": { "net461": {}