public static SettingsData For(IKeyValues values, string name = "Anonymous")
        {
            var source = new SettingsData(new Dictionary<string, object>(), name);
            values.ReadAll((key, value) => source[key] = value);

            return source;
        }
        private SettingsData newData()
        {
            var data = new SettingsData();
            data[Guid.NewGuid().ToString()] = Guid.NewGuid().ToString();

            return data;
        }
Esempio n. 3
0
        public void subset_by_filter_copies_provenance()
        {
            var data = new SettingsData(SettingCategory.core){
                Provenance = Guid.NewGuid().ToString()
            };

            data.SubsetByKey(key => true).Provenance.ShouldEqual(data.Provenance);
        }
Esempio n. 4
0
 // TESTING CTOR ONLY!!!!!!!!
 private DeploymentPlan(DeploymentSettings settings, DeploymentOptions options, IEnumerable<Recipe> recipes, IEnumerable<HostManifest> hosts)
 {
     _recipes = recipes;
     settings.Plan = this;
     _hosts = hosts;
     _options = options;
     _rootData = new SettingsData();
 }
Esempio n. 5
0
 public void reading_an_entry_with_a_key_but_no_value_should_bork()
 {
     Exception<Exception>.ShouldBeThrownBy(() =>
     {
         var data = new SettingsData(SettingCategory.core);
         data.Read("Key");
     });
 }
        private void saveData(SettingsData data, string directory, string name)
        {
            var file = FileSystem.Combine("geonosis", directory, "config", name + ".config");
            new FileSystem().CreateDirectory("geonosis", directory);
            new FileSystem().CreateDirectory("geonosis", directory, "config");

            XmlSettingsParser.Write(data, file);
        }
        public IEnumerable<SettingsData> FindSettingData()
        {
            var data = new SettingsData(_category);

            ConfigurationManager.AppSettings.AllKeys.Each(
                key => { data[key] = ConfigurationManager.AppSettings[key]; });

            yield return data;
        }
        public void package_has_priority_over_core_when_resolving_data()
        {
            var core1 = new SettingsData(SettingCategory.core).With("key1", "core1");

            var package = new SettingsData(SettingCategory.package).With("key1", "environment1");

            var request = SettingsRequestData.For(core1, package);
            request.Value("key1").ShouldEqual(package["key1"]);
        }
        public void contains_key_positive()
        {
            var core1 = new SettingsData(SettingCategory.core).With("key1", "core1");
            var environment = new SettingsData(SettingCategory.environment).With("key1", "environment1");

            var request = SettingsRequestData.For(core1, environment);

            request.ContainsKey("key1").ShouldBeTrue();
        }
        public IEnumerable<SettingsData> FindSettingData()
        {
            var data = new SettingsData();
            data.Child("FooSettings").Set("Name", "Max");
            data.Child("FooSettings").Set("Age", "9");
            data.Child("BarSettings").Set("Direction", "North");

            yield return data;
        }
Esempio n. 11
0
        public void read_complex_escaped_value()
        {
            var data = new SettingsData(SettingCategory.core);
            data.Read("DatabaseSettings.ConnectionString=\"Data Source=localhost;Initial Catalog=DovetailDAI;User Id=sa;Password=sa;\"");

            data.AllKeys.ShouldHaveTheSameElementsAs("DatabaseSettings.ConnectionString");

            data["DatabaseSettings.ConnectionString"].ShouldEqual("Data Source=localhost;Initial Catalog=DovetailDAI;User Id=sa;Password=sa;");
        }
Esempio n. 12
0
        public static void ReadFromFile(string file, SettingsData data)
        {
            new FileSystem().ReadTextFile(file, text =>
            {
                if (text.IsEmpty()) return;

                data.Read(text);
            });
        }
        public SettingsData SubsetByKey(Func<string, bool> keyFilter)
        {
            var subset = new SettingsData(Category){
                Provenance = Provenance
            };

            AllKeys.Where(keyFilter).Each(key => subset.With(key, _values[key]));

            return subset;
        }
Esempio n. 14
0
        public static SettingsData ReadFromFile(SettingCategory category, string file)
        {
            var data = new SettingsData(category){
                Provenance = file
            };

            ReadFromFile(file, data);

            return data;
        }
        public void SetUp()
        {
            theSettings1 = new SettingsData()
                .With("Beer", "FreeState Wheat");

            theSettings1.Provenance = "host";

            theSettings2 = new SettingsData()
                .With("Snack", "{Beer} and Peanuts");
            theSettings2.Provenance = "other";
        }
        public void not_all_substitutions_can_be_found_should_fail()
        {
            var theSettings1 = new SettingsData()
                .With("Beer", "{beerType}");

            Exception<SettingProviderException>.ShouldBeThrownBy(() =>
            {
                SettingsProvider.For(theSettings1).AssertAllSubstitutionsCanBeResolved();
            })
            .Message.ShouldContain("beerType");
        }
