예제 #1
0
        /// <remarks>Throws <see cref="ProtocolException"/> if the discovery result is invalid.</remarks>
        /// <remarks>Throws <see cref="ServiceUnavailableException"/> if the no discovery procedure could be found in the server.</remarks>
        public async Task <IRoutingTable> DiscoverAsync(IConnection connection, string database, Bookmark bookmark)
        {
            RoutingTable table;

            var provider          = new SingleConnectionBasedConnectionProvider(connection);
            var multiDb           = connection.SupportsMultidatabase();
            var sessionAccessMode = multiDb ? AccessMode.Read : AccessMode.Write;
            var sessionDb         = multiDb ? "system" : null;
            var session           = new AsyncSession(provider, _logger, null, sessionAccessMode, sessionDb, bookmark);

            try
            {
                var stmt   = DiscoveryProcedure(connection, database);
                var result = await session.RunAsync(stmt).ConfigureAwait(false);

                var record = await result.SingleAsync().ConfigureAwait(false);

                table = ParseDiscoveryResult(database, record);
            }
            finally
            {
                try
                {
                    await session.CloseAsync().ConfigureAwait(false);
                }
                catch (Exception)
                {
                    // ignore any exception
                }

                await provider.CloseAsync().ConfigureAwait(false);
            }

            return(table);
        }
예제 #2
0
        /// <remarks>Throws <see cref="ProtocolException"/> if the discovery result is invalid.</remarks>
        /// <remarks>Throws <see cref="ServiceUnavailableException"/> if the no discovery procedure could be found in the server.</remarks>
        public async Task <IRoutingTable> DiscoverAsync(IConnection connection)
        {
            var table = default(RoutingTable);

            var provider = new SingleConnectionBasedConnectionProvider(connection);
            var session  = new AsyncSession(provider, _logger);

            try
            {
                var result = await session.RunAsync(DiscoveryProcedure(connection)).ConfigureAwait(false);

                var record = await result.SingleAsync().ConfigureAwait(false);

                table = ParseDiscoveryResult(record);
            }
            finally
            {
                try
                {
                    await session.CloseAsync().ConfigureAwait(false);
                }
                catch (Exception)
                {
                    // ignore any exception
                }

                await provider.CloseAsync().ConfigureAwait(false);
            }

            return(table);
        }