コード例 #1
0
        public KetchupConfig ToKetchupConfig()
        {
            var config = new KetchupConfig();

            //nodes;
            foreach (ConfigNode cn in ConfigNodes)
                config.AddNode(cn.Host);

            //buckets;
            foreach (ConfigBucket cb in ConfigBuckets) {
                var bucket = new Bucket()
                {
                    Name = cb.Name,
                    Port = cb.Port,
                    Prefix = cb.Prefix
                };

                foreach (ConfigNode cbn in cb.ConfigNodes)
                    bucket.ConfigNodes.Add(cbn.Host);

                config.AddBucket(bucket);
            }

            //settings;
            foreach (ConfigSetting sa in ConfigSettings) {
                int sh;
                bool bo;

                switch (sa.Name) {
                    case "compression":
                        if (!bool.TryParse(sa.Value, out bo))
                            throw new ConfigurationErrorsException("Compression setting was not a valid boolean, use 'true' or 'false'");

                        config.Compression = bo;
                        break;
                    case "failover":
                        if (!bool.TryParse(sa.Value, out bo))
                            throw new ConfigurationErrorsException("Failover setting was not a valid boolean, use 'true' or 'false'");

                        config.Failover = bo;
                        break;
                    case "connectionRetryDelay":
                        if (!int.TryParse(sa.Value, out sh))
                            throw new ConfigurationErrorsException("ConnectionRetryDelay was not a valid integer in milliseconds");

                        config.ConnectionRetryDelay = new TimeSpan(0, 0, 0, 0, sh);
                        break;
                    case "connectionRetryCount":
                        if (!int.TryParse(sa.Value, out sh))
                            throw new ConfigurationErrorsException("ConnectionRetryCount was not a valid integer");

                        config.ConnectionRetryCount = sh;
                        break;
                    case "connectionTimeout":
                        if (!int.TryParse(sa.Value, out sh))
                            throw new ConfigurationErrorsException("ConnectionTimeout was not a valid integer in millisecods");

                        config.ConnectionTimeout = new TimeSpan(0, 0, 0, 0, sh);
                        break;
                    case "deadNodeRetryDelay":
                        if (!int.TryParse(sa.Value, out sh))
                            throw new ConfigurationErrorsException("DeadNodeRetryDelay was not a valid int integer in miliseconds");

                        config.DeadNodeRetryDelay = new TimeSpan(0, 0, 0, 0, sh);
                        break;
                }
            }

            return config;
        }
コード例 #2
0
ファイル: KetchupConfig.cs プロジェクト: sdether/Ketchup
 public static KetchupConfig Init(KetchupConfig config, KetchupClient client)
 {
     config.Init(client);
     return config;
 }