Esempio n. 17
0
        public void read_text()
        {
            var data = new SettingsData(SettingCategory.core);
            data.Read("Key=Value1");
            data.Read("A.Key=Value2");

            data.AllKeys.ShouldHaveTheSameElementsAs("A.Key", "Key");

            data["Key"].ShouldEqual("Value1");
            data["A.Key"].ShouldEqual("Value2");
        }
        public static void Write(SettingsData data, string filename)
        {
            var document = new XmlDocument();
            var root = document.WithRoot("Settings");
            root.SetAttribute("category", data.Category.ToString());

            data.AllKeys.Each(
                key => { root.AddElement("add").WithAtt("key", key).WithAtt("value", data[key].ToString()); });

            document.Save(filename);
        }
Esempio n. 19
0
        public void can_find_a_value_in_multiple_sources()
        {
            var core1 = new SettingsData().With("key1", "val1");
            var core2 = new SettingsData().With("key2", "val2");
            var core3 = new SettingsData().With("key3", "val3");

            var request = SettingsRequestData.For(core1, core2, core3);

            request.Value("key1").ShouldEqual("val1");
            request.Value("key2").ShouldEqual("val2");
            request.Value("key3").ShouldEqual("val3");
        }
Esempio n. 20
0
        public void has_any_value_prefixed_with_key()
        {
            var core1 = new SettingsData().With("One.key1", "val1");
            var core2 = new SettingsData().With("Two.key2", "val2");
            var core3 = new SettingsData().With("Three.key3", "val3");

            var request = SettingsRequestData.For(core1, core2, core3);

            request.HasAnyValuePrefixedWith("One").ShouldBeTrue();
            request.HasAnyValuePrefixedWith("Two").ShouldBeTrue();
            request.HasAnyValuePrefixedWith("Three").ShouldBeTrue();
            request.HasAnyValuePrefixedWith("NotInTheRequestDataAnywhere").ShouldBeFalse();
        }
Esempio n. 21
0
        public static void Write(SettingsData data, string filename)
        {
            var document = new XmlDocument();
            var root     = document.WithRoot("Settings");

            root.SetAttribute("category", data.Category.ToString());

            data.AllKeys.Each(key =>
            {
                root.AddElement("add").WithAtt("key", key).WithAtt("value", data[key]);
            });

            document.Save(filename);
        }
Esempio n. 22
0
        public void value_CPS_style_with_multiple_sources_with_a_match()
        {
            var core1 = new SettingsData().With("key1", "val1");
            var core2 = new SettingsData().With("key2", "val2");
            var core3 = new SettingsData().With("key3", "val3");

            var request = SettingsRequestData.For(core1, core2, core3);

            var action = MockRepository.GenerateMock<Action<object>>();

            request.Value("key2", action).ShouldBeTrue();

            action.AssertWasCalled(x => x.Invoke("val2"));
        }
