コード例 #1
0
        public ISettingsManagerSection GetSection(string name)
        {
            SettingsManagerSection section;

            lock (_sections)
            {
                section = _sections.FirstOrDefault(x => x.Name == name);

                if (section == null)
                {
                    if (_legacySection == null)
                    {
                        section = new SettingsManagerSection(name, this, new SettingsLoaderV3(this));
                    }
                    else
                    {
                        section = new LegacySettingsManagerSection(name, this, new SettingsLoaderV3(this), _legacySection);
                    }

                    _sections.Add(section);
                }
            }

            return(section);
        }
コード例 #2
0
        private void Load()
        {
            lock (_sections)
            {
                _sections.Clear();

                try
                {
                    using (FileStream fileStream = File.OpenRead(this._fileName))
                    {
                        XPathDocument  document = new XPathDocument(fileStream);
                        XPathNavigator nav      = document.CreateNavigator();

                        string version = String.Empty;
                        try
                        {
                            version = nav.SelectSingleNode("/data").GetAttribute("version", "");
                        }
                        catch { version = "1"; }

                        ISettingsLoader loader = null;

                        if (version == "1")
                        {
                            loader = new SettingsLoaderV1(this);
                        }
                        else if (version == "2")
                        {
                            loader = new SettingsLoaderV2(this);
                        }
                        else
                        {
                            loader = new SettingsLoaderV3(this);
                        }

                        if (loader != null)
                        {
                            _sections.AddRange(loader.Load(nav));
                        }

                        // Add first section as legacy and it will switch SettingManager to legacy mode.
                        // This mode should be active only for valid conversion from older version
                        // where we doesn't have sections in settings file.
                        if ((version == "1" || version == "2") && _sections.Count == 1)
                        {
                            _legacySection = _sections[0];
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.LogNotice("Failed to load settings");
                    Logger.LogWarn(e);
                }
            }
        }