예제 #1
0
        internal DatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
        {
            Hostname = hostname;
            Port = port;
            DatabaseName = databaseName;
            DatabaseType = databaseType;
            UserName = userName;
            UserPassword = userPassword;
            PoolSize = poolSize;
            Alias = alias;

            _connections = new Queue<Connection>();

            for (int i = 0; i < poolSize; i++)
            {
                Connection connection = new Connection(Hostname, Port, databaseName, databaseType, userName, userPassword, alias, true);

                _connections.Enqueue(connection);
            }

            //get release from last connection
            var lastConnection = _connections.LastOrDefault();
            if (lastConnection != null)
            {
                Release = lastConnection.Document.GetField<string>("OrientdbRelease");
            }
        }
예제 #2
0
        public static void CreateDatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
        {
            lock (_syncRoot)
            {
                DatabasePool databasePool = new DatabasePool(hostname, port, databaseName, databaseType, userName, userPassword, poolSize, alias);

                _databasePools.Add(databasePool);
            }
        }
예제 #3
0
        public bool CreateDatabase(string databaseName, ODatabaseType databaseType, OStorageType storageType)
        {
            DbCreate operation = new DbCreate(null);
            operation.DatabaseName = databaseName;
            operation.DatabaseType = databaseType;
            operation.StorageType = storageType;

            ODocument document = _connection.ExecuteOperation(operation);

            return document.GetField<bool>("IsCreated");
        }
예제 #4
0
        public static string CreateDatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias, string clientID = "null")
        {
            OClient.ClientID = clientID;

            lock (_syncRoot)
            {
                DatabasePool databasePool = new DatabasePool(hostname, port, databaseName, databaseType, userName, userPassword, poolSize, alias);

                _databasePools.Add(databasePool);
                return databasePool.Release;
            }
        }
예제 #5
0
        internal Connection(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, string alias, bool isReusable)
        {
            Hostname = hostname;
            Port = port;
            Type = ConnectionType.Database;
            Alias = alias;
            IsReusable = isReusable;
            ProtocolVersion = 0;
            SessionId = -1;
            UseTokenBasedSession = OClient.UseTokenBasedSession;

            DatabaseName = databaseName;
            DatabaseType = databaseType;
            UserName = userName;
            UserPassword = userPassword;
            InitializeDatabaseConnection(databaseName, databaseType, userName, userPassword);
        }
예제 #6
0
        internal Connection(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, string alias, bool isReusable)
        {
            Hostname             = hostname;
            Port                 = port;
            Type                 = ConnectionType.Database;
            Alias                = alias;
            IsReusable           = isReusable;
            ProtocolVersion      = 0;
            SessionId            = -1;
            UseTokenBasedSession = OClient.UseTokenBasedSession;

            DatabaseName = databaseName;
            DatabaseType = databaseType;
            UserName     = userName;
            UserPassword = userPassword;
            InitializeDatabaseConnection(databaseName, databaseType, userName, userPassword);
        }
예제 #7
0
        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);
        }
예제 #8
0
        internal DatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
        {
            Hostname     = hostname;
            Port         = port;
            DatabaseName = databaseName;
            DatabaseType = databaseType;
            UserName     = userName;
            UserPassword = userPassword;
            PoolSize     = poolSize;
            Alias        = alias;

            _connections = new Queue <Connection>();

            for (int i = 0; i < poolSize; i++)
            {
                Connection connection = new Connection(Hostname, Port, databaseName, databaseType, userName, userPassword, alias, true);

                _connections.Enqueue(connection);
            }
        }
예제 #9
0
        internal DatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
        {
            Hostname = hostname;
            Port = port;
            DatabaseName = databaseName;
            DatabaseType = databaseType;
            UserName = userName;
            UserPassword = userPassword;
            PoolSize = poolSize;
            Alias = alias;

            _connections = new Queue<Connection>();

            for (int i = 0; i < poolSize; i++)
            {
                Connection connection = new Connection(Hostname, Port, databaseName, databaseType, userName, userPassword, alias, true);

                _connections.Enqueue(connection);
            }
        }
