コード例 #1
0
        /// <summary>
        /// Apply settings to the <see cref="IrbisConnection" />.
        /// </summary>
        public void ApplyToConnection
        (
            [NotNull] IrbisConnection connection
        )
        {
            Sure.NotNull(connection, nameof(connection));

            connection.Host        = _Select(Host, connection.Host);
            connection.Port        = _Select(Port, connection.Port);
            connection.Username    = _Select(Username, connection.Username);
            connection.Password    = _Select(Password, connection.Password);
            connection.Database    = _Select(Database, connection.Database);
            connection.Workstation = (IrbisWorkstation)_Select
                                     (
                (int)Workstation,
                (int)connection.Workstation
                                     );

            if (!string.IsNullOrEmpty(EngineTypeName))
            {
                connection.SetEngine(EngineTypeName);
            }

            if (!string.IsNullOrEmpty(SocketTypeName))
            {
                ClientSocketUtility.CreateSocket
                (
                    connection,
                    SocketTypeName
                );
            }

            if (!string.IsNullOrEmpty(NetworkLogging))
            {
                connection.SetNetworkLogging(NetworkLogging);
            }

            if (!string.IsNullOrEmpty(FactoryTypeName))
            {
                connection.SetCommandFactory(FactoryTypeName);
            }

            if (!string.IsNullOrEmpty(Smart))
            {
                SmartClientSocket smartSocket
                    = new SmartClientSocket(connection);
                connection.SetSocket(smartSocket);
            }

            if (!string.IsNullOrEmpty(Slow))
            {
                SlowSocket slowSocket = new SlowSocket
                                        (
                    connection,
                    connection.Socket
                                        );
                int delay;
                if (NumericUtility.TryParseInt32(Slow, out delay) &&
                    delay > 0)
                {
                    slowSocket.Delay = delay;
                }
                connection.SetSocket(slowSocket);
            }

            if (!string.IsNullOrEmpty(Broken))
            {
                BrokenSocket brokenSocket = new BrokenSocket
                                            (
                    connection,
                    connection.Socket
                                            );
                double probability;
                if (NumericUtility.TryParseDouble(Broken, out probability) &&
                    probability > 0.0 &&
                    probability < 1.0)
                {
                    brokenSocket.Probability = probability;
                }
                connection.SetSocket(brokenSocket);
            }

            if (RetryLimit != 0)
            {
                connection.SetRetry(RetryLimit, null);
            }

            if (!string.IsNullOrEmpty(UserData))
            {
                connection.UserData = UserData;
            }

            connection._connected = Connected;
        }