diff --git a/uSync8.BackOffice/Configuration/BackOfficeConfig.cs b/uSync8.BackOffice/Configuration/BackOfficeConfig.cs index 3bb41f58..154a4790 100644 --- a/uSync8.BackOffice/Configuration/BackOfficeConfig.cs +++ b/uSync8.BackOffice/Configuration/BackOfficeConfig.cs @@ -315,6 +315,7 @@ public HandlerSettings LoadHandlerConfig(XElement node, uSyncSettings defaultSet settings.UseFlatStructure = GetLocalValue(node.Attribute("UseFlatStructure"), defaultSettings.UseFlatStructure); settings.Actions = node.Attribute("Actions").ValueOrDefault("All").ToDelimitedList().ToArray(); settings.FailOnMissingParent = GetLocalValue(node.Attribute("FailOnMissingParent"), defaultSettings.FailOnMissingParent); + settings.Group = node.Attribute("Group").ValueOrDefault(string.Empty); // handlers can have their own individual settings beneath a node // diff --git a/uSync8.BackOffice/Configuration/uSyncHandlerSettings.cs b/uSync8.BackOffice/Configuration/uSyncHandlerSettings.cs index 4f8ba743..deaf8f9f 100644 --- a/uSync8.BackOffice/Configuration/uSyncHandlerSettings.cs +++ b/uSync8.BackOffice/Configuration/uSyncHandlerSettings.cs @@ -15,6 +15,8 @@ public class HandlerSettings public string[] Actions { get; set; } = new string[] { "All" }; + public string Group { get; set; } + public OverriddenValue UseFlatStructure { get; set; } = new OverriddenValue(); public OverriddenValue GuidNames { get; set; } = new OverriddenValue(); diff --git a/uSync8.BackOffice/SyncHandlers/SyncHandlerFactory.cs b/uSync8.BackOffice/SyncHandlers/SyncHandlerFactory.cs index faccd5d5..60c8432f 100644 --- a/uSync8.BackOffice/SyncHandlers/SyncHandlerFactory.cs +++ b/uSync8.BackOffice/SyncHandlers/SyncHandlerFactory.cs @@ -117,9 +117,17 @@ public IEnumerable GetValidHandlersByEntityType(IEnum public IEnumerable GetValidGroups(SyncHandlerOptions options = null) - => GetValidHandlers(options) + { + var handlers = GetValidHandlers(options); + var groups = handlers .Select(x => x.Handler.Group) - .Distinct(); + .ToList(); + + groups.AddRange(handlers.Where(x => !string.IsNullOrWhiteSpace(x.Settings.Group)) + .Select(x => x.Settings.Group)); + + return groups.Distinct(); + } public IEnumerable GetValidHandlers(string[] aliases, SyncHandlerOptions options = null) => GetValidHandlers(options) @@ -151,7 +159,7 @@ public IEnumerable GetValidHandlers(SyncHandlerOption // check its valid for the passed group and action. if (handler != null - && IsValidGroup(options.Group, handler) + && IsValidGroup(options.Group, handler, settings) && IsValidAction(options.Action, settings.Actions)) { // logger.Debug("Adding {handler} to ValidHandler List", handler.Alias); @@ -180,11 +188,15 @@ private bool IsValidAction(HandlerActions requestedAction, string[] actions) actions.InvariantContains("all") || actions.InvariantContains(requestedAction.ToString()); - private bool IsValidGroup(string group, ISyncHandler handler) + private bool IsValidGroup(string group, ISyncHandler handler, HandlerSettings settings) { // empty means all if (string.IsNullOrWhiteSpace(group)) return true; + // group over written in settings. + if (!string.IsNullOrWhiteSpace(settings.Group)) + return settings.Group.InvariantEquals(group); + if (handler is ISyncExtendedHandler extendedHandler) return extendedHandler.Group.InvariantEquals(group); diff --git a/uSync8.Site/config/uSync8.config b/uSync8.Site/config/uSync8.config index 057cdfa2..106886c9 100644 --- a/uSync8.Site/config/uSync8.config +++ b/uSync8.Site/config/uSync8.config @@ -25,7 +25,7 @@ - +