release: 1.4.2

This commit is contained in:
2026-03-18 17:16:40 +08:00
parent da3d20be8c
commit 4024c15f5c
10 changed files with 328 additions and 6 deletions

View File

@@ -17,6 +17,8 @@ public sealed class ToponControllerOptions
public const string ExcludeBundleIdsKey = "topon.exclude_bundle_ids";
public const string RewardedExcludeAdSourceIdsKey = "topon.rewarded_exclude_ad_source_ids";
public const string QueryAreaOnInitKey = "topon.query_area_on_init";
public const string InitCustomMapKey = "topon.custom_map";
public const string RewardedCustomDataKey = "topon.rewarded_custom_data";
public string Channel { get; set; }
public string SubChannel { get; set; }
@@ -28,6 +30,8 @@ public sealed class ToponControllerOptions
public string[] ExcludeBundleIds { get; set; }
public string[] RewardedExcludeAdSourceIds { get; set; }
public bool QueryAreaOnInit { get; set; }
public Dictionary<string, string> InitCustomMap { get; set; }
public Dictionary<string, string> RewardedCustomData { get; set; }
public Action<string> OnAreaReceived { get; set; }
public Action<string> OnAreaError { get; set; }
@@ -87,6 +91,8 @@ public sealed class ToponControllerOptions
ExcludeBundleIds = GetStringArray(map, ExcludeBundleIdsKey) ?? ExcludeBundleIds;
RewardedExcludeAdSourceIds = GetStringArray(map, RewardedExcludeAdSourceIdsKey) ?? RewardedExcludeAdSourceIds;
QueryAreaOnInit = GetBool(map, QueryAreaOnInitKey) ?? QueryAreaOnInit;
InitCustomMap = MergeMaps(InitCustomMap, GetPrefixedMap(map, InitCustomMapKey + "."));
RewardedCustomData = MergeMaps(RewardedCustomData, GetPrefixedMap(map, RewardedCustomDataKey + "."));
}
private void ApplyLegacyArgs(object[] args)
@@ -124,6 +130,8 @@ public sealed class ToponControllerOptions
ExcludeBundleIds = explicitOptions.ExcludeBundleIds ?? ExcludeBundleIds;
RewardedExcludeAdSourceIds = explicitOptions.RewardedExcludeAdSourceIds ?? RewardedExcludeAdSourceIds;
QueryAreaOnInit = explicitOptions.QueryAreaOnInit || QueryAreaOnInit;
InitCustomMap = MergeMaps(InitCustomMap, explicitOptions.InitCustomMap);
RewardedCustomData = MergeMaps(RewardedCustomData, explicitOptions.RewardedCustomData);
OnAreaReceived = explicitOptions.OnAreaReceived ?? OnAreaReceived;
OnAreaError = explicitOptions.OnAreaError ?? OnAreaError;
}
@@ -143,7 +151,23 @@ public sealed class ToponControllerOptions
continue;
}
map[entry.Key.ToString()] = ConvertDictionaryValue(entry.Value);
var key = entry.Key.ToString();
if (entry.Value is IDictionary nestedDictionary)
{
if (string.Equals(key, InitCustomMapKey, StringComparison.OrdinalIgnoreCase))
{
InitCustomMap = MergeMaps(InitCustomMap, ToStringMap(nestedDictionary));
continue;
}
if (string.Equals(key, RewardedCustomDataKey, StringComparison.OrdinalIgnoreCase))
{
RewardedCustomData = MergeMaps(RewardedCustomData, ToStringMap(nestedDictionary));
continue;
}
}
map[key] = ConvertDictionaryValue(entry.Value);
}
Channel = GetString(map, ChannelKey, "channel") ?? Channel;
@@ -156,6 +180,8 @@ public sealed class ToponControllerOptions
ExcludeBundleIds = GetStringArray(map, ExcludeBundleIdsKey) ?? ExcludeBundleIds;
RewardedExcludeAdSourceIds = GetStringArray(map, RewardedExcludeAdSourceIdsKey) ?? RewardedExcludeAdSourceIds;
QueryAreaOnInit = GetBool(map, QueryAreaOnInitKey) ?? QueryAreaOnInit;
InitCustomMap = MergeMaps(InitCustomMap, GetPrefixedMap(map, InitCustomMapKey + "."));
RewardedCustomData = MergeMaps(RewardedCustomData, GetPrefixedMap(map, RewardedCustomDataKey + "."));
}
private static string GetString(IDictionary<string, string> map, params string[] keys)
@@ -225,6 +251,54 @@ public sealed class ToponControllerOptions
return items.Length > 0 ? items : null;
}
private static Dictionary<string, string> GetPrefixedMap(IDictionary<string, string> map, string prefix)
{
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var pair in map)
{
if (!pair.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
continue;
}
var nestedKey = pair.Key.Substring(prefix.Length).Trim();
if (string.IsNullOrWhiteSpace(nestedKey) || string.IsNullOrWhiteSpace(pair.Value))
{
continue;
}
result[nestedKey] = pair.Value.Trim();
}
return result.Count > 0 ? result : null;
}
private static Dictionary<string, string> MergeMaps(
Dictionary<string, string> current,
Dictionary<string, string> incoming)
{
if (incoming == null || incoming.Count == 0)
{
return current;
}
var result = current != null
? new Dictionary<string, string>(current, StringComparer.OrdinalIgnoreCase)
: new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var pair in incoming)
{
if (string.IsNullOrWhiteSpace(pair.Key) || string.IsNullOrWhiteSpace(pair.Value))
{
continue;
}
result[pair.Key] = pair.Value;
}
return result.Count > 0 ? result : null;
}
private static bool TryConvertBool(object value, out bool result)
{
switch (value)
@@ -287,4 +361,27 @@ public sealed class ToponControllerOptions
return value.ToString();
}
private static Dictionary<string, string> ToStringMap(IDictionary dictionary)
{
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (DictionaryEntry entry in dictionary)
{
if (entry.Key == null || entry.Value == null)
{
continue;
}
var key = entry.Key.ToString()?.Trim();
var value = entry.Value.ToString()?.Trim();
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
{
continue;
}
result[key] = value;
}
return result.Count > 0 ? result : null;
}
}