Esempio n. 1
0
        public virtual string GetPropertyNameFor(Type type)
        {
#if !PCL
            return(DynamicPropertyCache.GetOrAdd(
                       type,
                       t => DynamicPropertyFactory.PropertyFor(GetPropertyFor(type))).Name);
#else
            if (DynamicPropertyCache.ContainsKey(type))
            {
                return(DynamicPropertyCache[type].Name);
            }

            lock (DynamicPropertyCache)
            {
                if (DynamicPropertyCache.ContainsKey(type))
                {
                    return(DynamicPropertyCache[type].Name);
                }

                var r = DynamicPropertyFactory.PropertyFor(GetPropertyFor(type));
                DynamicPropertyCache.Add(type, r);

                return(r.Name);
            }
#endif
        }
Esempio n. 2
0
        protected virtual IStringSetter GetSetterFor(Type type)
        {
#if !PCL
            return(DynamicPropertyCache.GetOrAdd(
                       type,
                       t => DynamicPropertyFactory.PropertyFor(GetPropertyFor(type))).Setter);
#else
            if (DynamicPropertyCache.ContainsKey(type))
            {
                return(DynamicPropertyCache[type].Setter);
            }

            lock (DynamicPropertyCache)
            {
                if (DynamicPropertyCache.ContainsKey(type))
                {
                    return(DynamicPropertyCache[type].Setter);
                }

                var r = DynamicPropertyFactory.PropertyFor(GetPropertyFor(type));
                DynamicPropertyCache.Add(type, r);

                return(r.Setter);
            }
#endif
        }
Esempio n. 3
0
        public void TestInstall()
        {
            ConfigurationManager.GetConfigInstance().SetProperty("prop1", "abc");
            Assert.AreEqual("abc", ConfigurationManager.GetConfigInstance().GetProperty("prop1"));
            Assert.AreEqual("abc", m_Prop1.Value);
            ConcurrentDictionaryConfiguration newConfig = new ConcurrentDictionaryConfiguration();

            newConfig.SetProperty("prop1", "fromNewConfig");
            ConfigurationManager.Install(newConfig);
            Assert.AreEqual("fromNewConfig", ConfigurationManager.GetConfigInstance().GetProperty("prop1"));
            Assert.AreEqual("fromNewConfig", m_Prop1.Value);
            newConfig.SetProperty("prop1", "changed");
            Assert.AreEqual("changed", ConfigurationManager.GetConfigInstance().GetProperty("prop1"));
            Assert.AreEqual("changed", m_Prop1.Value);
            try
            {
                ConfigurationManager.Install(new ConcurrentDictionaryConfiguration());
                Assert.Fail("InvalidOperationException expected");
            }
            catch (InvalidOperationException e)
            {
            }
            try
            {
                DynamicPropertyFactory.InitWithConfigurationSource(new ConcurrentDictionaryConfiguration());
                Assert.Fail("InvalidOperationException expected");
            }
            catch (InvalidOperationException e)
            {
            }
        }
Esempio n. 4
0
        public void TestIncrementalPollingSource()
        {
            var config = new ConcurrentDictionaryConfiguration();

            DynamicPropertyFactory.InitWithConfigurationSource(config);
            DynamicStringProperty prop1 = new DynamicStringProperty("prop1", null);
            DynamicStringProperty prop2 = new DynamicStringProperty("prop2", null);

            config.AddProperty("prop1", "original");
            DummyPollingSource         source    = new DummyPollingSource(true);
            FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, true);

            scheduler.IgnoreDeletesFromSource = false;
            // ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source,scheduler);
            scheduler.StartPolling(source, config);
            Assert.AreEqual("original", config.GetProperty("prop1"));
            Assert.AreEqual("original", prop1.Value);
            source.SetAdded("prop2=new");
            Thread.Sleep(200);
            Assert.AreEqual("original", config.GetProperty("prop1"));
            Assert.AreEqual("new", config.GetProperty("prop2"));
            Assert.AreEqual("new", prop2.Value);
            source.SetDeleted("prop1=DoesNotMatter");
            source.SetChanged("prop2=changed");
            source.SetAdded("");
            Thread.Sleep(200);
            Assert.IsFalse(config.ContainsKey("prop1"));
            Assert.IsNull(prop1.Value);
            Assert.AreEqual("changed", config.GetProperty("prop2"));
            Assert.AreEqual("changed", prop2.Value);
        }
Esempio n. 5
0
        public void It_Creates_With_No_Value()
        {
            var factory = new DynamicPropertyFactory();

            var property = factory.Create <TestEntity>(DefaultPropertyName);

            property.Value.Should().BeNull();
        }
Esempio n. 6
0
        public static void FixtureSetUp()
        {
            CreateConfigFile();

            m_Config = new DynamicUrlConfiguration(100, 500, false, m_ConfigFile);
            Console.WriteLine("Initializing with sources: " + m_Config.Source);
            DynamicPropertyFactory.InitWithConfigurationSource(m_Config);
        }
Esempio n. 7
0
        public void TestGetSource()
        {
            DynamicPropertyFactory.GetInstance();
            var defaultConfig = DynamicPropertyFactory.BackingConfigurationSource;

            Assert.IsTrue(defaultConfig is ConcurrentCompositeConfiguration);
            Assert.IsTrue(DynamicPropertyFactory.InitializedWithDefaultConfig);
        }
Esempio n. 8
0
        public void It_Creates_From_Task_With_No_Value()
        {
            var source  = new TaskCompletionSource <TestEntity>();
            var factory = new DynamicPropertyFactory();

            var property = factory.CreateFromTask(DefaultPropertyName, _ => source.Task);

            property.Value.Should().BeNull();
        }
