public void TryInitializeComponentGroup(string uid) { if (uid == null) { throw new ArgumentNullException(nameof(uid)); } try { if (!_storageService.TryRead(out ComponentGroupConfiguration configuration, ComponentGroupsDirectory, uid, DefaultFilenames.Configuration)) { throw new ComponentGroupNotFoundException(uid); } if (!_storageService.TryRead(out WirehomeDictionary settings, ComponentGroupsDirectory, uid, DefaultFilenames.Settings)) { settings = new WirehomeDictionary(); } var componentGroup = new ComponentGroup(uid); foreach (var setting in settings) { componentGroup.Settings[setting.Key] = setting.Value; } var associationUids = _storageService.EnumeratureDirectories("*", ComponentGroupsDirectory, uid, "Components"); foreach (var associationUid in associationUids) { if (!_storageService.TryRead(out WirehomeDictionary associationSettings, ComponentGroupsDirectory, uid, "Components", associationUid, DefaultFilenames.Settings)) { associationSettings = new WirehomeDictionary(); } var componentAssociation = new ComponentGroupAssociation(); foreach (var associationSetting in associationSettings) { componentAssociation.Settings[associationSetting.Key] = associationSetting.Value; } componentGroup.Components.TryAdd(associationUid, componentAssociation); } lock (_componentGroups) { _componentGroups[uid] = componentGroup; } } catch (Exception exception) { _logger.LogError(exception, $"Error while initializing component group '{uid}'.'"); } }
private void Load() { _componentGroups.Clear(); var configurationFiles = _storageService.EnumerateFiles("Configuration.json", "ComponentGroups"); foreach (var configurationFile in configurationFiles) { if (_storageService.TryRead(out ComponentGroupConfiguration _, "ComponentGroups", configurationFile)) { var uid = Path.GetDirectoryName(configurationFile); var componentGroup = new ComponentGroup(uid); if (_storageService.TryRead(out Dictionary <string, object> settings, "ComponentGroups", uid, "Settings.json")) { foreach (var setting in settings) { componentGroup.Settings[setting.Key] = setting.Value; } } var componentSettingsFiles = _storageService.EnumerateFiles("Settings.json", "ComponentGroups", uid, "Components"); foreach (var componentSettingsFile in componentSettingsFiles) { if (_storageService.TryRead(out WirehomeDictionary componentSettings, "ComponentGroups", uid, "Components", componentSettingsFile)) { var componentUid = Path.GetDirectoryName(componentSettingsFile); var association = new ComponentGroupAssociation { Settings = componentSettings ?? new WirehomeDictionary() }; componentGroup.Components[componentUid] = association; } } _componentGroups[componentGroup.Uid] = componentGroup; } } }
private void SaveMacroAssociationSettings(ComponentGroup componentGroup, string componentUid, ComponentGroupAssociation association) { _storageService.Write(association.Settings, ComponentGroupsDirectory, componentGroup.Uid, "Macros", componentUid, DefaultFilenames.Settings); }
public void InitializeComponentGroup(string uid) { if (uid == null) { throw new ArgumentNullException(nameof(uid)); } if (!_storageService.TryRead(out ComponentGroupConfiguration configuration, ComponentGroupsDirectory, uid, DefaultFileNames.Configuration)) { throw new ComponentGroupNotFoundException(uid); } if (!_storageService.TryRead(out IDictionary <string, object> settings, ComponentGroupsDirectory, uid, DefaultFileNames.Settings)) { settings = new Dictionary <string, object>(); } var componentGroup = new ComponentGroup(uid); foreach (var setting in settings) { componentGroup.SetSetting(setting.Key, setting.Value); } var associationUids = _storageService.EnumerateDirectories("*", ComponentGroupsDirectory, uid, "Components"); foreach (var associationUid in associationUids) { if (!_storageService.TryRead(out IDictionary <string, object> associationSettings, ComponentGroupsDirectory, uid, "Components", associationUid, DefaultFileNames.Settings)) { associationSettings = new Dictionary <string, object>(); } var componentAssociation = new ComponentGroupAssociation(); foreach (var associationSetting in associationSettings) { componentAssociation.Settings[associationSetting.Key] = associationSetting.Value; } componentGroup.Components.TryAdd(associationUid, componentAssociation); } associationUids = _storageService.EnumerateDirectories("*", ComponentGroupsDirectory, uid, "Macros"); foreach (var associationUid in associationUids) { if (!_storageService.TryRead(out IDictionary <string, object> associationSettings, ComponentGroupsDirectory, uid, "Macros", associationUid, DefaultFileNames.Settings)) { associationSettings = new Dictionary <string, object>(); } var componentAssociation = new ComponentGroupAssociation(); foreach (var associationSetting in associationSettings) { componentAssociation.Settings[associationSetting.Key] = associationSetting.Value; } componentGroup.Macros.TryAdd(associationUid, componentAssociation); } lock (_componentGroups) { _componentGroups[uid] = componentGroup; } }