Ejemplo n.º 1
0
        public OptionsStorage(ISettingsService settingsService)
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            toGroupSection    = new Dictionary <string, ISettingsSection>(StringComparer.Ordinal);
            toSubGroupSection = new Dictionary <SubGroupKey, ISettingsSection>();
            toOptionSection   = new Dictionary <OptionKey, ISettingsSection>();
            settingsSection   = settingsService.GetOrCreateSection(SETTINGS_GUID);

            foreach (var groupSect in settingsSection.SectionsWithName(GroupName))
            {
                var groupName = groupSect.Attribute <string>(GroupNameAttr);
                if (groupName == null)
                {
                    continue;
                }
                if (toGroupSection.ContainsKey(groupName))
                {
                    continue;
                }
                toGroupSection[groupName] = groupSect;

                foreach (var ctSect in groupSect.SectionsWithName(SubGroupName))
                {
                    var subGroup = ctSect.Attribute <string>(SubGroupNameAttr);
                    if (subGroup == null)
                    {
                        continue;
                    }
                    var key = new SubGroupKey(groupName, subGroup);
                    if (toSubGroupSection.ContainsKey(key))
                    {
                        continue;
                    }
                    toSubGroupSection[key] = ctSect;

                    foreach (var optSect in ctSect.SectionsWithName(OptionName))
                    {
                        var name = optSect.Attribute <string>(OptionNameAttr);
                        if (name == null)
                        {
                            continue;
                        }
                        var optKey = new OptionKey(key, name);
                        if (toOptionSection.ContainsKey(optKey))
                        {
                            continue;
                        }
                        toOptionSection[optKey] = optSect;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        ISettingsSection GetOrCreateSubGroupSection(string groupName, string subGroup)
        {
            var key = new SubGroupKey(groupName, subGroup);

            if (toSubGroupSection.TryGetValue(key, out var sect))
            {
                return(sect);
            }
            var groupSect = GetOrCreateGroupSection(groupName);

            sect = groupSect.CreateSection(SubGroupName);
            toSubGroupSection.Add(key, sect);
            sect.Attribute(SubGroupNameAttr, subGroup);
            return(sect);
        }
Ejemplo n.º 3
0
 public OptionKey(SubGroupKey subGroupKey, string name)
 {
     this.subGroupKey = subGroupKey;
     this.name        = name;
 }