public void TestBindByNameWithWrappedConnection()
        {
            var wrapped = new ReliableConnection((DbConnection)_connection);

            // if the sql uses the same name twice, we need to set bindbyname to true
            var sql = @"select 
                       :p1 p1,
                        :p1 p1,
                        :p2 p2
                        from dual";

            var args = new
            {
                p1 = "one",
                p2 = "two"
            };

            var result = wrapped.QuerySql <dynamic>(sql, args);

            result = wrapped.QuerySql <dynamic>(sql, args);
        }
Beispiel #2
0
        public void MaxRetryCountCapsNumberOfRetries()
        {
            int retries = 0;

            RetryStrategy.Retrying     += (sender, re) => { retries++; };
            RetryStrategy.MaxRetryCount = 5;

            // try a bad connection
            SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(ConnectionString);

            b.InitialCatalog = "bad";
            ReliableConnection <SqlConnection> retry = new ReliableConnection <SqlConnection>(b.ConnectionString, RetryStrategy);

            try
            {
                retry.Query("SELECT 1");
            }
            catch
            {
            }

            Assert.AreEqual(5, retries);
        }
        public void TestReliableConnection()
        {
            int retries       = 0;
            var retryStrategy = new RetryStrategy();

            retryStrategy.MaxRetryCount = 1;
            retryStrategy.Retrying     += (sender, re) => { Console.WriteLine("Retrying. Attempt {0}", re.Attempt); retries++; };

            try
            {
                var builder = new OracleConnectionStringBuilder(_connectionStringBuilder.ConnectionString);
                builder.DataSource = "testserver:9999";
                using (var reliable = new ReliableConnection <OracleConnection>(builder.ConnectionString, retryStrategy))
                {
                    reliable.Open();
                }
            }
            catch
            {
            }

            Assert.AreEqual(1, retries);
        }
        public void TestReliableConnection()
        {
            int retries       = 0;
            var retryStrategy = new RetryStrategy();

            retryStrategy.MaxRetryCount = 1;
            retryStrategy.Retrying     += (sender, re) => { Console.WriteLine("Retrying. Attempt {0}", re.Attempt); retries++; };

            try
            {
                var builder = new AseConnectionStringBuilder();
                builder.ConnectionString = "Data Source=testserver;Port=9999;User ID=sa;Password=Password1";
                using (var reliable = new ReliableConnection <AseConnection>(builder.ConnectionString, retryStrategy))
                {
                    reliable.Open();
                }
            }
            catch
            {
            }

            Assert.AreEqual(1, retries);
        }
 public override object ExecuteScalar()
 {
     return(ReliableConnection.ExecuteCommand <int>(Current));
 }
 public override int ExecuteNonQuery()
 {
     return(ReliableConnection.ExecuteCommand(Current));
 }
 /// <summary>
 /// Executes the command text against the connection.
 /// </summary>
 /// <param name="behavior">An instance of <see cref="T:System.Data.CommandBehavior"></see>.</param>
 /// <returns>A task representing the operation.</returns>
 protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
 {
     return(ReliableConnection.ExecuteCommand <DbDataReader>(Current, behavior));
 }
 /// <summary>
 /// Executes the <see cref="P:System.Data.IDbCommand.CommandText"></see> against the <see cref="P:System.Data.IDbCommand.Connection"></see> and builds an <see cref="T:System.Data.IDataReader"></see>.
 /// </summary>
 /// <returns>An <see cref="T:System.Data.IDataReader"></see> object.</returns>
 public new IDataReader ExecuteReader()
 {
     return(ReliableConnection.ExecuteCommand <IDataReader>(Current));
 }
 public IDataReader ExecuteReader(CommandBehavior behavior)
 {
     return(ReliableConnection.ExecuteCommand <IDataReader>(Current, behavior));
 }
Beispiel #10
0
 protected override DbCommand CreateDbCommand()
 {
     return(new ReliableSqlCommand(ReliableConnection.CreateCommand()));
 }
Beispiel #11
0
 public override void ChangeDatabase(string databaseName)
 {
     ReliableConnection.ChangeDatabase(databaseName);
 }
Beispiel #12
0
 public override void Close()
 {
     ReliableConnection.Close();
 }
