private void InitializeDatabaseConnection(string databaseName, ODatabaseType databaseType, string userName, string userPassword)
        {
            _readBuffer = new byte[OClient.BufferLenght];

            // initiate socket connection
            try
            {
                _socket = new TcpClient(Hostname, Port);
            }
            catch (SocketException ex)
            {
                throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
            }

            _networkStream = new BufferedStream(_socket.GetStream());
            _networkStream.Read(_readBuffer, 0, 2);

            OClient.ProtocolVersion = ProtocolVersion = BinarySerializer.ToShort(_readBuffer.Take(2).ToArray());

            // execute db_open operation
            DbOpen operation = new DbOpen();

            operation.DatabaseName = databaseName;
            operation.DatabaseType = databaseType;
            operation.UserName     = userName;
            operation.UserPassword = userPassword;

            Document  = ExecuteOperation(operation);
            SessionId = Document.GetField <int>("SessionId");
        }
        private NetworkStream CreateDatabaseConnection(string databaseName, ODatabaseType databaseType, string userName, string userPassword)
        {
            _readBuffer = new byte[OClient.BufferLength];

            // initiate socket connection
            TcpClient socket;

            try
            {
                socket = new TcpClient();
                socket.ReceiveTimeout = RECIVE_TIMEOUT;
                socket.ConnectAsync(Hostname, Port).GetAwaiter().GetResult();
            }
            catch (SocketException ex)
            {
                throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
            }

            NetworkStream stream;

            stream = socket.GetStream();
            stream.Read(_readBuffer, 0, 2);

            OClient.ProtocolVersion = ProtocolVersion = BinarySerializer.ToShort(_readBuffer.Take(2).ToArray());
            if (ProtocolVersion < 27)
            {
                UseTokenBasedSession = false;
            }

            // execute db_open operation
            DbOpen operation = new DbOpen(null);

            operation.DatabaseName = databaseName;
            operation.DatabaseType = databaseType;
            operation.UserName     = userName;
            operation.UserPassword = userPassword;

            Document       = ExecuteOperation(operation);
            SessionId      = Document.GetField <int>("SessionId");
            _databaseToken = Document.GetField <byte[]>("Token");

            return(stream);
        }
        private void InitializeDatabaseConnection(string databaseName, ODatabaseType databaseType, string userName, string userPassword)
        {
            _readBuffer = new byte[OClient.BufferLenght];

            // initiate socket connection
            try
            {
#if DNX451
                _socket = new TcpClient(Hostname, Port);
                _socket.ReceiveTimeout = Configuration.Timeout;
#else
                _socket = new TcpClient();
                _socket.ReceiveTimeout = Configuration.Timeout;
                _socket.ConnectAsync(Hostname, Port).RunSynchronously();
#endif
            }
            catch (SocketException ex)
            {
                throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
            }

            _networkStream = _socket.GetStream();
            _networkStream.Read(_readBuffer, 0, 2);

            OClient.ProtocolVersion = ProtocolVersion = BinarySerializer.ToShort(_readBuffer.Take(2).ToArray());
            if (ProtocolVersion < 27)
            {
                UseTokenBasedSession = false;
            }

            // execute db_open operation
            DbOpen operation = new DbOpen(null);
            operation.DatabaseName = databaseName;
            operation.DatabaseType = databaseType;
            operation.UserName     = userName;
            operation.UserPassword = userPassword;

            Document       = ExecuteOperation(operation);
            SessionId      = Document.GetField <int>("SessionId");
            _databaseToken = Document.GetField <byte[]>("Token");
        }
Exemple #4
0
        private void InitializeDatabaseConnection(string databaseName, ODatabaseType databaseType, string userName, string userPassword)
        {
            _readBuffer = new byte[OClient.BufferLength];
            if (sslConnection && clientAuth == false)
            {
#if NET451
                SslStream sslStream;
                try
                {
                    Socket = new TcpClient(Hostname, Port);
                    Socket.ReceiveTimeout = RECIVE_TIMEOUT;

                    sslStream = new SslStream(Socket.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
                    //sslStream.AuthenticateAsClient(Hostname, _sslCerts, SslProtocols.Tls12, true);
                    sslStream.AuthenticateAsClient(Hostname);
                }
                catch (Exception ex)
                {
                    throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
                }
                _networkStream = Socket.GetStream();
                _sslStream     = sslStream;
                sslStream.Read(_readBuffer, 0, 2);
#endif
            }
            else
            {
                // initiate socket connection
                try
                {
                    var client = new TcpClient();

                    Socket = new TcpClient();
                    Socket.ReceiveTimeout = RECIVE_TIMEOUT;
                    Socket.ConnectAsync(Hostname, Port).GetAwaiter().GetResult();
                }
                catch (SocketException ex)
                {
                    throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
                }

                _networkStream = Socket.GetStream();
                _networkStream.Read(_readBuffer, 0, 2);
            }

            OClient.ProtocolVersion = ProtocolVersion = BinarySerializer.ToShort(_readBuffer.Take(2).ToArray());
            if (ProtocolVersion < 27)
            {
                UseTokenBasedSession = false;
            }

            // execute db_open operation
            DbOpen operation = new DbOpen(null);
            operation.DatabaseName = databaseName;
            operation.DatabaseType = databaseType;
            operation.UserName     = userName;
            operation.UserPassword = userPassword;

            Document       = ExecuteOperation(operation);
            SessionId      = Document.GetField <int>("SessionId");
            _databaseToken = Document.GetField <byte[]>("Token");
        }