OpenDatabaseInternalAsync() private method

Opens a database on this cluster
As of Beta2, the only supported database name is 'DB'
If is anything other than 'DB' If the token is cancelled
private OpenDatabaseInternalAsync ( string databaseName, FdbSubspace subspace, bool readOnly, bool ownsCluster, CancellationToken cancellationToken ) : Task
databaseName string Name of the database. Must be 'DB'
subspace FdbSubspace Subspace of keys that will be accessed.
readOnly bool If true, the database will only allow read operations.
ownsCluster bool If true, the database will dispose this cluster when it is disposed.
cancellationToken System.Threading.CancellationToken Cancellation Token
return Task
        internal static async Task <FdbDatabase> OpenInternalAsync(string clusterFile, string dbName, IFdbSubspace globalSpace, bool readOnly, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            dbName      = dbName ?? "DB";
            globalSpace = globalSpace ?? FdbSubspace.Empty;

            if (Logging.On)
            {
                Logging.Info(typeof(Fdb), "OpenAsync", String.Format("Connecting to database '{0}' using cluster file '{1}' and subspace '{2}' ...", dbName, clusterFile, globalSpace));
            }

            FdbCluster  cluster = null;
            FdbDatabase db      = null;
            bool        success = false;

            try
            {
                cluster = await CreateClusterInternalAsync(clusterFile, cancellationToken).ConfigureAwait(false);

                //note: since the cluster is not provided by the caller, link it with the database's Dispose()
                db = await cluster.OpenDatabaseInternalAsync(dbName, globalSpace, readOnly : readOnly, ownsCluster : true, cancellationToken : cancellationToken).ConfigureAwait(false);

                success = true;
                return(db);
            }
            finally
            {
                if (!success)
                {
                    // cleanup the cluter if something went wrong
                    if (db != null)
                    {
                        db.Dispose();
                    }
                    if (cluster != null)
                    {
                        cluster.Dispose();
                    }
                }
            }
        }
        internal static async Task <IFdbDatabase> OpenInternalAsync(FdbConnectionOptions options, CancellationToken ct)
        {
            Contract.Requires(options != null);
            ct.ThrowIfCancellationRequested();

            string       clusterFile = options.ClusterFile;
            string       dbName      = options.DbName ?? FdbConnectionOptions.DefaultDbName;  // new FdbConnectionOptions { GlobalSpace =
            bool         readOnly    = options.ReadOnly;
            IKeySubspace globalSpace = options.GlobalSpace ?? KeySubspace.Empty;

            string[] partitionPath = options.PartitionPath?.ToArray();
            bool     hasPartition  = partitionPath != null && partitionPath.Length > 0;

            if (Logging.On)
            {
                Logging.Info(typeof(Fdb), nameof(OpenInternalAsync), $"Connecting to database '{dbName}' using cluster file '{clusterFile}' and subspace '{globalSpace}' ...");
            }

            FdbCluster  cluster = null;
            FdbDatabase db      = null;
            bool        success = false;

            try
            {
                cluster = await CreateClusterInternalAsync(clusterFile, ct).ConfigureAwait(false);

                //note: since the cluster is not provided by the caller, link it with the database's Dispose()
                db = await cluster.OpenDatabaseInternalAsync(dbName, globalSpace, readOnly : !hasPartition && readOnly, ownsCluster : true, ct : ct).ConfigureAwait(false);

                // set the default options
                if (options.DefaultTimeout != TimeSpan.Zero)
                {
                    db.DefaultTimeout = checked ((int)Math.Ceiling(options.DefaultTimeout.TotalMilliseconds));
                }
                if (options.DefaultRetryLimit != 0)
                {
                    db.DefaultRetryLimit = options.DefaultRetryLimit;
                }
                if (options.DefaultMaxRetryDelay != 0)
                {
                    db.DefaultMaxRetryDelay = options.DefaultMaxRetryDelay;
                }

                if (hasPartition)
                {                 // open the partition, and switch the root of the db
                    await Fdb.Directory.SwitchToNamedPartitionAsync(db, partitionPath, readOnly, ct);
                }

                success = true;
                return(db);
            }
            finally
            {
                if (!success)
                {
                    // cleanup the cluter if something went wrong
                    db?.Dispose();
                    cluster?.Dispose();
                }
            }
        }