Esempio n. 9
0
        public void It_Creates_From_Observable_With_No_Value()
        {
            var source  = new Subject <TestEntity>();
            var factory = new DynamicPropertyFactory();

            var property = factory.CreateFromObservable(DefaultPropertyName, source);

            property.Value.Should().BeNull();
        }
Esempio n. 10
0
        public void It_Creates_With_Value()
        {
            var myValue = new TestEntity();
            var factory = new DynamicPropertyFactory();

            var property = factory.Create(DefaultPropertyName, myValue);

            property.Value.Should().Be(myValue);
        }
Esempio n. 11
0
        public void TestPropertyCreation()
        {
            m_Config.StopLoading();
            const string newValue          = "newValue";
            var          callbackTriggered = false;
            EventHandler callback          = (s, a) => callbackTriggered = true;
            var          prop = DynamicPropertyFactory.GetInstance().GetStringProperty("foo.bar", "xyz", callback);

            Assert.AreEqual("xyz", prop.Value);
            m_Config.SetProperty("foo.bar", newValue);
            Assert.IsTrue(callbackTriggered);
            Assert.AreEqual(newValue, prop.Value);
            Assert.IsTrue(prop.Property.PropertyChangedHandlers.Any(h => h == callback));
        }
Esempio n. 12
0
 /// <summary>
 /// Install the system wide configuration with the ConfigurationManager. This will also install
 /// the configuration with the <see cref="DynamicPropertyFactory"/> by calling <see cref="DynamicPropertyFactory.InitWithConfigurationSource"/>.
 /// This call can be made only once, otherwise IllegalStateException will be thrown.
 /// </summary>
 /// <param name="config"></param>
 public static void Install(AbstractConfiguration config)
 {
     lock (m_ClassLock)
     {
         if (m_CustomConfigurationInstalled)
         {
             throw new InvalidOperationException("A non-default configuration is already installed");
         }
         SetDirect(config);
         if (DynamicPropertyFactory.BackingConfigurationSource != config)
         {
             DynamicPropertyFactory.InitWithConfigurationSource(config);
         }
     }
 }
Esempio n. 13
0
        public void TestProperties()
        {
            ConcurrentCompositeConfiguration config          = new ConcurrentCompositeConfiguration();
            DynamicPropertyFactory           factory         = DynamicPropertyFactory.InitWithConfigurationSource(config);
            DynamicStringProperty            prop1           = factory.GetStringProperty("prop1", null);
            DynamicStringProperty            prop2           = factory.GetStringProperty("prop2", null);
            DynamicStringProperty            prop3           = factory.GetStringProperty("prop3", null);
            DynamicStringProperty            prop4           = factory.GetStringProperty("prop4", null);
            AbstractConfiguration            containerConfig = new ConcurrentDictionaryConfiguration();

            containerConfig.AddProperty("prop1", "prop1");
            containerConfig.AddProperty("prop2", "prop2");
            AbstractConfiguration baseConfig = new ConcurrentDictionaryConfiguration();

            baseConfig.AddProperty("prop3", "prop3");
            baseConfig.AddProperty("prop1", "prop1FromBase");
            // Make container configuration the highest priority
            config.SetContainerConfiguration(containerConfig, "container configuration", 0);
            config.AddConfiguration(baseConfig, "base configuration");
            Assert.AreEqual("prop1", config.GetProperty("prop1"));
            Assert.AreEqual("prop1", prop1.Value);
            Assert.AreEqual("prop2", prop2.Value);
            Assert.AreEqual("prop3", prop3.Value);
            containerConfig.SetProperty("prop1", "newvalue");
            Assert.AreEqual("newvalue", prop1.Value);
            Assert.AreEqual("newvalue", config.GetProperty("prop1"));
            baseConfig.AddProperty("prop4", "prop4");
            Assert.AreEqual("prop4", config.GetProperty("prop4"));
            Assert.AreEqual("prop4", prop4.Value);
            baseConfig.SetProperty("prop1", "newvaluefrombase");
            Assert.AreEqual("newvalue", prop1.Value);
            containerConfig.ClearProperty("prop1");
            Assert.AreEqual("newvaluefrombase", config.GetProperty("prop1"));
            Assert.AreEqual("newvaluefrombase", prop1.Value);
            config.SetOverrideProperty("prop2", "overridden");
            config.SetProperty("prop2", "fromContainer");
            Assert.AreEqual("overridden", config.GetProperty("prop2"));
            Assert.AreEqual("overridden", prop2.Value);
            config.clearOverrideProperty("prop2");
            Assert.AreEqual("fromContainer", prop2.Value);
            Assert.AreEqual("fromContainer", config.GetProperty("prop2"));
            config.SetProperty("prop3", "fromContainer");
            Assert.AreEqual("fromContainer", prop3.Value);
            Assert.AreEqual("fromContainer", config.GetProperty("prop3"));
            config.ClearProperty("prop3");
            Assert.AreEqual("prop3", prop3.Value);
            Assert.AreEqual("prop3", config.GetProperty("prop3"));
        }
Esempio n. 14
0
 public virtual string GetPropertyNameFor(Type type)
 {
     return(DynamicPropertyCache.GetOrAdd(
                type,
                t => DynamicPropertyFactory.PropertyFor(GetPropertyFor(type))).Name);
 }
Esempio n. 15
0
 protected virtual IStringSetter GetSetterFor(Type type)
 {
     return(DynamicPropertyCache.GetOrAdd(
                type,
                t => DynamicPropertyFactory.PropertyFor(GetPropertyFor(type))).Setter);
 }