예제 #10
0
        internal Connection(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, X509Certificate2Collection sslCerts)
        {
            Hostname             = hostname;
            Port                 = port;
            Type                 = ConnectionType.Database;
            ProtocolVersion      = 0;
            SessionId            = -1;
            UseTokenBasedSession = OClient.UseTokenBasedSession;

            DatabaseName          = databaseName;
            DatabaseType          = databaseType;
            UserName              = userName;
            UserPassword          = userPassword;
            ConnectionTransaction = new OTransaction(this);
            if (Port >= 2434 && Port <= 2440)
            {
#if NET451
                if (sslCerts != null)
                {
                    sslConnection = true;
                    clientAuth    = true;
                    _sslCerts     = sslCerts;
                }
                else
                {
                    sslConnection = true;
                    clientAuth    = false;
                }
#endif
#if DOTNET5_5
                sslConnection = false;
                clientauth    = false;
#endif
            }
            else
            {
                sslConnection = false;
                clientAuth    = false;
            }
            InitializeDatabaseConnection(databaseName, databaseType, userName, userPassword);
        }
        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");
        }
예제 #12
0
        public DatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
        {
            Hostname = hostname;
            Port = port;
            DatabaseName = databaseName;
            DatabaseType = databaseType;
            UserName = userName;
            UserPassword = userPassword;
            PoolSize = poolSize;
            Alias = alias;
            Databases = new Queue<Database>();

            for (int i = 0; i < poolSize; i++)
            {
                Database database = new Database(Hostname, Port, DatabaseName, DatabaseType, UserName, UserPassword);
                database.Alias = alias;
                database.ReturnToPool = true;

                Databases.Enqueue(database);
            }
        }
예제 #13
0
        /// <summary>
        /// Creates new database on currently connected server instance.
        /// </summary>
        /// <returns>
        /// Boolean indicating if the database was created successfuly.
        /// </returns>
        public bool CreateDatabase(string databaseName, ODatabaseType databaseType, OStorageType storageType)
        {
            DbCreate operation = new DbCreate();
            operation.DatabaseName = databaseName;
            operation.DatabaseType = databaseType;
            operation.StorageType = storageType;

            return (bool)WorkerConnection.ExecuteOperation<DbCreate>(operation);
        }
예제 #14
0
        public static string CreateDatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias, string clientID = "null")
        {
            OClient.ClientID = clientID;

            lock (_syncRoot)
            {
                DatabasePool databasePool = _databasePools.FirstOrDefault(db => db.Alias == alias);
                if (databasePool == null)
                {
                    databasePool = new DatabasePool(hostname, port, databaseName, databaseType, userName, userPassword, poolSize, alias);

                    _databasePools.Add(databasePool);
                }

                return(databasePool.Release);
            }
        }
예제 #15
0
        public static void CreateDatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
        {
            lock (_syncRoot)
            {
                DatabasePool databasePool = new DatabasePool(hostname, port, databaseName, databaseType, userName, userPassword, poolSize, alias);

                _databasePools.Add(databasePool);
            }
        }
예제 #16
0
 public ODatabase(string hostName, int port, string databaseName, ODatabaseType type, string userName, string userPassword, string poolAlias)
 {
     _connectionPool = new ConnectionPool(hostName, port, databaseName, type, userName, userPassword, poolAlias);
     ClientCache     = new ConcurrentDictionary <ORID, ODocument>();
 }
예제 #17
0
        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);
                _socket.ReceiveTimeout = RECIVE_TIMEOUT;
            }
            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());
            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");
        }
예제 #18
0
 public ODatabase(string hostName, int port, string databaseName, ODatabaseType type, string userName, string userPassword, X509Certificate2Collection sslCerts)
 {
     _connectionPool = new ConnectionPool(hostName, port, databaseName, type, userName, userPassword, sslCerts);
     ClientCache     = new ConcurrentDictionary <ORID, ODocument>();
 }
예제 #19
0
 public TestConnection(bool ssl = false)
 {
     _ssl    = ssl;
     _server = new OServer(HOSTNAME, PORT, ROOT_USER_NAME, ROOT_USER_PARSSWORD, ssl);
     GlobalTestDatabaseType = ODatabaseType.Graph;
 }
예제 #20
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");
        }