コード例 #1
0
        public RouteContext Decorate(RouteContext routeContext, ShardingConnectorMetaData metaData, ShardingRule shardingRule,
                                     ConfigurationProperties properties)
        {
            var sqlStatementContext = routeContext.GetSqlCommandContext();
            // var tableNames = sqlStatementContext.GetTablesContext().GetTableNames();
            // if (!shardingRule.TableRules.Any(o => tableNames.Any(t => o.LogicTable.EqualsIgnoreCase(t))))
            // {
            //     return routeContext;
            // }
            var parameters = routeContext.GetParameterContext();

            ShardingCommandValidatorFactory.NewInstance(
                sqlStatementContext.GetSqlCommand())
            .IfPresent(validator => validator.Validate(shardingRule, sqlStatementContext.GetSqlCommand(), parameters));
            ShardingConditions shardingConditions = GetShardingConditions(parameters, sqlStatementContext, metaData.Schema, shardingRule);
            var needMergeShardingValues           = IsNeedMergeShardingValues(sqlStatementContext, shardingRule);

            if (needMergeShardingValues && sqlStatementContext.GetSqlCommand() is DMLCommand)
            {
                CheckSubQueryShardingValues(sqlStatementContext, shardingRule, shardingConditions);
                MergeShardingConditions(shardingConditions);
            }
            var         shardingRouteEngine = ShardingRouteEngineFactory.NewInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, properties);
            RouteResult routeResult         = shardingRouteEngine.Route(shardingRule);

            if (needMergeShardingValues)
            {
                ShardingAssert.Else(1 == routeResult.GetRouteUnits().Count, "Must have one sharding with sub query.");
            }
            return(new RouteContext(sqlStatementContext, parameters, routeResult));
        }
コード例 #2
0
 public ShardingStandardRoutingEngine(string logicTableName, ISqlCommandContext <ISqlCommand> sqlCommandContext, ShardingConditions shardingConditions, ConfigurationProperties properties)
 {
     this.LogicTableName     = logicTableName;
     this.SqlCommandContext  = sqlCommandContext;
     this.ShardingConditions = shardingConditions;
     this.Properties         = properties;
 }
コード例 #3
0
        public void SaveConfigurationSettings(MainViewModel viewModel)
        {
            if (_commonProperties == null || _commonProperties.Version != Constants.Version)
            {
                SetDefaultProperties();
            }

            var configProps = new ConfigurationProperties
            {
                MinimizeOnStartUp       = viewModel.MinimizeOnStartUp,
                ExecuteOnStartUp        = viewModel.ExecuteOnStartUp,
                AlertTime               = viewModel.MinutesAlert,
                LunchBreakTime          = viewModel.MinutesBreak,
                EmailCheckBox           = viewModel.EmailCheckBox,
                ExtraTimeWorked         = viewModel.ExtraTimeWorked,
                SoundWarning            = viewModel.SoundWarning,
                TimeLogging             = viewModel.TimeLogging,
                TimeLogFileLocationName = viewModel.TimeLogFileLocationName,
                WorkingDaysPerWeek      = viewModel.WorkingDaysPerWeek,
                WorkingHoursPerWeek     = viewModel.WorkingHoursPerWeek
            };

            if (_commonProperties != null)
            {
                _commonProperties.ConfigurationProperties = configProps;
            }
            SaveFile();
        }
コード例 #4
0
        public virtual void TestDynamicProperty()
        {
            MemoryDictionaryConfigurationSource source = CreateSource();

            source.SetPropertyValue("exist", "ok");

            IConfigurationManager           manager        = CreateManager(source);
            PropertyConfig <String, String> propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>()
                                                             .SetKey("exist").SetDefaultValue("default").Build();
            IProperty <String, String> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok", property.Value);

            source.SetPropertyValue("exist", "ok2");
            Thread.Sleep(10);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok2", property.Value);

            source.SetPropertyValue("exist", "ok3");
            Thread.Sleep(10);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok3", property.Value);

            source.SetPropertyValue("exist", "ok4");
            Thread.Sleep(10);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok4", property.Value);
        }
