/// <summary>
        /// Removes the timeout if it hasn't been previously removed.
        /// </summary>
        /// <param name="timeoutId">The timeout id to remove.</param>
        /// <param name="timeoutData">The timeout data of the removed timeout.</param>
        /// <returns>
        /// <c>true</c> it the timeout was successfully removed.
        /// </returns>
        public bool TryRemove(string timeoutId, out Timeout.Core.TimeoutData timeoutData)
        {
            timeoutData = null;

            var collection = this.mongoDatabase.GetCollection <TimeoutData>(TimeoutDataName);

            var findAndRemoveArgs = new FindAndRemoveArgs {
                Query = Query <TimeoutData> .EQ(t => t.Id, timeoutId)
            };
            var result = collection.FindAndRemove(findAndRemoveArgs);

            if (!result.Ok)
            {
                throw new InvalidOperationException(
                          string.Format("Unable to remove timeout for id {0}: {1}", timeoutId, result.ErrorMessage));
            }

            var data = result.GetModifiedDocumentAs <TimeoutData>();

            if (data != null)
            {
                timeoutData = new Timeout.Core.TimeoutData()
                {
                    Id                   = data.Id,
                    Destination          = data.Destination,
                    SagaId               = data.SagaId,
                    State                = data.State,
                    Time                 = data.Time,
                    Headers              = data.Headers,
                    OwningTimeoutManager = data.OwningTimeoutManager
                };
            }

            return(data != null);
        }
示例#2
0
        public async void FindAndRemoveAsyncTest()
        {
            string entryMessage1 = "entry 1";

            AddMongoEntry(entryMessage1, MONGO_COLLECTION_1_NAME);

            List <Entry> results = new List <Entry>(_reader.Read <Entry>(MONGO_COLLECTION_1_NAME, "TimeStamp", _beforeTest, DateTime.Now));

            Assert.AreEqual(1, results.Count());
            Assert.AreEqual(entryMessage1, results[0].Message);

            var searchQuery = Query.EQ("Message", entryMessage1);

            var               update            = Update.Set("Message", MONGO_EDITED_TEXT);
            var               sortBy            = SortBy.Descending("TimeStamp");
            IMongoFields      fields            = Fields.Null;
            FindAndRemoveArgs findAndRemoveArgs = new FindAndRemoveArgs();

            findAndRemoveArgs.Query  = searchQuery;
            findAndRemoveArgs.SortBy = sortBy;

            FindAndModifyResult result = await _databaseUpdater.FindAndRemoveAsync <Entry>(MONGO_COLLECTION_1_NAME, findAndRemoveArgs);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Ok);
            Assert.IsNull(result.ErrorMessage);
            Assert.IsNotNull(result.ModifiedDocument);

            results = new List <Entry>(_reader.Read <Entry>(MONGO_COLLECTION_1_NAME, "TimeStamp", _beforeTest, DateTime.Now));
            Assert.AreEqual(0, results.Count());/*we deleted the entry via FindAndRemove...*/
        }
        public void FindAndRemoveTest2()
        {
            _AsyncDelegateUpdaterT.AsyncFindAndRemoveCompleted -= new FindAndRemoveCompletedEvent(_updaterAsync_AsyncFindAndRemoveCompleted);

            string entryMessage1 = "entry 1";

            AddMongoEntry(entryMessage1, MONGO_COLLECTION_1_NAME);

            List <Entry> results = new List <Entry>(_readerT.Read(MONGO_COLLECTION_1_NAME, "TimeStamp", _beforeTest, DateTime.Now));

            Assert.AreEqual(1, results.Count());
            Assert.AreEqual(entryMessage1, results[0].Message);

            var searchQuery = Query.EQ("Message", entryMessage1);

            var               update            = Update.Set("Message", MONGO_EDITED_TEXT);
            var               sortBy            = SortBy.Descending("TimeStamp");
            IMongoFields      fields            = Fields.Null;
            FindAndRemoveArgs findAndRemoveArgs = new FindAndRemoveArgs();

            findAndRemoveArgs.Query  = searchQuery;
            findAndRemoveArgs.SortBy = sortBy;
            _AsyncDelegateUpdaterT.FindAndRemoveAsync(MONGO_COLLECTION_1_NAME, findAndRemoveArgs);
            Thread.Sleep(2000); // wait 2 seconds to show that event handler will not pick up callback

            Assert.IsNull(_writeConcernResult);

            results = new List <Entry>(_readerT.Read(MONGO_COLLECTION_1_NAME, "TimeStamp", _beforeTest, DateTime.Now));
            Assert.AreEqual(0, results.Count());/*we deleted the entry via FindAndRemove...*/
        }
