Feature - live SignalR preview
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<StephansHub>();
|
||||
|
||||
ContentService.Published += (sender, args) =>
|
||||
{
|
||||
var entity = args.PublishedEntities.FirstOrDefault();
|
||||
if (entity != null)
|
||||
{
|
||||
_hub.Clients.All.someEventName(sender.GetType().Name.ToString(), entity.Name);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using Microsoft.AspNet.SignalR;
|
||||
|
||||
namespace Umbraco.Web.UI
|
||||
{
|
||||
public class StephansHub : Hub
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -196,14 +196,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Identity.Owin.2.2.1\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNet.SignalR.Core">
|
||||
<HintPath>..\packages\Microsoft.AspNet.SignalR.Core.2.2.0\lib\net45\Microsoft.AspNet.SignalR.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNet.SignalR.SystemWeb">
|
||||
<HintPath>..\packages\Microsoft.AspNet.SignalR.SystemWeb.2.2.0\lib\net45\Microsoft.AspNet.SignalR.SystemWeb.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -387,8 +379,6 @@
|
||||
<Compile Include="..\SolutionInfo.cs">
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="SignalRStartup.cs" />
|
||||
<Compile Include="StephansHub.cs" />
|
||||
<Compile Include="Umbraco\Install\Legacy\LoadStarterKits.ascx.cs">
|
||||
<DependentUpon>loadStarterKits.ascx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
@@ -558,7 +548,6 @@
|
||||
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.controller.js" />
|
||||
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.htm" />
|
||||
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.resource.js" />
|
||||
<Content Include="client.html" />
|
||||
<Content Include="Config\grid.editors.config.js" />
|
||||
<Content Include="Config\Lang\cs-CZ.user.xml" />
|
||||
<Content Include="Config\Lang\da-DK.user.xml" />
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>signalr</title>
|
||||
<meta charset="utf-8"/>
|
||||
<script src="/Scripts/jquery-1.6.4.min.js"></script>
|
||||
<script src="/Scripts/jquery.signalR-2.2.0.min.js"></script>
|
||||
<script src="/signalr/hubs"></script>
|
||||
|
||||
<script>
|
||||
var stephansHub = $.connection.stephansHub;
|
||||
stephansHub.client.someEventName = function(message, sender) {
|
||||
var li = $('<li>' + message + ' (' + sender + ')</li>');
|
||||
$('ul').append(li);
|
||||
};
|
||||
$.connection.hub.start()
|
||||
.done(function() { console.log('Now connected, connection ID=' + $.connection.hub.id); })
|
||||
.fail(function() { console.log('Could not connect!'); });
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h3>events:</h3>
|
||||
<ul>
|
||||
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,8 +2,8 @@
|
||||
<packages>
|
||||
<package id="AutoMapper" version="4.2.1" targetFramework="net461" />
|
||||
<package id="ClientDependency" version="1.9.0-beta4" targetFramework="net45" />
|
||||
<package id="CSharpTest.Net.Collections" version="14.906.1403.1082" targetFramework="net461" />
|
||||
<package id="ClientDependency-Mvc5" version="1.8.0.0" targetFramework="net45" />
|
||||
<package id="CSharpTest.Net.Collections" version="14.906.1403.1082" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta2" targetFramework="net461" />
|
||||
<package id="ImageProcessor" version="2.4.1.0" targetFramework="net45" />
|
||||
<package id="ImageProcessor.Web" version="4.6.1.0" targetFramework="net45" />
|
||||
@@ -15,9 +15,7 @@
|
||||
<package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.SignalR.Core" version="2.2.0" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.SignalR.JS" version="2.2.0" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.SignalR.SystemWeb" version="2.2.0" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
|
||||
|
||||
33
src/Umbraco.Web/SignalR/PreviewHub.cs
Normal file
33
src/Umbraco.Web/SignalR/PreviewHub.cs
Normal file
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,6 +254,7 @@
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\XmlStore.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\XmlStoreFilePersister.cs" />
|
||||
<Compile Include="Routing\Domain.cs" />
|
||||
<Compile Include="SignalR\PreviewHub.cs" />
|
||||
<Compile Include="Trees\RelationTypeTreeController.cs" />
|
||||
<Compile Include="Trees\MacrosTreeController.cs" />
|
||||
<Compile Include="Models\ContentEditing\MemberGroupDisplay.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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the middelware has been configured
|
||||
/// </summary>
|
||||
public static event EventHandler<OwinMiddlewareConfiguredEventArgs> MiddlewareConfigured;
|
||||
private IHubContext _previewHubContext;
|
||||
|
||||
protected virtual ApplicationContext ApplicationContext
|
||||
/// <summary>
|
||||
/// Configures SignalR.
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
protected virtual void ConfigureSignalR(IAppBuilder app)
|
||||
{
|
||||
get { return ApplicationContext.Current; }
|
||||
app.MapSignalR();
|
||||
|
||||
_previewHubContext = GlobalHost.ConnectionManager.GetHubContext<PreviewHub>();
|
||||
PreviewHub.Initialize(_previewHubContext);
|
||||
}
|
||||
|
||||
protected virtual ApplicationContext ApplicationContext => ApplicationContext.Current;
|
||||
|
||||
public static event EventHandler<OwinMiddlewareConfiguredEventArgs> MiddlewareConfigured;
|
||||
|
||||
internal static void OnMiddlewareConfigured(OwinMiddlewareConfiguredEventArgs args)
|
||||
{
|
||||
var handler = MiddlewareConfigured;
|
||||
if (handler != null) handler(null, args);
|
||||
MiddlewareConfigured?.Invoke(null, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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": {}
|
||||
|
||||
Reference in New Issue
Block a user