コード例 #5
0
        public ICollection <string> DoSharding(ICollection <string> availableTargetNames, ICollection <IRouteValue> shardingValues,
                                               ConfigurationProperties properties)
        {
            IDictionary <string, ICollection <IComparable> > columnShardingValues =
                new Dictionary <string, ICollection <IComparable> >(shardingValues.Count);
            IDictionary <string, Range <IComparable> > columnRangeValues = new Dictionary <string, Range <IComparable> >(shardingValues.Count);
            string logicTableName = "";

            foreach (var shardingValue in shardingValues)
            {
                if (shardingValue is ListRouteValue listRouteValue)
                {
                    columnShardingValues.Add(shardingValue.GetColumnName(), listRouteValue.GetValues());
                }
                else if (shardingValue is RangeRouteValue rangeRouteValue)
                {
                    columnRangeValues.Add(shardingValue.GetColumnName(), rangeRouteValue.GetValueRange());
                }
                logicTableName = shardingValue.GetTableName();
            }
            var shardingResult = shardingAlgorithm.DoSharding(availableTargetNames, new ComplexKeysShardingValue <IComparable>(logicTableName, columnShardingValues, columnRangeValues));
            var result         = new SortedSet <string>(StringComparer.OrdinalIgnoreCase);

            result.AddAll(shardingResult);
            return(result);
        }
コード例 #6
0
        public virtual void TestGetPropertyWithFilter()
        {
            IConfigurationManager manager = CreateManager(new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("exist").SetValueFilter(v =>
            {
                if (Object.Equals("ok", v))
                {
                    return("ok_new");
                }
                return(null);
            }).Build();
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok_new", property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey("exist2")
                             .SetValueFilter(v =>
            {
                return(v.Length >= 8 && v.Length <= 32 ? v : null);
            }).Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);
        }
コード例 #7
0
 public ShardingComplexRoutingEngine(ICollection <string> logicTables, ISqlCommandContext <ISqlCommand> sqlStatementContext, ShardingConditions shardingConditions, ConfigurationProperties properties)
 {
     this.logicTables         = logicTables;
     this.sqlStatementContext = sqlStatementContext;
     this.shardingConditions  = shardingConditions;
     this.properties          = properties;
 }
