Exemplo n.º 1
0
        public IUserSettings ReadUserSettings()
        {
            var settingsFile = GetUserSettingsFilename();

            if (File.Exists(settingsFile))
            {
                try
                {
                    var section = new UserSettingsConfiguration();
                    using (var file = File.OpenRead(settingsFile))
                    {
                        var reader = new XmlTextReader(file);
                        section.Deserialize(reader);
                        return(section);
                    }
                }
                catch (Exception ex)
                {
                    ex.Log();
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public void WriteUserSettings(IUserSettings settings)
        {
            var settingsFile = GetUserSettingsFilename();

            if (!File.Exists(settingsFile))
            {
                var dir = Path.GetDirectoryName(settingsFile);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }

            var section = new UserSettingsConfiguration();

            section.Set(settings);
            using (var writer = new XmlTextWriter(settingsFile, null))
            {
                writer.Formatting = Formatting.Indented;
                section.Serialize(writer);
            }
        }