Exemplo n.º 1
0
        /// <summary>
        /// Delete all documents based on predicate expression. Returns how many documents was deleted
        /// </summary>
        public Task <int> DeleteManyAsync(string predicate, params BsonValue[] args)
        {
            var tcs = new TaskCompletionSource <int>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.DeleteMany(predicate, args));
            });
            return(tcs.Task);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Insert or Update a document in this collection.
        /// </summary>
        public Task <bool> UpsertAsync(BsonValue id, T entity)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Upsert(id, entity));
            });
            return(tcs.Task);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Delete a single document on collection based on _id index. Returns true if document was deleted
        /// </summary>
        public Task <bool> DeleteAsync(BsonValue id)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Delete(id));
            });
            return(tcs.Task);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Find a document using Document Id. Returns null if not found.
        /// </summary>
        public Task <T> FindByIdAsync(BsonValue id)
        {
            var tcs = new TaskCompletionSource <T>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.FindById(id));
            });
            return(tcs.Task);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Find the first document using predicate expression. Returns null if not found
        /// </summary>
        public Task <T> FindOneAsync(BsonExpression predicate, params BsonValue[] args)
        {
            var tcs = new TaskCompletionSource <T>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.FindOne(predicate, args));
            });
            return(tcs.Task);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Find documents inside a collection using query definition.
        /// </summary>
        public Task <IEnumerable <T> > FindAsync(Query query, int skip = 0, int limit = int.MaxValue)
        {
            var tcs = new TaskCompletionSource <IEnumerable <T> >();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Find(query, skip, limit));
            });
            return(tcs.Task);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find documents inside a collection using predicate expression.
        /// </summary>
        public Task <IEnumerable <T> > FindAsync(Expression <Func <T, bool> > predicate, int skip = 0, int limit = int.MaxValue)
        {
            var tcs = new TaskCompletionSource <IEnumerable <T> >();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Find(predicate, skip, limit));
            });
            return(tcs.Task);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns all documents inside collection order by _id index.
        /// </summary>
        public Task <IEnumerable <T> > FindAllAsync()
        {
            var tcs = new TaskCompletionSource <IEnumerable <T> >();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.FindAll());
            });
            return(tcs.Task);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Find the first document using defined query structure. Returns null if not found
        /// </summary>
        public Task <T> FindOneAsync(Query query)
        {
            var tcs = new TaskCompletionSource <T>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.FindOne(query));
            });
            return(tcs.Task);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Update many document based on merge current document with extend expression. Use your class with initializers.
        /// Eg: col.UpdateMany(x => new Customer { Name = x.Name.ToUpper(), Salary: 100 }, x => x.Name == "John")
        /// </summary>
        public Task <int> UpdateManyAsync(Expression <Func <T, T> > extend, Expression <Func <T, bool> > predicate)
        {
            var tcs = new TaskCompletionSource <int>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.UpdateMany(extend, predicate));
            });
            return(tcs.Task);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Delete all documents inside collection. Returns how many documents was deleted. Run inside current transaction
        /// </summary>
        public Task <int> DeleteAllAsync()
        {
            var tcs = new TaskCompletionSource <int>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.DeleteAll());
            });
            return(tcs.Task);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get document count in collection using predicate filter expression
        /// </summary>
        public Task <int> CountAsync(BsonExpression predicate)
        {
            var tcs = new TaskCompletionSource <int>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Count(predicate));
            });
            return(tcs.Task);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Update a document in this collection. Returns false if not found document in collection
        /// </summary>
        public Task <bool> UpdateAsync(T entity)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Update(entity));
            });
            return(tcs.Task);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Get true if collection contains at least 1 document that satisfies the predicate expression
        /// </summary>
        public Task <bool> ExistsAsync(Expression <Func <T, bool> > predicate)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Exists(predicate));
            });
            return(tcs.Task);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Get true if collection contains at least 1 document that satisfies the predicate expression
        /// </summary>
        public Task <bool> ExistsAsync(Query query)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Exists(query));
            });
            return(tcs.Task);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Get document count in collection using predicate filter expression
        /// </summary>
        public Task <long> LongCountAsync(Query query)
        {
            var tcs = new TaskCompletionSource <long>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.LongCount(query));
            });
            return(tcs.Task);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Get true if collection contains at least 1 document that satisfies the predicate expression
        /// </summary>
        public Task <bool> ExistsAsync(string predicate, params BsonValue[] args)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Exists(predicate, args));
            });
            return(tcs.Task);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Drop index and release slot for another index
        /// </summary>
        public Task <bool> DropIndexAsync(string name)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.DropIndex(name));
            });
            return(tcs.Task);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Get document count in collection using predicate filter expression
        /// </summary>
        public Task <long> LongCountAsync(string predicate, BsonDocument parameters)
        {
            var tcs = new TaskCompletionSource <long>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.LongCount(predicate, parameters));
            });
            return(tcs.Task);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create a new permanent index in all documents inside this collections if index not exists already. Returns true if index was created or false if already exits
        /// </summary>
        /// <param name="expression">Document field/expression</param>
        /// <param name="unique">If is a unique index</param>
        public Task <bool> EnsureIndexAsync(BsonExpression expression, bool unique = false)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.EnsureIndex(expression, unique));
            });
            return(tcs.Task);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Insert a new entity to this collection. Document Id must be a new value in collection - Returns document Id
        /// </summary>
        public Task <BsonValue> InsertAsync(T entity)
        {
            var tcs = new TaskCompletionSource <BsonValue>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Insert(entity));
            });
            return(tcs.Task);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Insert an array of new documents to this collection. Document Id must be a new value in collection. Can be set buffer size to commit at each N documents
        /// </summary>
        public Task <int> InsertAsync(IEnumerable <T> entities)
        {
            var tcs = new TaskCompletionSource <int>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Insert(entities));
            });
            return(tcs.Task);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Returns the last/max field using a linq expression
        /// </summary>
        public Task <K> MaxAsync <K>(Expression <Func <T, K> > keySelector)
        {
            var tcs = new TaskCompletionSource <K>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Max(keySelector));
            });
            return(tcs.Task);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Returns the max value from specified key value in collection
        /// </summary>
        public Task <BsonValue> MaxAsync(BsonExpression keySelector)
        {
            var tcs = new TaskCompletionSource <BsonValue>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Max(keySelector));
            });
            return(tcs.Task);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Update many documents based on transform expression. This expression must return a new document that will be replaced over current document (according with predicate).
        /// Eg: col.UpdateMany("{ Name: UPPER($.Name), Age }", "_id > 0")
        /// </summary>
        public Task <int> UpdateManyAsync(BsonExpression transform, BsonExpression predicate)
        {
            var tcs = new TaskCompletionSource <int>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.UpdateMany(transform, predicate));
            });
            return(tcs.Task);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Returns the min value of _id index
        /// </summary>
        public Task <BsonValue> MinAsync()
        {
            var tcs = new TaskCompletionSource <BsonValue>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.Min());
            });
            return(tcs.Task);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Create a new permanent index in all documents inside this collections if index not exists already.
        /// </summary>
        /// <param name="name">Index name - unique name for this collection</param>
        /// <param name="keySelector">LinqExpression to be converted into BsonExpression to be indexed</param>
        /// <param name="unique">Create a unique keys index?</param>
        public Task <bool> EnsureIndexAsync <K>(string name, Expression <Func <T, K> > keySelector, bool unique = false)
        {
            var tcs = new TaskCompletionSource <bool>();

            Database.Enqueue(tcs, () => {
                tcs.SetResult(UnderlyingCollection.EnsureIndex <K>(name, keySelector, unique));
            });
            return(tcs.Task);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Inserts a specified item into this dispatching list.
 /// </summary>
 /// <param name="index">
 /// The index at which to insert the item.
 /// </param>
 /// <param name="item">
 /// The item to insert.
 /// </param>
 public void Insert(int index, TItem item)
 {
     if (!Dispatcher.CheckAccess())
     {
         Dispatcher.Invoke(DispatcherPriority.Send, new InsertHandler(Insert), index, item);
     }
     else
     {
         UnderlyingCollection.Insert(index, item);
     }
 }
Exemplo n.º 29
0
 void generateData()
 {
     for (int i = 0; i < 250; i++)
     {
         var person = new Person()
         {
             Name = "Tile" + i
         };
         UnderlyingCollection.Add(person);
     }
 }
Exemplo n.º 30
0
 /// <summary>
 /// Removes an item from a specified index.
 /// </summary>
 /// <param name="index">
 /// The index of the item to remove.
 /// </param>
 public void RemoveAt(int index)
 {
     if (!Dispatcher.CheckAccess())
     {
         Dispatcher.Invoke(DispatcherPriority.Send, new RemoveAtHandler(RemoveAt), index);
     }
     else
     {
         UnderlyingCollection.RemoveAt(index);
     }
 }