Beispiel #1
0
        private async Task <IEnumerable <BsonDocument> > GetDatabases(IMongoClient client)
        {
            var databasesList = client.ListDatabasesAsync().Result;
            var list          = await databasesList.ToListAsync();

            return(list);
        }
Beispiel #2
0
        public async static Task <bool> DatabaseExists(IMongoClient client, string database)
        {
            var cursor = await client.ListDatabasesAsync();

            var dbList = cursor.ToList().Select(db => db.GetValue("name").AsString);

            return(dbList.Contains(database));
        }
Beispiel #3
0
        public async Task <OperationResult> ExecuteAsync(CancellationToken cancellationToken)
        {
            try
            {
                using var cursor = _session == null
                    ? await _client.ListDatabasesAsync(cancellationToken)
                    : await _client.ListDatabasesAsync(_session, cancellationToken);

                var result = await cursor.ToListAsync(cancellationToken);

                return(OperationResult.FromResult(new BsonArray(result)));
            }
            catch (Exception exception)
            {
                return(OperationResult.FromException(exception));
            }
        }
Beispiel #4
0
        public static async Task <bool> DatabaseExistsAsync(this IMongoClient client, string name)
        {
            var cursor = await client.ListDatabasesAsync();

            var databases = await cursor.ToListAsync();

            return(databases.Any(x => string.Equals(x["name"].AsString, name, StringComparison.OrdinalIgnoreCase)));
        }
Beispiel #5
0
        public async Task <bool> ConnectTest()
        {
            var databases = (await mongoClient.ListDatabasesAsync()).ToList();

            foreach (var db in databases)
            {
                System.Diagnostics.Trace.WriteLine(db.AsString);
            }
            return(true);
        }
Beispiel #6
0
        private async void _populateDatabaseList()
        {
            databaseListBox.Items.Clear();
            var dbs = await _client.ListDatabasesAsync();

            await dbs.ForEachAsync(d =>
            {
                this.Invoke(new MethodInvoker(delegate() {
                    databaseListBox.Items.Add((string)d["name"]);
                }));
            });
        }
Beispiel #7
0
        public async Task <List <string> > Get()
        {
            var databases = await MongoDB.ListDatabasesAsync();

            var names = new List <string>();

            while (await databases.MoveNextAsync())
            {
                names.AddRange(databases.Current.Select(document => document.GetElement("name").Value.AsString));
            }

            return(names);
        }
Beispiel #8
0
        public Task <IAsyncCursor <BsonDocument> > ListDatabasesAsync(
            CancellationToken cancellationToken = default)
        {
            if (TryGetSession(out IClientSessionHandle? session))
            {
                return(_client.ListDatabasesAsync(session, cancellationToken));
            }

            return(_client.ListDatabasesAsync(cancellationToken));
        }
        protected virtual async Task <List <string> > GetDatabaseNamesAsync(IMongoClient client)
        {
            var ret = new List <string>();

            using (var cursor = await client.ListDatabasesAsync())
            {
                var databaseDocuments = await cursor.ToListAsync();

                foreach (var databaseDocument in databaseDocuments)
                {
                    ret.Add(databaseDocument["name"].AsString);
                }
            }

            ret.RemoveAll(t => backupOptions.ExcludedDatabases.Contains(t, StringComparison.InvariantCultureIgnoreCase));
            return(ret);
        }
Beispiel #10
0
 public Task <IAsyncCursor <BsonDocument> > ListDatabasesAsync(CancellationToken cancellationToken = default(CancellationToken))
 {
     return(wrapped.ListDatabasesAsync(cancellationToken));
 }