Cleanup SignalR

This commit is contained in:
Stephan
2016-10-19 11:16:33 +02:00
parent a1c11d17ea
commit b7ef002da5
17 changed files with 132 additions and 3019 deletions

View File

@@ -18,6 +18,7 @@
<dependency id="UmbracoCms.Core" version="[$version$]" />
<dependency id="Newtonsoft.Json" version="[6.0.8, 9.0.0)" />
<dependency id="Umbraco.ModelsBuilder" version="[3.0.0, 9.0.0)" />
<dependency id="Microsoft.AspNet.SignalR.Core" version="[2.2.1, 3.0.0)" />
</dependencies>
</metadata>
<files>

View File

@@ -16,6 +16,7 @@
"tests"
],
"dependencies": {
"signalr": "^2.2.1",
"typeahead.js": "~0.10.5",
"underscore": "~1.7.0",
"rgrove-lazyload": "*",

View File

@@ -12,10 +12,9 @@ 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',
'../lib/signalr/jquery.signalR.js',
'/umbraco/signalr/hubs',
'../js/canvasdesigner.panel.js'
], function () {
jQuery(document).ready(function () {
angular.bootstrap(document, ['Umbraco.canvasdesigner']);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -637,8 +637,6 @@
<None Include="Scripts\jquery-1.6.4-vsdoc.js" />
<Content Include="Scripts\jquery-1.6.4.js" />
<Content Include="Scripts\jquery-1.6.4.min.js" />
<Content Include="Scripts\jquery.signalR-2.2.0.js" />
<Content Include="Scripts\jquery.signalR-2.2.0.min.js" />
<Content Include="Umbraco\Config\Lang\cs.xml" />
<Content Include="Umbraco\Install\Legacy\loadStarterKits.ascx" />
<Content Include="Umbraco\ClientRedirect.aspx" />

View File

@@ -15,7 +15,6 @@
<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.JS" 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" />

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Logging;
using Owin;
using Umbraco.Core.Logging;
using Umbraco.Web.SignalR;
namespace Umbraco.Web
{
/// <summary>
/// Provides general extension methods to IAppBuilder.
/// </summary>
public static class AppBuilderExtensions
{
/// <summary>
/// Called at the end of configuring middleware
/// </summary>
/// <param name="app">The app builder.</param>
/// <remarks>
/// This could be used for something else in the future - maybe to inform Umbraco that middleware is done/ready, but for
/// now this is used to raise the custom event
///
/// This is an extension method in case developer entirely replace the UmbracoDefaultOwinStartup class, in which case they will
/// need to ensure they call this extension method in their startup class.
/// </remarks>
public static void FinalizeMiddlewareConfiguration(this IAppBuilder app)
{
UmbracoDefaultOwinStartup.OnMiddlewareConfigured(new OwinMiddlewareConfiguredEventArgs(app));
}
/// <summary>
/// Sets the OWIN logger to use Umbraco's logging system.
/// </summary>
/// <param name="app">The app builder.</param>
public static void SetUmbracoLoggerFactory(this IAppBuilder app)
{
app.SetLoggerFactory(new OwinLoggerFactory());
}
/// <summary>
/// Configures SignalR.
/// </summary>
/// <param name="app">The app builder.</param>
public static void ConfigureSignalR(this IAppBuilder app)
{
app.MapSignalR("/umbraco/signalr", new HubConfiguration { EnableDetailedErrors = true });
}
}
}

View File

@@ -10,7 +10,6 @@ using Microsoft.Owin.Security.Cookies;
using Owin;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Identity;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
@@ -18,38 +17,11 @@ using Constants = Umbraco.Core.Constants;
namespace Umbraco.Web.Security.Identity
{
/// <summary>
/// Provides security/identity extension methods to IAppBuilder.
/// </summary>
public static class AppBuilderExtensions
{
/// <summary>
/// Called at the end of configuring middleware
/// </summary>
/// <param name="app"></param>
/// <remarks>
/// This could be used for something else in the future - maybe to inform Umbraco that middleware is done/ready, but for
/// now this is used to raise the custom event
///
/// This is an extension method in case developer entirely replace the UmbracoDefaultOwinStartup class, in which case they will
/// need to ensure they call this extension method in their startup class.
///
/// TODO: Move this method in v8, it doesn't belong in this namespace/extension class
/// </remarks>
public static void FinalizeMiddlewareConfiguration(this IAppBuilder app)
{
UmbracoDefaultOwinStartup.OnMiddlewareConfigured(new OwinMiddlewareConfiguredEventArgs(app));
}
/// <summary>
/// Sets the OWIN logger to use Umbraco's logging system
/// </summary>
/// <param name="app"></param>
/// <remarks>
/// TODO: Move this method in v8, it doesn't belong in this namespace/extension class
/// </remarks>
public static void SetUmbracoLoggerFactory(this IAppBuilder app)
{
app.SetLoggerFactory(new OwinLoggerFactory());
}
/// <summary>
/// Configure Default Identity User Manager for Umbraco
/// </summary>

View File

@@ -0,0 +1,12 @@
namespace Umbraco.Web.SignalR
{
public interface IPreviewHub
{
// define methods implemented by client
// ReSharper disable InconsistentNaming
void refreshed(int id);
// ReSharper restore InconsistentNaming
}
}

View File

@@ -1,33 +1,7 @@
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);
}
};
}
}
public class PreviewHub : Hub<IPreviewHub>
{ }
}