Esempio n. 23
0
        public SettingsProvider(IObjectResolver resolver, IEnumerable <ISettingsSource> sources)
        {
            _resolver = resolver;

            _settings = new Lazy <IEnumerable <SettingsData> >(() =>
            {
                var allSettings = sources.SelectMany(x => x.FindSettingData()).ToArray();
                return(SettingsData.Order(allSettings));
            });

            _requestData = new Lazy <SettingsRequestData>(() => new SettingsRequestData(_settings.Value));

            _substitutedData = new Lazy <SubstitutedRequestData>(() => new SubstitutedRequestData(_requestData.Value, _requestData.Value));
        }
        public IEnumerable<SettingsData> FindSettingData()
        {
            var appSettings = ConfigurationManager.AppSettings;

            var data = new SettingsData(SettingCategory.profile) { Provenance = "applicationConfiguration/appSettings" };

            appSettings.AllKeys.Each(key =>
            {
                var value = appSettings[key];
                var keyWithSettings = appendSettingsToKeyTypeName(key);
                data[keyWithSettings] = value;
            });

            return new[] { data };
        }
        public SettingsData SubsetPrefixedBy(string prefix)
        {
            var keys = AllKeys.Where(key => key.StartsWith(prefix));
            var subset = new SettingsData(Category){
                Provenance = Provenance
            };

            keys.Each(rawKey =>
            {
                var subsetKey = rawKey.Substring(prefix.Length);
                subset.With(subsetKey, Get(rawKey));
            });

            return subset;
        }
        public void SetUp()
        {
            theSettings1 = new SettingsData()
                .With("Beer", "FreeState Wheat")
                .With("Snack", "Chips");
            theSettings1.Provenance = "host";

            theSettings2 = new SettingsData()
                .With("Snack", "Peanuts")
                .With("Friend","Philip");
            theSettings2.Provenance = "other";

            theSettings3 = new SettingsData(SettingCategory.environment)
                .With("Friend","Chad");
            theSettings3.Provenance = "environment";
        }
        public SettingsData SubsetPrefixedBy(string prefix)
        {
            var keys   = AllKeys.Where(key => key.StartsWith(prefix));
            var subset = new SettingsData(Category)
            {
                Provenance = Provenance
            };

            keys.Each(rawKey =>
            {
                var subsetKey = rawKey.Substring(prefix.Length);
                subset.With(subsetKey, Get(rawKey));
            });

            return(subset);
        }
        public static SettingsData Parse(XmlElement element)
        {
            var category = (SettingCategory)(element.HasAttribute("category")
                                               ? Enum.Parse(typeof(SettingCategory), element.GetAttribute("category"))
                                               : SettingCategory.core);

            var data = new SettingsData(category);

            element.SelectNodes("add").OfType<XmlElement>().Each(elem =>
            {
                var key = elem.GetAttribute("key");
                var value = elem.GetAttribute("value");
                data[key] = value;
            });

            return data;
        }
Esempio n. 29
0
        public static SettingsData Parse(XmlElement element, IDictionary <string, string> substitutions)
        {
            var category = (SettingCategory)(element.HasAttribute("category")
                                               ? Enum.Parse(typeof(SettingCategory), element.GetAttribute("category"))
                                               : SettingCategory.core);

            var data = new SettingsData(category, substitutions);

            element.SelectNodes("add").OfType <XmlElement>().Each(elem =>
            {
                var key   = elem.GetAttribute("key");
                var value = elem.GetAttribute("value");
                data[key] = value;
            });

            return(data);
        }
        public void no_substitutions_should_succeed()
        {
            var theSettings1 = new SettingsData()
                .With("Beer", "FreeState Wheat")
                .With("Snack", "Chips");
            theSettings1.Provenance = "host";

            var theSettings2 = new SettingsData()
                .With("Snack", "Peanuts")
                .With("Friend", "Philip");
            theSettings2.Provenance = "other";

            var theSettings3 = new SettingsData(SettingCategory.environment)
                .With("Friend", "Chad");
            theSettings3.Provenance = "environment";

            SettingsProvider.For(theSettings1, theSettings2, theSettings3).AssertAllSubstitutionsCanBeResolved();
        }
Esempio n. 31
0
        public SettingsData GetParentSource(SettingsData source)
        {
            ParentParts.Each(x =>
            {
                if (x.Contains("["))
                {
                    var parts = x.TrimEnd(']').Split('[');
                    var index = int.Parse(parts.Last());

                    source = source.GetChildrenElement(parts.First(), index);
                }
                else
                {
                    source = source.Child(x);
                }

            });

            return source;
        }
Esempio n. 32
0
        public void subset_by_key_filter()
        {
            var data = new SettingsData(SettingCategory.core);
            data.With("One.A", "1");
            data.With("One.B", "2");
            data.With("One.C", "1");
            data.With("Two.A", "11");
            data.With("Two.B", "12");
            data.With("Two.C", "13");
            data.With("Two.D", "14");
            data.With("Three.A", "21");
            data.With("Three.B", "22");
            data.With("Three.C", "23");

            var subsetA = data.SubsetByKey(key => key.Contains("A"));
            subsetA.AllKeys.ShouldHaveTheSameElementsAs("One.A", "Two.A", "Three.A");
            subsetA.Get("One.A").ShouldEqual("1");

            var subsetOne = data.SubsetByKey(key => key.StartsWith("One"));
            subsetOne.AllKeys.ShouldHaveTheSameElementsAs("One.A", "One.B", "One.C");
        }
Esempio n. 33
0
 public static void WriteToDirectory(SettingsData data, string directory)
 {
     data.Category = SettingCategory.package;
     XmlSettingsParser.Write(data, directory.AppendPath(FILE));
 }