示例#4
0
        public void FindAndRemoveTest1()
        {
            string entryMessage1 = "entry 1";

            AddMongoEntry(entryMessage1, MONGO_COLLECTION_1_NAME);

            List <Entry> results = new List <Entry>(_readerT.Read(MONGO_COLLECTION_1_NAME, "TimeStamp", _beforeTest, DateTime.Now));

            Assert.AreEqual(1, results.Count());
            Assert.AreEqual(entryMessage1, results[0].Message);

            var searchQuery = Query.EQ("Message", entryMessage1);

            var               update            = Update.Set("Message", MONGO_EDITED_TEXT);
            var               sortBy            = SortBy.Descending("TimeStamp");
            IMongoFields      fields            = Fields.Null;
            FindAndRemoveArgs findAndRemoveArgs = new FindAndRemoveArgs();

            findAndRemoveArgs.Query  = searchQuery;
            findAndRemoveArgs.SortBy = sortBy;
            _AsyncDelegateUpdaterT.FindAndRemoveAsync(MONGO_COLLECTION_1_NAME, findAndRemoveArgs);
            _updaterAutoResetEvent.WaitOne();

            Assert.IsTrue(_findAndModifyResult.Ok, "FindAndModifyResult from FindAndModify not OK");
            Assert.IsNull(_findAndModifyResult.ErrorMessage);
            Assert.IsNotNull(_findAndModifyResult.ModifiedDocument);

            results = new List <Entry>(_readerT.Read(MONGO_COLLECTION_1_NAME, "TimeStamp", _beforeTest, DateTime.Now));
            Assert.AreEqual(0, results.Count());/*we deleted the entry via FindAndRemove...*/
        }
示例#5
0
        public object FindAndRemoveAs(Type documentType, IMongoQuery query, IMongoSortBy sortBy)
        {
            var args = new FindAndRemoveArgs();

            args.Query  = query;
            args.SortBy = sortBy;
            return(_this.FindAndRemove(args).GetModifiedDocumentAs(documentType));
        }
        public void RemoveDispatchedTimeout(Guid id)
        {
            MongoCollection <TimeoutData> collection = _mongoDatabase.GetCollection <TimeoutData>(TimeoutsCollectionName);

            var args = new FindAndRemoveArgs
            {
                Query = Query.And(Query.EQ("Locked", true), Query.EQ("_id", id))
            };

            collection.FindAndRemove(args);
        }