View File

@@ -0,0 +1,47 @@
using System;
using LightInject;
using Microsoft.AspNet.SignalR;
using Umbraco.Core;
using Umbraco.Core.Components;
using Umbraco.Core.Sync;
using Umbraco.Web.Cache;
namespace Umbraco.Web.SignalR
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class PreviewHubComponent : UmbracoComponentBase, IUmbracoCoreComponent
{
public override void Compose(Composition composition)
{
base.Compose(composition);
composition.Container.Register(_ => GlobalHost.ConnectionManager.GetHubContext<PreviewHub, IPreviewHub>(), new PerContainerLifetime());
}
// using a lazy arg here means that we won't create the hub until necessary
// and therefore we won't have too bad an impact on boot time
public void Initialize(Lazy<IHubContext<IPreviewHub>> 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;
var hubContextInstance = hubContext.Value;
foreach (var payload in payloads)
{
var id = payload.Id; // keep it simple for now, ignore ChangeTypes
hubContextInstance.Clients.All.refreshed(id);
}
};
}
}
}

View File

@@ -156,6 +156,7 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="AppBuilderExtensions.cs" />
<Compile Include="AreaRegistrationContextExtensions.cs" />
<Compile Include="AspNetHttpContextAccessor.cs" />
<Compile Include="Cache\ContentCacheRefresher.cs" />
@@ -277,7 +278,9 @@
<Compile Include="Routing\IContentLastChanceFinder.cs" />
<Compile Include="Routing\UrlProviderCollection.cs" />
<Compile Include="Routing\UrlProviderCollectionBuilder.cs" />
<Compile Include="SignalR\IPreviewHub.cs" />
<Compile Include="SignalR\PreviewHub.cs" />
<Compile Include="SignalR\PreviewHubComponent.cs" />
<Compile Include="Strategies\LegacyServerRegistrarAndMessengerComponent.cs" />
<Compile Include="Strategies\Migrations\IPostMigration.cs" />
<Compile Include="Strategies\Migrations\PostMigrationCollection.cs" />

View File

@@ -35,7 +35,6 @@ namespace Umbraco.Web
ConfigureServices(app, Current.Services);
ConfigureMiddleware(app);
ConfigureSignalR(app);
}
/// <summary>
@@ -52,6 +51,8 @@ namespace Umbraco.Web
app.ConfigureUserManagerForUmbracoBackOffice(
services,
Core.Security.MembershipProviderExtensions.GetUsersMembershipProvider().AsUmbracoMembershipProvider());
app.ConfigureSignalR();
}
/// <summary>
@@ -69,20 +70,6 @@ namespace Umbraco.Web
.FinalizeMiddlewareConfiguration();
}
private IHubContext _previewHubContext;
/// <summary>
/// Configures SignalR.
/// </summary>
/// <param name="app"></param>
protected virtual void ConfigureSignalR(IAppBuilder app)
{
app.MapSignalR();
_previewHubContext = GlobalHost.ConnectionManager.GetHubContext<PreviewHub>();
PreviewHub.Initialize(_previewHubContext);
}
public static event EventHandler<OwinMiddlewareConfiguredEventArgs> MiddlewareConfigured;
internal static void OnMiddlewareConfigured(OwinMiddlewareConfiguredEventArgs args)

View File

@@ -11,6 +11,7 @@ using System.Web.Mvc;
using System.Web.Routing;
using ClientDependency.Core.Config;
using LightInject;
using Microsoft.AspNet.SignalR;
using Umbraco.Core;
using Umbraco.Core.Components;
using Umbraco.Core.Configuration;
@@ -36,6 +37,7 @@ using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using Umbraco.Web.Services;
using Umbraco.Web.SignalR;
using Umbraco.Web.UI.JavaScript;
using Umbraco.Web.WebApi;
using Umbraco.Web._Legacy.Actions;
@@ -171,6 +173,9 @@ namespace Umbraco.Web
// register facade router
composition.Container.Register<FacadeRouter>();
composition.Container.Register(_ => UmbracoConfig.For.UmbracoSettings().WebRouting);
// register preview SignalR hub
composition.Container.Register(_ => GlobalHost.ConnectionManager.GetHubContext<PreviewHub>(), new PerContainerLifetime());
}
internal void Initialize(

View File

@@ -19,7 +19,6 @@
"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",

View File

@@ -2,7 +2,6 @@
using System.Web;
using Umbraco.Web;
using Umbraco.Core;
using Umbraco.Web.PublishedCache;
namespace umbraco.presentation.dialogs
{