Esempio n. 34
0
 public static void ReadFromFile(string file, SettingsData data)
 {
     StringPropertyReader.ForFile(file).ReadProperties((key, value) => data[key] = value);
 }
        public AppSettingsProvider(IObjectResolver resolver)
        {
            _resolver = resolver;

            _values = new Lazy <IValueSource>(() => SettingsData.For(new AppSettingsKeyValues()));
        }
Esempio n. 36
0
 public static SettingsRequestData For(params SettingsData[] data)
 {
     return(new SettingsRequestData(SettingsData.Order(data)));
 }
Esempio n. 37
0
        public void SetUp()
        {
            var xml = @"
            <appSettings>
              <add key='EntitySettings.DefaultUserCalendar' value='M-F 9-5'/>

              <add key='AttachmentSettings.MaximumFileSizeKB' value='10240'/>

              <add key='DatabaseSettings.ConnectionString' value='DbConnectionString' />
              <add key='DatabaseSettings.Dialect' value='NHibernate.Dialect.MsSql2005Dialect' />
              <add key='DatabaseSettings.Driver' value='NHibernate.Driver.SqlClientDriver' />
              <add key='DatabaseSettings.Provider' value='NHibernate.Connection.DriverConnectionProvider' />
              <add key='DatabaseSettings.ProxyFactory' value='NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' />
              <add key='DatabaseSettings.ShowSql' value='false' />
              <add key='DatabaseSettings.UseOuterJoin' value='True' />
              <add key='DatabaseSettings.GenerateStatistics' value='true'/>

              <add key='EmailEngineSettings.AdministratorEmail' value='*****@*****.**'/>
              <add key='EmailEngineSettings.PollingFrequency' value='15'/>

              <add key='EmailSettings.IncomingEmailCaseIdentifierPattern' value='About(\s*Case)?\s*(?&lt;Identifier>[\d\-]+)'/>
              <add key='EmailSettings.LogEmailReplyToAddress' value='*****@*****.**'/>
              <add key='EmailSettings.OutgoingDefaultFromEmail' value='*****@*****.**'/>
              <add key='EmailSettings.OutgoingEmailSubjectPrefix' value='About Case'/>
              <add key='EmailSettings.SmtpEnableSsl' value='false'/>
              <add key='EmailSettings.SmtpHostAddress' value='127.0.0.1'/>
              <add key='EmailSettings.SmtpPort' value='25'/>
              <add key='EmailSettings.UseSmtpCredentials' value='false'/>

              <add key='IntegratedAuthenticationSettings.DefaultSite' value='Default Site'/>
              <add key='IntegratedAuthenticationSettings.InternalSiteType' value='Internal'/>

              <add key='LocalizationSettings.PrependCultureOnMissing' value='true'/>

              <add key='PollingServiceSettings.FrequencyInSeconds' value='5' />

              <add key='SearchSettings.IndexFilesPath' value='A thingie'/>

              <add key='SearchSettings.LuceneParams' value='(+domain:case +({0})) OR (+domain:solution -status:expired +({0})) OR (+domain:externalfile +({0}))'/>
              <add key='SearchSettings.NumberOfIndexChangesBeforeOptimization' value='500'/>
              <add key='SearchSettings.LuceneMaximumClauseCount' value='1024'/>
              <add key='SearchSettings.SelfServiceLuceneParams' value='+domain:solution +public:true +status:published +({0})'/>

              <add key='WebsiteSettings.MaxNotificationDisplayCount' value='10'/>

              <add key='WebsiteSettings.PublicReportFrameUrlBase' value='http://localhost/DovetailCRM.Reports/reportlist.aspx' />
              <add key='WebsiteSettings.PublicReportListUrl' value='http://localhost/DovetailCRM.Reports/reports.axd'/>
              <add key='WebsiteSettings.PublicReportWidgetUrlBase' value='http://localhost/DovetailCRM.Reports/DashboardReportViewer.aspx'/>

              <add key='WebsiteSettings.PublicMobileUrlBase' value='http://localhost/mobile' />
              <add key='WebsiteSettings.PublicUrlBase' value='http://localhost/DovetailCRM/' />
              <add key='WebsiteSettings.DiagnosticsEnabled' value='true' />
              <add key='WebsiteSettings.CustomViewPath' value='Overrides' />
              <add key='WebsiteSettings.AnonymousAccessFileExtensions' value='gif, png, jpg, css, js, htm, html' />

            </appSettings>
            ".Replace("'", "\"");

            var document = new XmlDocument();
            document.LoadXml(xml);

            theSettings =XmlSettingsParser.Parse(document.DocumentElement);
        }
Esempio n. 38
0
 public void Add(SettingsData data)
 {
     _settings.Add(data);
 }