Implemented ConfigProfiles internally.
This commit is contained in:
@@ -121,12 +121,17 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
|
|
||||||
private const string SaveDataFileName = "SettingsData.xml";
|
private const string SaveDataFileName = "SettingsData.xml";
|
||||||
|
|
||||||
|
// --- Settings
|
||||||
private readonly ConcurrentDictionary<(ContentPackage OwnerPackage, string InternalName), ISettingBase>
|
private readonly ConcurrentDictionary<(ContentPackage OwnerPackage, string InternalName), ISettingBase>
|
||||||
_settingsInstances = new();
|
_settingsInstances = new();
|
||||||
private readonly ConcurrentDictionary<string, Func<(IConfigService ConfigService, IConfigInfo Info), ISettingBase>>
|
private readonly ConcurrentDictionary<string, Func<(IConfigService ConfigService, IConfigInfo Info), ISettingBase>>
|
||||||
_instanceFactory = new();
|
_instanceFactory = new();
|
||||||
private readonly ConcurrentDictionary<ContentPackage, ConcurrentBag<ISettingBase>>
|
private readonly ConcurrentDictionary<ContentPackage, ConcurrentBag<ISettingBase>>
|
||||||
_settingsInstancesByPackage = new();
|
_settingsInstancesByPackage = new();
|
||||||
|
|
||||||
|
// --- Profiles
|
||||||
|
private readonly ConcurrentDictionary<(ContentPackage Package, string ProfileName), IConfigProfileInfo>
|
||||||
|
_settingsProfiles = new();
|
||||||
|
|
||||||
private IStorageService _storageService;
|
private IStorageService _storageService;
|
||||||
private ILoggerService _logger;
|
private ILoggerService _logger;
|
||||||
@@ -170,7 +175,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
|
|
||||||
public async Task<FluentResults.Result> LoadConfigsAsync(ImmutableArray<IConfigResourceInfo> configResources)
|
public async Task<FluentResults.Result> LoadConfigsAsync(ImmutableArray<IConfigResourceInfo> configResources)
|
||||||
{
|
{
|
||||||
using var lck = _operationLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
using var lck = await _operationLock.AcquireReaderLock();
|
||||||
IService.CheckDisposed(this);
|
IService.CheckDisposed(this);
|
||||||
if (configResources.IsDefaultOrEmpty)
|
if (configResources.IsDefaultOrEmpty)
|
||||||
{
|
{
|
||||||
@@ -258,11 +263,47 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
|
|
||||||
public async Task<FluentResults.Result> LoadConfigsProfilesAsync(ImmutableArray<IConfigResourceInfo> configProfileResources)
|
public async Task<FluentResults.Result> LoadConfigsProfilesAsync(ImmutableArray<IConfigResourceInfo> configProfileResources)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
using var _ = await _operationLock.AcquireReaderLock();
|
||||||
// TODO: Implement profiles.
|
IService.CheckDisposed(this);
|
||||||
return FluentResults.Result.Ok();
|
if (configProfileResources.IsDefaultOrEmpty)
|
||||||
#endif
|
{
|
||||||
throw new NotImplementedException();
|
ThrowHelper.ThrowArgumentNullException($"{nameof(LoadConfigsProfilesAsync)}: {nameof(configProfileResources)} is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new FluentResults.Result();
|
||||||
|
|
||||||
|
foreach (var resource in configProfileResources)
|
||||||
|
{
|
||||||
|
var r = await _configProfileInfoParserService.TryParseResourcesAsync(resource);
|
||||||
|
if (r.IsFailed)
|
||||||
|
{
|
||||||
|
result.WithErrors(r.Errors);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var info in r.Value)
|
||||||
|
{
|
||||||
|
if (!_settingsProfiles.TryAdd((info.OwnerPackage, info.InternalName), info))
|
||||||
|
{
|
||||||
|
result.WithErrors(r.Errors);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.InternalName.Equals("default", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
//apply it
|
||||||
|
foreach (var value in info.ProfileValues)
|
||||||
|
{
|
||||||
|
if (_settingsInstances.TryGetValue((info.OwnerPackage, value.SettingName), out var instance))
|
||||||
|
{
|
||||||
|
instance.TrySetValue(value.Element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluentResults.Result LoadSavedValueForConfig(ISettingBase setting)
|
public FluentResults.Result LoadSavedValueForConfig(ISettingBase setting)
|
||||||
|
|||||||
Reference in New Issue
Block a user