コード例 #8
0
        public virtual void TestGetPropertyWithDynamicSource()
        {
            TestDynamicConfigurationSource source  = CreateDynamicSource();
            IConfigurationManager          manager = CreateManager(new Dictionary <int, IConfigurationSource>()
            {
                { 1, source }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("exist").Build();
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok.2", property.Value);

            source.SetPropertyValue("exist", "okx");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("okx", property.Value);

            source.SetPropertyValue("exist", "ok.2");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok.2", property.Value);

            ObjectReference <bool> touched = new ObjectReference <bool>();

            property.OnChange += (o, e) => touched.Value = true;
            property.OnChange += (o, e) => Console.WriteLine("property: {0}, changeTime: {1}, from: {2}, to: {3}\n",
                                                             e.Property, e.ChangeTime, e.OldValue, e.NewValue);
            source.SetPropertyValue("exist", "okx");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("okx", property.Value);
            Assert.True(touched.Value);
        }
コード例 #9
0
        public virtual void TestGetPropertyWithDiffFilterInSimilarConfig()
        {
            IConfigurationManager manager = CreateManager(new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("exist").SetValueFilter(v =>
            {
                if (Object.Equals("ok", v))
                {
                    return("ok_new");
                }
                return(null);
            }).Build();

            Console.WriteLine("propertyConfig: " + propertyConfig + "\n");
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Assert.Equal("ok_new", property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey("exist")
                             .SetValueFilter(v =>
            {
                if (Object.Equals("ok", v))
                {
                    return("ok_new");
                }
                return(null);
            }).Build();
            Console.WriteLine("propertyConfig: " + propertyConfig + "\n");
            Assert.Throws <ArgumentException>(() => manager.GetProperty(propertyConfig));
        }
コード例 #10
0
        public void TestPropertyConfigRequiredDefault()
        {
            bool   required               = false;
            string key                    = "not-exist";
            string defaultValue           = "default";
            IConfigurationManager manager = CreateManager(
                new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey(key).SetDefaultValue(defaultValue).Build();

            Assert.Equal(required, propertyConfig.IsRequired);
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Assert.Equal(required, property.Config.IsRequired);
            string value = manager.GetPropertyValue(propertyConfig);

            Assert.Equal(defaultValue, value);

            required       = true;
            key            = "not-exist-2";
            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey(key)
                             .SetRequired(required).SetDefaultValue(defaultValue).Build();
            Assert.Equal(required, propertyConfig.IsRequired);
            property = manager.GetProperty(propertyConfig);
            value    = manager.GetPropertyValue(propertyConfig);
            Assert.Equal(defaultValue, value);
        }
コード例 #11
0
        public void TestPropertyConfigDoc()
        {
            string doc = null;
            string key = "not-exist";
            IConfigurationManager manager = CreateManager(
                new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties
                                                             .NewConfigBuilder <string, string>().SetKey(key).Build();

            Assert.Equal(doc, propertyConfig.Doc);
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Assert.Equal(doc, property.Config.Doc);

            doc            = "test-doc";
            key            = "not-exist-2";
            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                             .SetKey(key).SetDoc(doc).Build();
            Assert.Equal(doc, propertyConfig.Doc);
            property = manager.GetProperty(propertyConfig);
            Assert.Equal(doc, property.Config.Doc);
        }
コード例 #12
0
        public virtual void TestGetProperties()
        {
            IConfigurationManager manager = CreateManager(new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("not-exist").Build();
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey("not-exist2")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("default", property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey("exist")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok", property.Value);

            PropertyConfig <string, int> propertyConfig2 = ConfigurationProperties.NewConfigBuilder <string, int>()
                                                           .SetKey("exist2").Build();
            IProperty <string, int> property2 = manager.GetProperty(propertyConfig2);

            Console.WriteLine("property: " + property2 + "\n");
            Assert.Equal(0, property2.Value);
        }
コード例 #13
0
        public virtual void TestGetProperties(string kv)
        {
            string[] commandLineArgs = kv == null ? null : new string[] { kv };
            IConfigurationManager           manager        = CreateManager(commandLineArgs);
            PropertyConfig <String, String> propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>()
                                                             .SetKey("not-exist").Build();
            IProperty <String, String> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>().SetKey("not-exist2")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("default", property.Value);

            if (commandLineArgs == null)
            {
                return;
            }

            propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>().SetKey("exist")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok", property.Value);
        }
コード例 #14
0
        public virtual void TestGetProperties(AppSettingsType type)
        {
            String propertyValue = ConfigurationManager.AppSettings["not-exist"];

            Assert.Null(propertyValue);

            IConfigurationManager           manager        = CreateManager(type);
            PropertyConfig <String, String> propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>()
                                                             .SetKey("not-exist").Build();
            IProperty <String, String> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>().SetKey("not-exist2")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("default", property.Value);

            if (type == AppSettingsType.AppConfig)
            {
                return;
            }

            propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>().SetKey("exist")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok", property.Value);
        }
コード例 #15
0
        public virtual void TestSameConfigSameProperty()
        {
            IConfigurationManager manager = CreateManager(new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("not-exist").Build();
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            IProperty <string, string> property2 = manager.GetProperty(propertyConfig);

            Console.WriteLine("property2: " + property + "\n");
            Assert.True(Object.ReferenceEquals(property, property2));

            PropertyConfig <string, string> propertyConfig2 = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                              .SetKey("not-exist").Build();
            IProperty <string, string> property3 = manager.GetProperty(propertyConfig2);

            Console.WriteLine("property3: " + property2 + "\n");
            Assert.True(Object.ReferenceEquals(property, property3));
        }
コード例 #16
0
        public void TestGetPropertyWithConverter()
        {
            IConfigurationManager manager = CreateManager(
                new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, int?> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, int?>()
                                                           .SetKey("exist_int").AddValueConverter(NewTypeConverter()).Build();
            IProperty <string, int?> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Equal(1, property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, int?>()
                             .SetKey("exist").AddValueConverter(NewTypeConverter()).Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, int?>()
                             .SetKey("not_exist").AddValueConverter(NewTypeConverter()).Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);
        }
コード例 #17
0
 protected BasePrepareEngine(ICollection <IBaseRule> rules, ConfigurationProperties properties, ShardingConnectorMetaData metaData, SqlParserEngine sqlParserEngine)
 {
     _router     = new DataNodeRouter(metaData, sqlParserEngine, properties);
     _rules      = rules;
     _properties = properties;
     _metaData   = metaData;
     _rewriter   = new SqlRewriteEntry(metaData.Schema, properties);
 }
コード例 #18
0
        public void TestTimeout()
        {
            ConnectorInfoManager manager = GetConnectorInfoManager();
            ConnectorInfo        info1   = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector");

            Assert.IsNotNull(info1);

            APIConfiguration config = info1.CreateDefaultAPIConfiguration();

            config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(CreateApiOp)), 5000);
            config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(SearchApiOp)), 5000);
            ConfigurationProperties props    = config.ConfigurationProperties;
            ConfigurationProperty   property = props.GetProperty("numResults");

            // 1000 is several times the remote size between pauses
            property.Value = 2;
            OperationOptionsBuilder opBuilder = new OperationOptionsBuilder();

            opBuilder.SetOption("delay", 10000);

            ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config);

            ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>();

            try
            {
                facade1.Create(ObjectClass.ACCOUNT, attrs, opBuilder.Build()).GetUidValue();
                Assert.Fail("expected timeout");
            }
            catch (OperationTimeoutException)
            {
                // expected
            }
            //catch (RemoteWrappedException e)
            //{
            //    Assert.IsTrue(e.Is(typeof(OperationTimeoutException)));
            //}

            try
            {
                facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler()
                {
                    Handle = obj =>
                    {
                        return(true);
                    }
                }, opBuilder.Build());
                Assert.Fail("expected timeout");
            }
            catch (OperationTimeoutException)
            {
                // expected
            }
            //catch (RemoteWrappedException e)
            //{
            //    Assert.IsTrue(e.Is(typeof(OperationTimeoutException)));
            //}
        }
コード例 #19
0
        private void SetConfigurationProperties(ConfigurationProperties configProps)
        {
            var fd = new KeyValueListCM(
                new KeyValueDTO("SelectedProjectKey", configProps.SelectedProjectKey),
                new KeyValueDTO("SelectedIssueType", configProps.SelectedIssueType)
                );

            Storage.ReplaceByLabel(Crate.FromContent(ConfigurationPropertiesLabel, fd));
        }
コード例 #20
0
        public virtual void TestGetPropertyWithComparator()
        {
            TestDynamicConfigurationSource source  = CreateDynamicSource();
            IConfigurationManager          manager = CreateManager(new Dictionary <int, IConfigurationSource>()
            {
                { 1, source }
            });
            HashSet <string> equalsSet = new HashSet <string>()
            {
                "e.1", "e.2"
            };
            Func <string, string, int> customComparator = (o1, o2) =>
            {
                if (equalsSet.Contains(o1) && equalsSet.Contains(o2))
                {
                    return(0);
                }
                return(o1 == o2 ? 0 : -1);
            };
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("exist").SetValueComparator(customComparator).Build();
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok.2", property.Value);

            source.SetPropertyValue("exist", "okx");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("okx", property.Value);

            source.SetPropertyValue("exist", "ok.2");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok.2", property.Value);

            ObjectReference <bool> touched = new ObjectReference <bool>();

            property.OnChange += (o, e) => touched.Value = true;
            property.OnChange += (o, e) => Console.WriteLine("property: {0}, changeTime: {1}, from: {2}, to: {3}\n",
                                                             e.Property, e.ChangeTime, e.OldValue, e.NewValue);
            source.SetPropertyValue("exist", "okx");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("okx", property.Value);
            Assert.True(touched.Value);

            source.SetPropertyValue("exist", "e.1");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("e.1", property.Value);

            source.SetPropertyValue("exist", "e.2");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("e.1", property.Value);

            source.SetPropertyValue("exist", "n.1");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("n.1", property.Value);
        }
コード例 #21
0
        public virtual void TestDemo()
        {
            // create a scf yaml configuration source
            YamlFileConfigurationSourceConfig sourceConfig = new YamlFileConfigurationSourceConfig.Builder()
                                                             .SetName("yaml-file").SetFileName("test.yaml").Build();
            YamlFileConfigurationSource source = new YamlFileConfigurationSource(sourceConfig);

            // create scf manager & properties facade tool
            ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("my-app")
                                                       .AddSource(1, source).Build();
            IConfigurationManager manager = ConfigurationManagers.NewManager(managerConfig);

            PropertyConfig <string, bool?> propertyConfig1 = ConfigurationProperties.NewConfigBuilder <string, bool?>()
                                                             .SetKey("booleanProperty").SetDefaultValue(false).Build();
            bool?boolValue = manager.GetPropertyValue(propertyConfig1);

            Console.WriteLine(boolValue);

            PropertyConfig <string, int?> propertyConfig2 = ConfigurationProperties.NewConfigBuilder <string, int?>()
                                                            .SetKey("intProperty").SetDefaultValue(0).Build();
            int?intValue = manager.GetPropertyValue(propertyConfig2);

            Console.WriteLine(intValue);

            PropertyConfig <string, long?> propertyConfig3 = ConfigurationProperties.NewConfigBuilder <string, long?>()
                                                             .SetKey("longProperty").SetDefaultValue(0L).Build();
            long?longValue = manager.GetPropertyValue(propertyConfig3);

            Console.WriteLine(longValue);

            PropertyConfig <string, string> propertyConfig4 = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                              .SetKey("stringProperty").Build();
            string stringValue = manager.GetPropertyValue(propertyConfig4);

            Console.WriteLine(stringValue);

            PropertyConfig <string, List <string> > propertyConfig5 = ConfigurationProperties
                                                                      .NewConfigBuilder <string, List <string> >().SetKey("listProperty").Build();
            List <string> listValue = manager.GetPropertyValue(propertyConfig5);

            Console.WriteLine(listValue == null ? null : string.Join(", ", listValue));

            PropertyConfig <string, Dictionary <string, string> > propertyConfig6 = ConfigurationProperties
                                                                                    .NewConfigBuilder <string, Dictionary <string, string> >().SetKey("mapProperty").Build();
            Dictionary <string, string> mapValue = manager.GetPropertyValue(propertyConfig6);

            Console.WriteLine(mapValue == null ? null :
                              (string.Join(", ", mapValue.Select(p => string.Format("{0}: {1}", p.Key, p.Value)).ToList())));

            PropertyConfig <string, TestPojo> propertyConfig7 = ConfigurationProperties.NewConfigBuilder <string, TestPojo>()
                                                                .SetKey("objProperty").Build();
            TestPojo objValue = manager.GetPropertyValue(propertyConfig7);

            Console.WriteLine(objValue);
        }
コード例 #22
0
        private static void InitConfig()
        {
            // create a non-dynamic K/V (string/string) configuration source
            PropertiesFileConfigurationSourceConfig sourceConfig = StringPropertySources
                                                                   .NewPropertiesFileSourceConfigBuilder().SetName("app-properties-file").SetFileName("app.properties")
                                                                   .Build();
            IConfigurationSource source = StringPropertySources.NewPropertiesFileSource(sourceConfig);

            // create a configuration manager with single source
            ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("little-app")
                                                       .AddSource(1, source).Build();

            _manager = ConfigurationManagers.NewManager(managerConfig);

            // default to null
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("app.id").Build();

            _appId = _manager.GetProperty(propertyConfig);

            // default to "unknown"
            PropertyConfig <string, string> propertyConfig2 = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                              .SetKey("app.name").SetDefaultValue("unknown").Build();

            _appName = _manager.GetProperty(propertyConfig2);

            // default to empty list
            PropertyConfig <string, List <string> > propertyConfig3 = ConfigurationProperties
                                                                      .NewConfigBuilder <string, List <string> >().SetKey("user.list")
                                                                      .SetDefaultValue(new List <string>()).AddValueConverter(StringToListConverter.Default).Build();

            _userList = _manager.GetProperty(propertyConfig3);

            // default to empty map
            PropertyConfig <string, Dictionary <string, string> > propertyConfig4 = ConfigurationProperties
                                                                                    .NewConfigBuilder <string, Dictionary <string, string> >().SetKey("user.data")
                                                                                    .SetDefaultValue(new Dictionary <string, string>()).AddValueConverter(StringToDictionaryConverter.Default).Build();

            _userData = _manager.GetProperty(propertyConfig4);

            // default to 1000, if value in app._properties is invalid, ignore the invalid value
            PropertyConfig <string, int?> propertyConfig5 = ConfigurationProperties.NewConfigBuilder <string, int?>()
                                                            .SetKey("sleep.time").SetDefaultValue(1000)
                                                            .AddValueConverter(StringToIntConverter.Default).SetValueFilter(v => v < 0 ? null : v).Build();

            _sleepTime = _manager.GetProperty(propertyConfig5);

            // custom type property
            PropertyConfig <string, MyCustomType> propertyConfig6 = ConfigurationProperties
                                                                    .NewConfigBuilder <string, MyCustomType>().SetKey("my-custom-type-property")
                                                                    .AddValueConverter(MyCustomType.Converter).Build();

            _myCustomData = _manager.GetProperty(propertyConfig6);
        }
コード例 #23
0
        public ICollection <string> DoSharding(ICollection <string> availableTargetNames, ICollection <IRouteValue> shardingValues,
                                               ConfigurationProperties properties)
        {
            var shardingValue  = (ListRouteValue)shardingValues.First();
            var shardingResult = ShardingAlgorithm.DoSharding(availableTargetNames,
                                                              new HintShardingValue <IComparable>(shardingValue.GetTableName(), shardingValue.GetColumnName(), shardingValue.GetValues()));
            var result = new SortedSet <string>(StringComparer.OrdinalIgnoreCase);

            result.AddAll(shardingResult);
            return(result);
        }
コード例 #24
0
        public void TestAPIConfiguration()
        {
            ConnectorInfoManager manager =
                GetConnectorInfoManager();
            ConnectorInfo info =
                FindConnectorInfo(manager,
                                  "1.0.0.0",
                                  "org.identityconnectors.testconnector.TstConnector");

            Assert.IsNotNull(info);
            APIConfiguration api = info.CreateDefaultAPIConfiguration();

            ConfigurationProperties props    = api.ConfigurationProperties;
            ConfigurationProperty   property = props.GetProperty("tstField");

            Assert.IsNotNull(property);
            ICollection <SafeType <APIOperation> > operations =
                property.Operations;

            Assert.AreEqual(1, operations.Count);
            Assert.IsTrue(operations.Contains(SafeType <APIOperation> .Get <SyncApiOp>()));

            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
            Assert.AreEqual("Help for test field.", property.GetHelpMessage(null));
            Assert.AreEqual("Display for test field.", property.GetDisplayName(null));
            Assert.AreEqual("Group for test field.", property.GetGroup(null));
            Assert.AreEqual("Test Framework Value",
                            info.Messages.Format("TEST_FRAMEWORK_KEY", "empty"));

            CultureInfo eslocale = new CultureInfo("es");

            Thread.CurrentThread.CurrentUICulture = eslocale;
            Assert.AreEqual("tstField.help_es", property.GetHelpMessage(null));
            Assert.AreEqual("tstField.display_es", property.GetDisplayName(null));

            CultureInfo esESlocale = new CultureInfo("es-ES");

            Thread.CurrentThread.CurrentUICulture = esESlocale;
            Assert.AreEqual("tstField.help_es-ES", property.GetHelpMessage(null));
            Assert.AreEqual("tstField.display_es-ES", property.GetDisplayName(null));

            CultureInfo esARlocale = new CultureInfo("es-AR");

            Thread.CurrentThread.CurrentUICulture = esARlocale;
            Assert.AreEqual("tstField.help_es", property.GetHelpMessage(null));
            Assert.AreEqual("tstField.display_es", property.GetDisplayName(null));

            ConnectorFacadeFactory facf   = ConnectorFacadeFactory.GetInstance();
            ConnectorFacade        facade = facf.NewInstance(api);

            // call the various create/update/delete commands..
            facade.Schema();
        }
コード例 #25
0
 protected AbstractRuntimeContext(T rule, IDictionary <string, object> props, IDatabaseType databaseType)
 {
     this.rule = rule;
     // properties = new ConfigurationProperties(null == props ? new Properties() : props);
     properties        = new ConfigurationProperties();
     this.databaseType = databaseType;
     executorEngine    = ExecutorEngine.Instance;
     //更加数据库类型获取对应的解析器
     sqlParserEngine = SqlParserEngineFactory.GetSqlParserEngine(DatabaseTypes.GetTrunkDatabaseTypeName(databaseType));
     // ConfigurationLogger.log(rule.getRuleConfiguration());
     // ConfigurationLogger.log(props);
 }
コード例 #26
0
        public ICollection <string> DoSharding(ICollection <string> availableTargetNames, ICollection <IRouteValue> shardingValues,
                                               ConfigurationProperties properties)
        {
            IRouteValue          shardingValue  = shardingValues.First();
            ICollection <string> shardingResult = shardingValue is ListRouteValue listRouteValue
                ? DoSharding(availableTargetNames, listRouteValue) : DoSharding(availableTargetNames, (RangeRouteValue)shardingValue);

            ICollection <string> result = new SortedSet <string>(StringComparer.OrdinalIgnoreCase);

            result.AddAll(shardingResult);
            return(result);
        }
コード例 #27
0
        private void Start(string[] args)
        {
            string[] filteredArgs = new string[0];
            if (ConfigurationProperties.Length > 0)
            {
                var switchMaps         = ConfigurationProperties.GetSwitchMaps(_namespace);
                var implicitSwitchMaps = _implicitBoolProperties.GetSwitchMaps(_namespace);
                filteredArgs = args.Except(implicitSwitchMaps.Keys, StringComparer.OrdinalIgnoreCase).ToArray();
                var configBuilder = new ConfigurationBuilder();
                AppSettings.UserConfiguration?.Invoke(configBuilder);
                var configWithoutCli = configBuilder.Build();
                configBuilder.AddCommandLine(filteredArgs, switchMaps);
                var config = configBuilder.Build();

                var            commandName = _optionsAttribute?.Namespace ?? Type.Name;
                IConfiguration configSection;
                if (_isAppRoot)
                {
                    configSection = config;
                }
                else
                {
                    configSection = config.GetSection(commandName);
                }

                IConfiguration configSectionWithoutCli;
                if (_isAppRoot)
                {
                    configSectionWithoutCli = config;
                }
                else
                {
                    configSectionWithoutCli = config.GetSection(commandName);
                }

                InjectConfigProperties(args, switchMaps, configSection, configSectionWithoutCli);

                for (var i = 0; i < filteredArgs.Length; i++)
                {
                    if (filteredArgs[i] != null && switchMaps.Keys.ContainsOrStartsWith(filteredArgs[i]))
                    {
                        if (!filteredArgs[i].Contains("=") && i + 1 < filteredArgs.Length)
                        {
                            filteredArgs[i + 1] = null;
                        }
                        filteredArgs[i] = null;
                    }
                }
            }

            OnExecute(filteredArgs.Where(s => !string.IsNullOrEmpty(s)).ToArray());
        }
コード例 #28
0
        /// <summary>
        /// The entrypoint for a single command within the command-line application.
        /// </summary>
        public CliCommand()
        {
            Type              = GetType();
            _isAppRoot        = Type.IsSubclassOf(typeof(CliApp));
            _optionsAttribute = Type.GetCustomAttribute <CliOptionsAttribute>();

            var allProps = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            ConfigurationProperties = allProps.GetConfigProperties().ToArray();
            CommandProperties       = allProps.GetCommandProperties().ToArray();
            _implicitBoolProperties = ConfigurationProperties
                                      .Where(p => p.PropertyType == typeof(bool) && !p.HasAttribute <CliExplicitBoolAttribute>())
                                      .ToArray();
        }
コード例 #29
0
 private static void RestoreConfiguration(ConfigurationProperties configProps, MainViewModel viewModel)
 {
     viewModel.MinimizeOnStartUp       = configProps.MinimizeOnStartUp;
     viewModel.ExecuteOnStartUp        = configProps.ExecuteOnStartUp;
     viewModel.MinutesAlert            = configProps.AlertTime;
     viewModel.MinutesBreak            = configProps.LunchBreakTime;
     viewModel.EmailCheckBox           = configProps.EmailCheckBox;
     viewModel.SoundWarning            = configProps.SoundWarning;
     viewModel.ExtraTimeWorked         = configProps.ExtraTimeWorked;
     viewModel.WorkingDaysPerWeek      = configProps.WorkingDaysPerWeek;
     viewModel.WorkingHoursPerWeek     = configProps.WorkingHoursPerWeek;
     viewModel.TimeLogging             = configProps.TimeLogging;
     viewModel.TimeLogFileLocationName = configProps.TimeLogFileLocationName;
 }
コード例 #30
0
        public void TestPropertyConfigRequired()
        {
            bool   required = false;
            string key      = "not-exist";
            IConfigurationManager manager = CreateManager(
                new Dictionary <int, IConfigurationSource>()
            {
                { 1, CreateSource() }
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties
                                                             .NewConfigBuilder <string, string>().SetKey(key).Build();

            Assert.Equal(required, propertyConfig.IsRequired);
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Assert.Equal(required, property.Config.IsRequired);
            string value = manager.GetPropertyValue(propertyConfig);

            Assert.Null(value);

            required       = true;
            key            = "not-exist-2";
            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey(key)
                             .SetRequired(required).Build();
            Assert.Equal(required, propertyConfig.IsRequired);
            Assert.Throws <InvalidOperationException>(() => manager.GetProperty(propertyConfig));
            Assert.Throws <InvalidOperationException>(() => manager.GetPropertyValue(propertyConfig));

            required       = false;
            key            = "exist";
            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey(key)
                             .SetRequired(required).Build();
            Assert.Equal(required, propertyConfig.IsRequired);
            property = manager.GetProperty(propertyConfig);
            Assert.Equal(required, property.Config.IsRequired);
            value = manager.GetPropertyValue(propertyConfig);
            Assert.Equal("ok", value);

            required       = true;
            key            = "exist2";
            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey(key)
                             .SetRequired(required).Build();
            Assert.Equal(required, propertyConfig.IsRequired);
            property = manager.GetProperty(propertyConfig);
            Assert.Equal(required, property.Config.IsRequired);
            value = manager.GetPropertyValue(propertyConfig);
            Assert.Equal("ok2", value);
        }