상속: BindableBase, IConfigurationSetting
예제 #1
0
        protected async Task SaveSetting(string value) {
            string name = null;
            var hier = _projectSystemServices.GetSelectedProject<IVsHierarchy>();
            var configuredProject = hier?.GetConfiguredProject();
            if (configuredProject != null) {
                using (var access = await _projectConfigurationSettingsProvider.OpenProjectSettingsAccessAsync(configuredProject)) {
                    name = access.Settings.FindNextAvailableSettingName(_settingNameTemplate);
                    var s = new ConfigurationSetting(name, value ?? name, ConfigurationSettingValueType.String);
                    s.EditorType = ConnectionStringEditor.ConnectionStringEditorName;
                    s.Category = ConnectionStringEditor.ConnectionStringEditorCategory;
                    s.Description = Resources.ConnectionStringDescription;
                    access.Settings.Add(s);
                }
            }

            if(Workflow.RSession.IsHostRunning) {
                var expr = Invariant($"if (!exists('settings')) {{ settings <- as.environment(list()); }}; if (is.environment(settings)) {{ settings${name ?? _settingNameTemplate} = {value.ToRStringLiteral()}; }}");
                Workflow.Operations.EnqueueExpression(expr, addNewLine: true);
            }
        }
예제 #2
0
        public async Task ConcurrentAccess() {
            string folder = Path.Combine(_files.DestinationPath, "ConcurrentAccess");
            if(!Directory.Exists(folder)) {
                Directory.CreateDirectory(folder);
            }
            string projFile = Path.Combine(folder, "file.rproj");
            var up = Substitute.For<UnconfiguredProject>();
            up.FullPath.Returns(projFile);

            var props = Substitute.For<IRProjectProperties>();
            var p = new ProjectConfigurationSettingsProvider();

            var s1 = new ConfigurationSetting("s1", "1", ConfigurationSettingValueType.String);
            var s2 = new ConfigurationSetting("s2", "2", ConfigurationSettingValueType.String);

            using (var access1 = await p.OpenProjectSettingsAccessAsync(up, props)) {
                access1.Settings.Should().NotBeNull();
                access1.Settings.Should().BeEmpty();

                using (var access2 = await p.OpenProjectSettingsAccessAsync(up, props)) {
                    access2.Settings.Should().NotBeNull();
                    access2.Settings.Add(s1);
                    access1.Settings.Count.Should().Be(1);
                }

                access1.Settings.Add(s2);
                access1.Settings.Count.Should().Be(2);
            }

            var settingsFile = Path.Combine(folder, "Settings.R");
            File.Exists(settingsFile).Should().BeTrue();

            var c = new ConfigurationSettingCollection();
            c.Load(settingsFile);

            c.Count.Should().Be(2);
            c.GetSetting("s1").Value.Should().Be("1");
            c.GetSetting("s2").Value.Should().Be("2");

            File.Delete(settingsFile);
        }