Storage of the R application settings. Settings are written into R file as assignment statements such as 'name <- value'. Value can be string or an expression. The difference is that string values are quoted when written into the file and expressions are written as is.
Inheritance: IConfigurationSettingsReader
 /// <summary>
 /// Loads settings from the file
 /// </summary>
 public void Load(string filePath)
 {
     lock (_lock) {
         try {
             Clear();
             using (var sr = new StreamReader(filePath)) {
                 using (var csr = new ConfigurationSettingsReader(sr)) {
                     var settings = csr.LoadSettings();
                     foreach (var s in settings)
                     {
                         Add(s);
                     }
                 }
             }
             SourceFile = filePath;
         } catch (IOException) {
             SourceFile = null;
         } catch (UnauthorizedAccessException) {
             SourceFile = null;
         }
     }
 }
Exemplo n.º 2
0
        private void LoadAndWrite(string originalContent, string expectedContent) {
            IReadOnlyList<IConfigurationSetting> settings;
            var sr = new StreamReader(ToStream(originalContent));
            using (var csr = new ConfigurationSettingsReader(sr)) {
                settings = csr.LoadSettings();
            }

            var stream = new MemoryStream();
            using (var csw = new ConfigurationSettingsWriter(new StreamWriter(stream))) {
                csw.SaveSettings(settings);

                stream.Seek(0, SeekOrigin.Begin);
                using (var r = new StreamReader(stream)) {
                    var s = r.ReadToEnd();
                    s.Should().StartWith(Resources.SettingsFileHeader);
                    s.Should().Contain(expectedContent);
                }
            }
        }
Exemplo n.º 3
0
        public void LoadMultiple02() {
            string content1 =
@"
# [Category] SQL
# [Description] Database connection string
# [Editor] ConnectionStringEditor
settings$c1 <- 'DSN'
";
            string content2 =
@"
# [Category] SQL
# [Description] Database connection string
# [Editor] ConnectionStringEditor
c1 <- 'DSN'
";
            foreach (var content in new string[] { content1, content2 }) {
                using (var sr = new StreamReader(ToStream(content))) {
                    using (var css = new ConfigurationSettingsReader(sr)) {
                        var settings = css.LoadSettings();
                        settings.Should().HaveCount(1);

                        settings[0].Name.Should().Be("c1");
                        settings[0].Value.Should().Be("DSN");
                        settings[0].ValueType.Should().Be(ConfigurationSettingValueType.String);
                        settings[0].Category.Should().Be("SQL");
                        settings[0].Description.Should().Be("Database connection string");
                        settings[0].EditorType.Should().Be("ConnectionStringEditor");
                    }
                }
            }
        }