Skip to content

Commit

Permalink
Fix #205 - allow config to overwrite where the signalR hub is.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Mar 4, 2021
1 parent fde7fb7 commit 11e6f0a
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 67 deletions.
11 changes: 8 additions & 3 deletions uSync8.BackOffice/App_Plugins/uSync8/settings/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@
</umb-box>


<umb-box>
<umb-box-content ng-if="vm.working || vm.reported">
<umb-box ng-if="!vm.showSpinner && (vm.working || vm.reported)">
<umb-box-content>
<usync-progress-view update="vm.update"
status="vm.status"
hide-labels="false">
</usync-progress-view>
</umb-box-content>
</umb-box>

<div ng-if="vm.showSpinner && vm.working">
<umb-load-indicator></umb-load-indicator>
</div>


<div ng-if="vm.warnings.Message.length > 0" class="alert alert-{{vm.warnings.Type}}">
<span ng-bind-html="vm.warnings.Message"></span>

</div>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
vm.reported = false;
vm.syncing = false;
vm.hideLink = false;
vm.showSpinner = false;

vm.showAdvanced = false;

Expand Down Expand Up @@ -317,6 +318,7 @@

vm.reported = vm.showAll = false;
vm.working = true;
vm.showSpinner = false;
vm.runmode = mode;
vm.hideLink = false;
vm.savings.show = false;
Expand All @@ -328,6 +330,11 @@
Handlers: vm.handlers
};

if (!vm.hub.active) {
vm.status.Message = 'Working ';
vm.showSpinner = true;
}

