Skip to content

Commit

Permalink
breaking: change the settings dictionary to string,object #493
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed May 11, 2023
1 parent fef714b commit da505f3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
4 changes: 1 addition & 3 deletions uSync.BackOffice.Targets/appsettings-schema.usync.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@
"Settings": {
"type": "object",
"description": "Additional settings for the handler",
"additionalProperties": {
"type": "string"
}
"additionalProperties": {}
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions uSync.BackOffice/Configuration/uSyncHandlerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class HandlerSettings
/// <summary>
/// Additional settings for the handler
/// </summary>
public Dictionary<string, string> Settings { get; set; } = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
}

/// <summary>
Expand Down Expand Up @@ -89,7 +89,7 @@ public static TResult GetSetting<TResult>(this HandlerSettings settings, string
public static void AddSetting<TObject>(this HandlerSettings settings, string key, TObject value)
{
if (settings.Settings == null)
settings.Settings = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
settings.Settings = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);

settings.Settings[key] = value.ToString();
}
Expand All @@ -109,7 +109,7 @@ public static HandlerSettings Clone(this HandlerSettings settings)
UseFlatStructure = settings.UseFlatStructure,
Group = settings.Group,
GuidNames = settings.GuidNames,
Settings = new Dictionary<string, string>(settings.Settings, StringComparer.InvariantCultureIgnoreCase)
Settings = new Dictionary<string, object>(settings.Settings, StringComparer.InvariantCultureIgnoreCase)
};
}

Expand Down
4 changes: 1 addition & 3 deletions uSync.BackOffice/SyncHandlers/Handlers/DictionaryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ protected override IEnumerable<uSyncAction> ReportElement(XElement node, string
}

private bool IsOneWay(HandlerSettings config)
{
return (config.Settings.ContainsKey("OneWay") && config.Settings["OneWay"].InvariantEquals("true"));
}
=> config.GetSetting<bool>("OneWay", false);
}
}
14 changes: 7 additions & 7 deletions uSync.Core/Serialization/SyncSerializerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public SyncSerializerOptions(SerializerFlags flags)
this.Flags = flags;
}

public SyncSerializerOptions(Dictionary<string, string> settings)
public SyncSerializerOptions(Dictionary<string, object> settings)
{
this.Settings = settings != null ? new Dictionary<string, string>(settings) : new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
this.Settings = settings != null ? new Dictionary<string, object>(settings) : new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);

}

public SyncSerializerOptions(SerializerFlags flags, Dictionary<string, string> settings)
public SyncSerializerOptions(SerializerFlags flags, Dictionary<string, object> settings)
: this(settings)
{
this.Flags = flags;
Expand All @@ -46,7 +46,7 @@ public SyncSerializerOptions(SerializerFlags flags, Dictionary<string, string> s
/// <summary>
/// Parameterized options, custom for each handler
/// </summary>
public Dictionary<string, string> Settings { get; internal set; }
public Dictionary<string, object> Settings { get; internal set; }

/// <summary>
/// flag properties, we can move this away from flags if we want to.
Expand Down Expand Up @@ -102,7 +102,7 @@ public IList<string> GetSegments()

public string SwapValue(string key, string newValue)
{
string oldValue = null;
object oldValue = null;

if (!this.Settings.ContainsKey(key))
oldValue = this.Settings[key];
Expand All @@ -112,15 +112,15 @@ public string SwapValue(string key, string newValue)
else
this.Settings[key] = newValue;

return oldValue;
return oldValue.ToString();
}

/// <summary>
/// merge any new settings into the settings collection.
/// </summary>
public void MergeSettings(Dictionary<string, string> newSettings)
{
if (Settings == null) Settings = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
if (Settings == null) Settings = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
if (newSettings != null)
{
foreach (var kvp in newSettings)
Expand Down

0 comments on commit da505f3

Please sign in to comment.