Skip to content

Commit

Permalink
Fix #200 - Add ability to set handler group in config (e.g move dicti…
Browse files Browse the repository at this point in the history
…onary)
  • Loading branch information
Kevin Jump committed Mar 4, 2021
1 parent 11e6f0a commit f75949a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions uSync8.BackOffice/Configuration/BackOfficeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
2 changes: 2 additions & 0 deletions uSync8.BackOffice/Configuration/uSyncHandlerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class HandlerSettings

public string[] Actions { get; set; } = new string[] { "All" };

public string Group { get; set; }

public OverriddenValue<bool> UseFlatStructure { get; set; } = new OverriddenValue<bool>();
public OverriddenValue<bool> GuidNames { get; set; } = new OverriddenValue<bool>();

Expand Down
20 changes: 16 additions & 4 deletions uSync8.BackOffice/SyncHandlers/SyncHandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ public IEnumerable<ExtendedHandlerConfigPair> GetValidHandlersByEntityType(IEnum


public IEnumerable<string> 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<ExtendedHandlerConfigPair> GetValidHandlers(string[] aliases, SyncHandlerOptions options = null)
=> GetValidHandlers(options)
Expand Down Expand Up @@ -151,7 +159,7 @@ public IEnumerable<ExtendedHandlerConfigPair> 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<SyncHandlerFactory>("Adding {handler} to ValidHandler List", handler.Alias);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion uSync8.Site/config/uSync8.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Handler Alias="templateHandler" Enabled="true" Actions="All" />
<Handler Alias="contentTypeHandler" Enabled="true" Actions="All" />
<Handler Alias="contentTemplateHandler" Enabled="true" Actions="All" />
<Handler Alias="dictionaryHandler" Enabled="true" Actions="All" />
<Handler Alias="dictionaryHandler" Enabled="true" Actions="All" Group="Settings" />
<Handler Alias="mediaTypeHandler" Enabled="true" Actions="All" />
<Handler Alias="domainHandler" Enabled="true" Actions="All" />
<Handler Alias="contentHandler" Enabled="true" Actions="All">
Expand Down

0 comments on commit f75949a

Please sign in to comment.