Exemple #1
0
        public void UpdateItem(TaskMessage item)
        {
            Dictionary <string, object> holder = item.GetHolder();
            object id = holder["_id"];

            if (id == null || !(id is ObjectId))
            {
                throw new Exception("_id of queue element is missing");
            }

            BsonObjectId objid = new BsonObjectId((ObjectId)id);

            holder.Remove("_id");

            MongoMessage msg = new MongoMessage
            {
                ExtraElements = holder,
                id            = objid
            };

            //var result = Collection.Save(msg, new MongoInsertOptions() { WriteConcern = new WriteConcern() { Journal = true } });
            var result = Collection.Save(msg);

            if (!result.Ok)
            {
                throw new Exception("error in update to mongo queue: " + result.ToJson());
            }
        }
Exemple #2
0
        public TaskMessage GetItem()
        {
            CheckConnection();

            var cursor = Collection.Find(QueryFeature).SetSortOrder(SortFeature);

            cursor.Limit = 1;
            MongoMessage mms = cursor.FirstOrDefault();

            if (mms == null)//empty
            {
                return(null);
            }
            TaskMessage msg = new TaskMessage(mms.ExtraElements);

            msg.Holder.Add("_id", mms.id.Value);
            return(msg);
        }
Exemple #3
0
        public TaskMessage GetItemFifo()
        {
            CheckConnection();

            TaskQueue.TQItemSelector selector = TaskQueue.TQItemSelector.DefaultFifoSelector;
            var cursor = Collection.Find(MongoSelector.GetQuery(selector)).SetSortOrder();

            cursor.Limit = 1;
            MongoMessage mms = cursor.FirstOrDefault();

            if (mms == null)//empty
            {
                return(null);
            }
            TaskMessage msg = new TaskMessage(mms.ExtraElements);

            msg.Holder.Add("_id", mms.id.Value);
            return(msg);
        }
Exemple #4
0
        public void UpdateItem(TaskMessage item)
        {
            Dictionary<string, object> holder = item.GetHolder();
            object id = holder["__id"];
            if (id == null || !(id is ObjectId))
                throw new Exception("__id of queue element is missing");

            BsonObjectId objid = new BsonObjectId((ObjectId)id);
            holder.Remove("__id");

            MongoMessage msg = new MongoMessage
            {
                ExtraElements = holder,
                id = objid
            };

            //var result = Collection.Save(msg, new MongoInsertOptions() { WriteConcern = new WriteConcern() { Journal = true } });
            var result = Collection.Save(msg);
            if (!result.Ok)
                throw new Exception("error in update to mongo queue: " + result.ToJson());
        }