예제 #1
0
        private IrbisConnection GetConnection()
        {
            string connectionString
                = CM.AppSettings["connectionString"];

            IrbisConnection result
                = new IrbisConnection(connectionString);

            if (_slowBox.CheckBox.Checked)
            {
                SlowSocket slow = new SlowSocket
                                  (
                    result,
                    result.Socket
                                  )
                {
                    Delay = 1000
                };
                result.SetSocket(slow);
            }

            if (_brokenBox.CheckBox.Checked)
            {
                BrokenSocket broken = new BrokenSocket
                                      (
                    result,
                    result.Socket
                                      )
                {
                    Probability = 0.5
                };
                result.SetSocket(broken);
            }

            if (_busyBox.CheckBox.Checked)
            {
                _busyStripe.SubscribeTo(result);
            }

            if (_retryBox.CheckBox.Checked)
            {
                RetryManager manager =
                    result.SetupRetryForm();
                manager.ExceptionOccurs += ExceptionOccurs;
                manager.Resolved        += ExceptionResolved;
                result.Disposing        += ConnectionDisposing;
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Remove given socket from the socket chain.
        /// </summary>
        public static void RemoveSocket
        (
            [NotNull] IrbisConnection connection,
            [NotNull] AbstractClientSocket socket
        )
        {
            Sure.NotNull(connection, nameof(connection));
            Sure.NotNull(socket, nameof(socket));

            AbstractClientSocket inner = socket.InnerSocket;

            if (ReferenceEquals(connection.Socket, socket))
            {
                inner = inner.ThrowIfNull("socket.InnerSocket");
                connection.SetSocket(inner);
            }
            else
            {
                for (
                    AbstractClientSocket current = connection.Socket;
                    !ReferenceEquals(current, null);
                    )
                {
                    inner = current.InnerSocket;

                    if (ReferenceEquals(inner, socket))
                    {
                        current.InnerSocket = inner.InnerSocket;
                        break;
                    }

                    current = inner;
                }
            }
        }
예제 #3
0
        private IrbisConnection GetConnection()
        {
            IrbisConnection result
                = IrbisConnectionUtility.GetClientFromConfig();

            SlowSocket socket = new SlowSocket(result, result.Socket)
            {
                Delay = 1000
            };

            result.SetSocket(socket);

            result.Busy.StateChanged += Busy_StateChanged;
            result.Disposing         += Connection_Disposing;

            return(result);
        }
예제 #4
0
        public static T CreateSocket <T>
        (
            [NotNull] IrbisConnection connection
        )
            where T : AbstractClientSocket
        {
            Sure.NotNull(connection, nameof(connection));

            Type type   = typeof(T);
            T    result = (T)Activator.CreateInstance
                          (
                type,
                connection
                          );

            connection.SetSocket(result);

            return(result);
        }
예제 #5
0
        public static AbstractClientSocket CreateSocket
        (
            [NotNull] IrbisConnection connection,
            [NotNull] string typeName
        )
        {
            Sure.NotNull(connection, nameof(connection));
            Sure.NotNullNorEmpty(typeName, nameof(typeName));

            Type type = Type.GetType(typeName, true).ThrowIfNull("Type.GetType");
            AbstractClientSocket result = (AbstractClientSocket)Activator.CreateInstance
                                          (
                type,
                connection
                                          );

            connection.SetSocket(result);

            return(result);
        }
예제 #6
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;
        }