示例#7
0
 /// <summary>
 /// [MongoDB] 通用根据查询条件删除首个匹配的文档对象
 /// </summary>
 /// <typeparam name="TDocument">泛型类型</typeparam>
 /// <param name="queryList">查询实体集合</param>
 /// <param name="sortBy">排序实体 创建示例:SortBy.Descending("Title") OR SortBy.Descending("Title").Ascending("Author")</param>
 /// <returns></returns>
 public static bool FindAndRemove <TDocument>(IList <IMongoQuery> queryList, IMongoSortBy sortBy)
 {
     try
     {
         var findAndRemoveArgs = new FindAndRemoveArgs {
             Query = GetIMongoQueryBy(queryList), SortBy = sortBy
         };
         var result = GetCollection <TDocument>(typeof(TDocument).Name).FindAndRemove(findAndRemoveArgs);
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
示例#8
0
        public override FindAndModifyResult FindAndRemove(FindAndRemoveArgs args)
        {
            var sw = new Stopwatch();

            sw.Start();
            var result = base.FindAndRemove(args);

            sw.Stop();

            var commandStringBuilder = new StringBuilder(1024);

            commandStringBuilder.AppendFormat("db.{0}.findAndModify(query, sort, remove, fields)", Name);

            if (args.Query != null)
            {
                commandStringBuilder.AppendFormat("\nquery = {0}", args.Query.ToBsonDocument());
            }
            else
            {
                commandStringBuilder.Append("\nquery = null");
            }

            if (args.SortBy != null)
            {
                commandStringBuilder.AppendFormat("\nsort = {0}", args.SortBy.ToBsonDocument());
            }
            else
            {
                commandStringBuilder.Append("\nsort = null");
            }

            commandStringBuilder.AppendFormat("\nremove = true");

            if (args.Fields != null)
            {
                commandStringBuilder.AppendFormat("\nfields = {0}", args.Fields.ToBsonDocument());
            }
            else
            {
                commandStringBuilder.Append("\nfields = null");
            }

            string commandString = commandStringBuilder.ToString();

            ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Update);

            return(result);
        }
        /// <summary>
        /// Removes the timeout if it hasn't been previously removed.
        /// </summary>
        /// <param name="timeoutId">The timeout id to remove.</param>
        /// <param name="timeoutData">The timeout data of the removed timeout.</param>
        /// <returns>
        /// <c>true</c> it the timeout was successfully removed.
        /// </returns>
        public bool TryRemove(string timeoutId, out Timeout.Core.TimeoutData timeoutData)
        {
            timeoutData = null;

            var collection = this.mongoDatabase.GetCollection<TimeoutData>(TimeoutDataName);

            var findAndRemoveArgs = new FindAndRemoveArgs { Query = Query<TimeoutData>.EQ(t => t.Id, timeoutId) };
            var result = collection.FindAndRemove(findAndRemoveArgs);

            if (!result.Ok)
            {
                throw new InvalidOperationException(
                    string.Format("Unable to remove timeout for id {0}: {1}", timeoutId, result.ErrorMessage));
            }

            var data = result.GetModifiedDocumentAs<TimeoutData>();

            if (data != null)
            {
                timeoutData = new Timeout.Core.TimeoutData()
                                  {
                                      Id = data.Id,
                                      Destination = data.Destination,
                                      SagaId = data.SagaId,
                                      State = data.State,
                                      Time = data.Time,
                                      Headers = data.Headers,
                                      OwningTimeoutManager = data.OwningTimeoutManager
                                  };
            }

            return data != null;
        }
 public void FindAndRemoveAsync <T>(string collectionName, FindAndRemoveArgs findAndRemoveArgs)
 {
     new Func <string, FindAndRemoveArgs, FindAndModifyResult>(_updater.FindAndRemove <T>).BeginInvoke(collectionName, findAndRemoveArgs, CallbackFindAndModify, null);
 }
示例#11
0
 public Task <FindAndModifyResult> FindAndRemoveAsync <T>(string collectionName, FindAndRemoveArgs findAndRemoveArgs)
 {
     return(_asyncUpdater.FindAndRemoveAsync <T>(collectionName, findAndRemoveArgs));
 }
示例#12
0
 public Task <FindAndModifyResult> FindAndRemoveAsync <T>(string collectionName, FindAndRemoveArgs findAndRemoveArgs)
 {
     return(Task.Run(() => { return _updater.FindAndRemove <T>(collectionName, findAndRemoveArgs); }));
 }
示例#13
0
        public virtual Tuple <TResult, int> FindAndRemove <TResult>(FindAndRemoveArgs args)
        {
            var result = this.context.GetCollection <TEntity>().FindAndRemove(args);

            return(Tuple.Create(result.GetModifiedDocumentAs <TResult>(), result.ModifiedDocument.ElementCount));
        }
示例#14
0
 public Task <FindAndModifyResult> FindAndRemoveAsync <T>(FindAndRemoveArgs findAndRemoveArgs)
 {
     return(_databaseUpdater.FindAndRemoveAsync <T>(_collectionName, findAndRemoveArgs));
 }
示例#15
0
 public FindAndModifyResult FindAndRemove <T>(FindAndRemoveArgs findAndRemoveArgs)
 {
     return(_databaseUpdater.FindAndRemove <T>(_collectionName, findAndRemoveArgs));
 }
示例#16
0
        public FindAndModifyResult FindAndRemove <T>(string collectionName, FindAndRemoveArgs findAndRemoveArgs)
        {
            var collection = GetCollection <T>(collectionName);

            return(collection.FindAndRemove(findAndRemoveArgs));
        }
示例#17
0
 public FindAndModifyResult FindAndRemove <T>(string collectionName, FindAndRemoveArgs findAndRemoveArgs)
 {
     return(_updater.FindAndRemove <T>(collectionName, findAndRemoveArgs));
 }