vm.update = {
Message: '',
Count: 0,
Expand Down
49 changes: 30 additions & 19 deletions uSync8.BackOffice/App_Plugins/uSync8/uSyncHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

var scripts = [
Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/lib/signalr/jquery.signalR.js',
Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/backoffice/signalr/hubs'];
Umbraco.Sys.ServerVariables.uSync.signalRHub];

var resource = {
initHub: initHub
Expand Down Expand Up @@ -62,30 +62,41 @@
function hubSetup(callback) {
var proxy = $.connection.uSyncHub;

var hub = {
start: function () {
$.connection.hub.start();
},
on: function (eventName, callback) {
proxy.on(eventName, function (result) {
$rootScope.$apply(function () {
if (callback) {
callback(result);
}
});
});
},
invoke: function (methodName, callback) {
proxy.invoke(methodName)
.done(function (result) {
var hub = {};
if (proxy !== undefined) {
hub = {
active: true,
start: function () {
$.connection.hub.start();
},
on: function (eventName, callback) {
proxy.on(eventName, function (result) {
$rootScope.$apply(function () {
if (callback) {
callback(result);
}
});
});
}
};
},
invoke: function (methodName, callback) {
proxy.invoke(methodName)
.done(function (result) {
$rootScope.$apply(function () {
if (callback) {
callback(result);
}
});
});
}
};
}
else {
hub = {
on: function () { },
invoke: function () { },
start: function () { console.log('no hub to start - missing signalR library ?'); }
};
}

return callback(hub);
}
Expand Down
4 changes: 4 additions & 0 deletions uSync8.BackOffice/Configuration/BackOfficeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public uSyncSettings LoadSettings()

settings.CacheFolderKeys = node.Element("CacheFolderKeys").ValueOrDefault(true);

settings.SignalRRoot = ValueFromWebConfigOrDefault("SignalRRoot", node.Element("SignalRRoot")
.ValueOrDefault("backoffice/signalr/hubs"))
.TrimStart(new[] { '/' });


settings.DefaultHandlerSettings = LoadKeyValueSettings(node.Element("HandlerDefaults"));

Expand Down
5 changes: 5 additions & 0 deletions uSync8.BackOffice/Configuration/uSyncSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public HandlerSet DefaultHandlerSet()
/// options you can set at the top level, that are then set on all handlers.
/// </summary>
public IDictionary<string, string> DefaultHandlerSettings { get; set; }

/// <summary>
/// location of SignalR hub script (/
/// </summary>
public string SignalRRoot { get; set; }
}

public class HandlerSet
Expand Down
30 changes: 19 additions & 11 deletions uSync8.BackOffice/uSyncBackofficeComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Web;
using Umbraco.Web.JavaScript;
Expand All @@ -25,21 +26,27 @@ public class uSyncBackofficeComponent : IComponent
private readonly SyncHandlerFactory handlerFactory;

private readonly SyncFileService syncFileService;
private readonly uSyncSettings globalSettings;
private readonly uSyncSettings uSyncSettings;
private readonly uSyncService uSyncService;
private readonly IRuntimeState runtimeState;

private readonly IUmbracoContextFactory umbracoContextFactory;

private readonly string UmbracoMvcArea;

public uSyncBackofficeComponent(
IGlobalSettings globalSettings,
uSyncConfig uSyncConfig,
SyncHandlerFactory handlerFactory,
IProfilingLogger logger,
SyncFileService fileService,
uSyncService uSyncService,
IRuntimeState runtimeState,
IUmbracoContextFactory umbracoContextFactory)
{
globalSettings = Current.Configs.uSync();
uSyncSettings = uSyncConfig.Settings;

UmbracoMvcArea = globalSettings.GetUmbracoMvcArea();

this.runtimeState = runtimeState;
this.logger = logger;
Expand Down Expand Up @@ -85,7 +92,8 @@ private void ServerVariablesParser_Parsing(object sender, Dictionary<string, obj

e.Add("uSync", new Dictionary<string, object>
{
{ "uSyncService", urlHelper.GetUmbracoApiServiceBaseUrl<uSyncDashboardApiController>(controller => controller.GetApi()) }
{ "uSyncService", urlHelper.GetUmbracoApiServiceBaseUrl<uSyncDashboardApiController>(controller => controller.GetApi()) },
{ "signalRHub", UriUtility.ToAbsolute($"~/{UmbracoMvcArea}/{uSyncSettings.SignalRRoot}") }
});
}

Expand All @@ -99,28 +107,28 @@ private void InitBackOffice()
using (var reference = umbracoContextFactory.EnsureUmbracoContext())
{

if (globalSettings.ExportAtStartup || (globalSettings.ExportOnSave && !syncFileService.RootExists(globalSettings.RootFolder)))
if (uSyncSettings.ExportAtStartup || (uSyncSettings.ExportOnSave && !syncFileService.RootExists(uSyncSettings.RootFolder)))
{
logger.Info<uSyncBackofficeComponent>("uSync: Running Export at startup");
uSyncService.Export(globalSettings.RootFolder, default(SyncHandlerOptions));
uSyncService.Export(uSyncSettings.RootFolder, default(SyncHandlerOptions));
}

if (globalSettings.ImportAtStartup)
if (uSyncSettings.ImportAtStartup)
{
logger.Info<uSyncBackofficeComponent>("uSync: Running Import at startup");

if (!HasStopFile(globalSettings.RootFolder))
if (!HasStopFile(uSyncSettings.RootFolder))
{
uSyncService.Import(globalSettings.RootFolder, false, default(SyncHandlerOptions));
ProcessOnceFile(globalSettings.RootFolder);
uSyncService.Import(uSyncSettings.RootFolder, false, default(SyncHandlerOptions));
ProcessOnceFile(uSyncSettings.RootFolder);
}
else
{
logger.Info<uSyncBackofficeComponent>("Startup Import blocked by usync.stop file");
}
}

if (globalSettings.ExportOnSave)
if (uSyncSettings.ExportOnSave)
{
var handlers = handlerFactory
.GetValidHandlers(new SyncHandlerOptions(handlerFactory.DefaultSet, HandlerActions.Save))
Expand Down Expand Up @@ -149,7 +157,7 @@ private void InitBackOffice()
public void Terminate()
{
logger.Debug<uSyncBackofficeComponent>("Terminiating Component");
if (globalSettings.ExportOnSave)
if (uSyncSettings.ExportOnSave)
{
var handlers = handlerFactory
.GetValidHandlers(new SyncHandlerOptions(handlerFactory.DefaultSet, HandlerActions.Save))
Expand Down
11 changes: 8 additions & 3 deletions uSync8.Site/App_Plugins/uSync8/settings/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@
</umb-box>


<umb-box>
<umb-box-content ng-if="vm.working || vm.reported">
<umb-box ng-if="!vm.showSpinner && (vm.working || vm.reported)">
<umb-box-content>
<usync-progress-view update="vm.update"
status="vm.status"
hide-labels="false">
</usync-progress-view>
</umb-box-content>
</umb-box>

<div ng-if="vm.showSpinner && vm.working">
<umb-load-indicator></umb-load-indicator>
</div>


<div ng-if="vm.warnings.Message.length > 0" class="alert alert-{{vm.warnings.Type}}">
<span ng-bind-html="vm.warnings.Message"></span>

</div>


Expand Down
7 changes: 7 additions & 0 deletions uSync8.Site/App_Plugins/uSync8/settings/uSyncController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
vm.reported = false;
vm.syncing = false;
vm.hideLink = false;
vm.showSpinner = false;

vm.showAdvanced = false;

Expand Down Expand Up @@ -317,6 +318,7 @@

vm.reported = vm.showAll = false;
vm.working = true;
vm.showSpinner = false;
vm.runmode = mode;
vm.hideLink = false;
vm.savings.show = false;
Expand All @@ -328,6 +330,11 @@
Handlers: vm.handlers
};

if (!vm.hub.active) {
vm.status.Message = 'Working ';
vm.showSpinner = true;
}

vm.update = {
Message: '',
Count: 0,
Expand Down
49 changes: 30 additions & 19 deletions uSync8.Site/App_Plugins/uSync8/uSyncHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

var scripts = [
Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/lib/signalr/jquery.signalR.js',
Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/backoffice/signalr/hubs'];
Umbraco.Sys.ServerVariables.uSync.signalRHub];

var resource = {
initHub: initHub
Expand Down Expand Up @@ -62,30 +62,41 @@
function hubSetup(callback) {
var proxy = $.connection.uSyncHub;

var hub = {
start: function () {
$.connection.hub.start();
},
on: function (eventName, callback) {
proxy.on(eventName, function (result) {
$rootScope.$apply(function () {
if (callback) {
callback(result);
}
});
});
},
invoke: function (methodName, callback) {
proxy.invoke(methodName)
.done(function (result) {
var hub = {};
if (proxy !== undefined) {
hub = {
active: true,
start: function () {
$.connection.hub.start();
},
on: function (eventName, callback) {
proxy.on(eventName, function (result) {
$rootScope.$apply(function () {
if (callback) {
callback(result);
}
});
});
}
};
},
invoke: function (methodName, callback) {
proxy.invoke(methodName)
.done(function (result) {
$rootScope.$apply(function () {
if (callback) {
callback(result);
}
});
});
}
};
}
else {
hub = {
on: function () { },
invoke: function () { },
start: function () { console.log('no hub to start - missing signalR library ?'); }
};
}

return callback(hub);
}
Expand Down
Loading

0 comments on commit 11e6f0a

Please sign in to comment.