Beispiel #13
0
 public override void Open()
 {
     ReliableConnection.Open();
 }
        public void ConnectReliable()
        {
            mustConnectBy = DateTime.Now.AddMilliseconds(GameSparksRT.ComputeSleepPeriod(connectionAttempts) + GameSparksRT.HandshakeOffset);

            reliableConnection = new ReliableConnection(hostName, TcpPort, this);
        }
        private void CheckConnection()
        {
            try {
                if (DateTime.Now > mustConnectBy)
                {
                    if (ConnectState == GameSparksRT.ConnectState.Disconnected)
                    {
                        Log("IRTSession", GameSparksRT.LogLevel.INFO, "Disconnected, trying to connect");

                        ConnectState = GameSparksRT.ConnectState.Connecting;

#if !__WINDOWS__
                        if (useOnlyWebSockets)
                        {
                            ConnectWSReliable();
                        }
                        else
#endif
                        {
                            ConnectReliable();
                        }

                        connectionAttempts++;
                    }
                    else if (ConnectState == GameSparksRT.ConnectState.Connecting)
                    {
                        ConnectState = GameSparksRT.ConnectState.Disconnected;

                        Log("IRTSession", GameSparksRT.LogLevel.INFO, "Not connected in time, retrying");

#if !__WINDOWS__
                        if (useOnlyWebSockets)
                        {
                            if (reliableWSConnection != null)
                            {
                                reliableWSConnection.StopInternal();
                                reliableWSConnection = null;
                            }
                        }
                        else
#endif
                        {
                            if (reliableConnection != null)
                            {
                                reliableConnection.StopInternal();
                                reliableConnection = null;
                            }

                            if (fastConnection != null)
                            {
                                fastConnection.StopInternal();
                                fastConnection = null;
                            }
                        }
                    }
                }
#if __WINDOWS__
#else
            } catch (ThreadAbortException e) {
                Log("IRTSession", GameSparksRT.LogLevel.INFO, e.StackTrace);

                return;
#endif
            } catch (Exception e) {
                //General exception, ignore it
                System.Diagnostics.Debug.WriteLine(e);

                Log("IRTSession", GameSparksRT.LogLevel.ERROR, e.StackTrace);
            }
        }
Beispiel #16
0
    void test_join()
    {
        print("-----------------------------------------------------");
        print("test join");
        print("-----------------------------------------------------");

        ushort      ServerPort = 19120;
        const int   ClientPort = 19121;
        const int   ProtocolId = 0x11112222;
        const float DeltaTime  = 0.001f;
        const float TimeOut    = 1.0f;

        ReliableConnection client = new ReliableConnection(ProtocolId, TimeOut);
        ReliableConnection server = new ReliableConnection(ProtocolId, TimeOut);

        if (!client.Start(ClientPort))
        {
            Debug.LogError("");
        }
        ;
        if (!server.Start(ServerPort))
        {
            Debug.LogError("");
        }
        ;
        System.Net.IPEndPoint addr = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 1912);
        client.Connect(ref addr);
        server.Listen();

        while (true)
        {
            if (client.IsConnected() && server.IsConnected())
            {
                break;
            }

            if (!client.IsConnecting() && client.ConnectFailed())
            {
                break;
            }

            byte[] client_packet = { 0x00, 0x10, 0x20, 0x30 };
            client.SendPacket(client_packet, (client_packet.Length));

            byte[] server_packet = { 0x01, 0x11, 0x21, 0x31 };
            server.SendPacket(server_packet, (server_packet.Length));

            while (true)
            {
                byte[] packet     = new byte[256];
                int    bytes_read = client.ReceivePacket(ref packet, (packet.Length));
                if (bytes_read == 0)
                {
                    break;
                }
            }

            while (true)
            {
                byte[] packet     = new byte[256];
                int    bytes_read = server.ReceivePacket(ref packet, (packet.Length));
                if (bytes_read == 0)
                {
                    break;
                }
            }

            client.Update(DeltaTime);
            server.Update(DeltaTime);
        }

        if (!client.IsConnected())
        {
            Debug.LogError("client connect error");
        }
        ;
        if (!server.IsConnected())
        {
            Debug.LogError("server connect error");
        }
        ;
    }