Beispiel #1
0
        internal ClientNode(ClientNodeConfiguration config, Action <ClientNode> errorAction)
        {
            if (string.IsNullOrEmpty(config.Address))
            {
                throw new ArgumentNullException(string.Format("{0}.Address"), config.Name);
            }
            if (config.Address.Split(':').Length != 2)
            {
                throw new ArgumentException(string.Format("{0}.Address格式必须为IP:Port", config.Name), "Address");
            }
            var port = 0;

            if (!int.TryParse(config.Address.Split(':')[1], out port))
            {
                throw new ArgumentException(string.Format("{0}.Address的端口号不是数字", config.Name), "Address");
            }
            if (config.MaxConnections < config.MinConnections)
            {
                throw new ArgumentException(string.Format("{0}.MaxConnections不能小于{0}.MinConnections", config.Name), "MaxConnections");
            }

            if (config.ConnectTimeout < TimeSpan.FromMilliseconds(100))
            {
                config.ConnectTimeout = TimeSpan.FromMilliseconds(100);
            }
            if (config.ReceiveTimeout < TimeSpan.FromMilliseconds(100))
            {
                config.ReceiveTimeout = TimeSpan.FromMilliseconds(100);
            }
            if (config.SendTimeout < TimeSpan.FromMilliseconds(100))
            {
                config.SendTimeout = TimeSpan.FromMilliseconds(100);
            }

            if (config.MaxIdleTime < TimeSpan.FromSeconds(1))
            {
                config.MaxIdleTime = TimeSpan.FromSeconds(1);
            }
            if (config.MaxBusyTime < TimeSpan.FromSeconds(1))
            {
                config.MaxBusyTime = TimeSpan.FromSeconds(1);
            }
            if (config.MaintenanceInterval < TimeSpan.FromSeconds(1))
            {
                config.MaintenanceInterval = TimeSpan.FromSeconds(1);
            }

            this.config = config;
            this.nodeErrorCallbackAction = errorAction;
            LocalLoggingService.Info("{0} {1} {2} {3}", DistributedServerConfiguration.ModuleName, "ClientNode", "ClientNode",
                                     string.Format("开始初始化一个新的节点:{0}", Name));
            Init();
            maintainThread = new Thread(MaintainThreadAction)
            {
                IsBackground = true,
                Name         = string.Format("{0}_{1}", "Adhesive.DistributedComponentClient_NodeMaintainThread", config.Name),
            };
            maintainThread.Start();
            IsAlive = true;
        }
        private DomainConfiguration BuildConfiguration(ClientNodeConfiguration nodeConfig, DomainUpgradeMode upgradeMode, Type modelType)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.ConnectionInfo = nodeConfig.ConnectionInfo;
            configuration.ConnectionInitializationSql = nodeConfig.InitializationSql;
            configuration.UpgradeMode   = upgradeMode;
            configuration.DefaultSchema = nodeConfig.DefaultSchema;
            configuration.Types.Register(modelType.Assembly, modelType.Namespace);
            return(configuration);
        }
        private void BuildNodeConfigurationsMetadata()
        {
            var defaultConnection = DomainConfigurationFactory.Create().ConnectionInfo;

            main = new ClientNodeConfiguration {
                Name              = "main",
                ConnectionInfo    = ComposeConnectionToMasterDatabase(defaultConnection),
                InitializationSql = "USE [DO-Tests-1]",
                DefaultSchema     = "dbo"
            };
            alpha = new ClientNodeConfiguration {
                Name              = "alpha",
                ConnectionInfo    = ComposeConnectionToMasterDatabase(defaultConnection),
                InitializationSql = "USE [DO-Tests-1]",
                DefaultSchema     = "Model1"
            };

            beta = new ClientNodeConfiguration {
                Name              = "beta",
                ConnectionInfo    = ComposeConnectionToMasterDatabase(defaultConnection),
                InitializationSql = "USE [DO-Tests-2]",
                DefaultSchema     = "Model2"
            };
        }
        private void BuildNodeConfigurationsMetadata()
        {
            var defaultConnection = DomainConfigurationFactory.Create().ConnectionInfo;

            main = new ClientNodeConfiguration {
                Name              = "main",
                ConnectionInfo    = ComposeConnectionToMasterDatabase(defaultConnection),
                InitializationSql = $"USE [{DOTests1Db}]",
                DefaultSchema     = WellKnownSchemas.SqlServerDefaultSchema
            };
            alpha = new ClientNodeConfiguration {
                Name              = "alpha",
                ConnectionInfo    = ComposeConnectionToMasterDatabase(defaultConnection),
                InitializationSql = $"USE [{DOTests1Db}]",
                DefaultSchema     = WellKnownSchemas.Schema1
            };

            beta = new ClientNodeConfiguration {
                Name              = "beta",
                ConnectionInfo    = ComposeConnectionToMasterDatabase(defaultConnection),
                InitializationSql = $"USE [{DOTests2Db}]",
                DefaultSchema     = WellKnownSchemas.Schema2
            };
        }
        private NodeConfiguration BuildNodeConfiguration(DomainConfiguration domainConfiguration, ClientNodeConfiguration nodeConfiguration, DomainUpgradeMode upgradeMode)
        {
            var node = new NodeConfiguration(nodeConfiguration.Name);

            node.ConnectionInfo = nodeConfiguration.ConnectionInfo;
            node.ConnectionInitializationSql = nodeConfiguration.InitializationSql;
            node.UpgradeMode = upgradeMode;
            if (!domainConfiguration.DefaultSchema.IsNullOrEmpty() && !nodeConfiguration.DefaultSchema.IsNullOrEmpty())
            {
                node.SchemaMapping.Add(domainConfiguration.DefaultSchema, nodeConfiguration.DefaultSchema);
            }
            return(node);
        }