コード例 #1
0
        /// <summary>
        /// 处理队列
        /// </summary>
        /// <param name="entity"></param>
        protected override bool Handle(QueueEntity entity)
        {
            var info = entity.Value.DeserializeJson <MobileEntity>();

            MobileRepository.Send(info);
            return(true);
        }
コード例 #2
0
ファイル: QueueConverter.cs プロジェクト: crazyants/WiseQueue
        /// <summary>
        /// Convert task <c>entity</c> into the task model.
        /// </summary>
        /// <param name="entity">The <see cref="QueueEntity"/> instance.</param>
        /// <returns>The <see cref="QueueModel"/> instance.</returns>
        public QueueModel Convert(QueueEntity entity)
        {
            QueueModel model = entity.Id > 0
                ? new QueueModel(entity.Id, entity.Name, entity.Description)
                : new QueueModel(entity.Name, entity.Description);

            return(model);
        }
コード例 #3
0
        public QueueHandle QueueDeclare(string name, bool durable, bool autoDelete, bool exclusive, IDictionary <string, object> arguments)
        {
            var id = GetNextId();

            var queue = new QueueEntity(id, name, durable, autoDelete, exclusive, arguments);

            return(Queues.GetOrAdd(queue));
        }
コード例 #4
0
        public QueueHandle CreateQueue(string name, bool durable, bool autoDelete, IDictionary <string, object> queueAttributes = null, IDictionary <string, object> queueSubscriptionAttributes = null, IDictionary <string, string> tags = null)
        {
            var id = GetNextId();

            var queueEntity = new QueueEntity(id, name, durable, autoDelete, queueAttributes, queueSubscriptionAttributes, tags);

            return(Queues.GetOrAdd(queueEntity));
        }
コード例 #5
0
        public void Post_Throws_WhenObjectDisposed()
        {
            var entity = new QueueEntity("s");

            entity.Dispose();

            Should.Throw <ObjectDisposedException>(() => entity.Post(new Amqp.Message()));
        }
コード例 #6
0
        public QueueHandle CreateQueue(string name, bool durable, bool autoDelete)
        {
            var id = GetNextId();

            var queueEntity = new QueueEntity(id, name, durable, autoDelete);

            return(Queues.GetOrAdd(queueEntity));
        }
コード例 #7
0
 public void CreateEntity(int entityId)
 {
     if (!this.Simulation.Entities.ContainsKey(entityId))
     {
         QueueEntity queueEntity = new QueueEntity(this.Simulation, entityId);
         this.Simulation.Entities.Add(entityId, queueEntity);
     }
 }
コード例 #8
0
        private void InsertJobInQueue(DbConnection conn, int jobId, string queueName)
        {
            var queue = new QueueEntity()
            {
                JobId = jobId,
                Queue = queueName,
            };

            conn.Insert(queue);
        }
コード例 #9
0
ファイル: QueueConverter.cs プロジェクト: crazyants/WiseQueue
        /// <summary>
        /// Convert task <c>model</c> into the task entity.
        /// </summary>
        /// <param name="model">The <see cref="QueueModel"/> instance.</param>
        /// <returns>The <see cref="QueueEntity"/> instance.</returns>
        public QueueEntity Convert(QueueModel model)
        {
            QueueEntity entity = new QueueEntity
            {
                Id          = model.Id,
                Name        = model.Name,
                Description = model.Description
            };

            return(entity);
        }
コード例 #10
0
        /// <summary>
        /// 处理队列
        /// </summary>
        /// <param name="entity"></param>
        protected override bool Handle(QueueEntity entity)
        {
            var json = entity.Value.DeserializeJson <Dictionary <string, string> >();

            if (json == null || !json.ContainsKey("SiteId") || !json.ContainsKey("AlbumId"))
            {
                return(true);
            }
            Create(json["SiteId"].Convert <long>(), json["AlbumId"].Convert <long>());
            return(true);
        }
コード例 #11
0
        private void InsertFetchedJobInQueue(DbConnection conn, int jobId, string queueName, string workerId)
        {
            var queue = new QueueEntity()
            {
                JobId    = jobId,
                Queue    = queueName,
                WorkerId = workerId
            };

            conn.Insert(queue);
        }
コード例 #12
0
        public QueueEntity AddEntity(string name)
        {
            var entity = new QueueEntity
            {
                Name = name
            };

            _db.Add(entity);
            _db.SaveChanges();
            return(entity);
        }
コード例 #13
0
ファイル: QueryService.cs プロジェクト: vvucetic/Pulse
        public int InsertJobToQueue(int jobId, string queue, DbConnection connection, DbTransaction transaction = null)
        {
            var insertedQueueItem = new QueueEntity()
            {
                JobId = jobId,
                Queue = queue
            };

            connection.Insert <QueueEntity>(insertedQueueItem, transaction);
            return(insertedQueueItem.Id);
        }
コード例 #14
0
        public void QueueConverterModelToEntityTest()
        {
            QueueModel model = new QueueModel(23, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            IQueueConverter converter = new QueueConverter(LoggerFactory);

            QueueEntity actual = converter.Convert(model);

            Assert.AreEqual(model.Id, actual.Id);
            Assert.AreEqual(model.Name, actual.Name);
            Assert.AreEqual(model.Description, actual.Description);
        }
コード例 #15
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="info"></param>
        public virtual string Send(EmailEntity info)
        {
            var queue = new QueueEntity();

            queue.Name     = "SendEmail";
            queue.Value    = info.SerializeJson();
            queue.SaveType = SaveType.Add;
            Creator.Get <IContext>().Set(queue, queue, queue.SaveSequence);
            var unitofworks = Creator.Get <IContext>().Save();

            return(Creator.Get <IContext>().Commit(unitofworks).ToString());
        }
コード例 #16
0
        public void Post_CreatesEndEnqueuesDelivery()
        {
            var message = new Amqp.Message();
            var entity  = new QueueEntity("s");

            IDelivery delivery = entity.Post(message);

            entity.ShouldSatisfyAllConditions(
                () => delivery.Message.ShouldBeSameAs(message),
                () => ((IEntity)entity).DeliveryQueue.Dequeue(CancellationToken.None).ShouldBeSameAs(message)
                );
        }
コード例 #17
0
        public void Dispose_CanBeCalledMultipleTimes()
        {
            var entity = new QueueEntity("s");

            entity.Post(new Amqp.Message());

            Should.NotThrow(() =>
            {
                entity.Dispose();
                entity.Dispose();
                entity.Dispose();
            });
        }
コード例 #18
0
        public async Task <bool> AddItemAsync2(QueueEntity queue)
        {
            var registration = JsonConvert.DeserializeObject <RegistrationModel>(queue.Body);

            try
            {
                await AddItemAsync(registration, queue.Url);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #19
0
        private QueueEntity CreateQueue(int level)
        {
            var id          = GetNextId();
            var queueName   = GetQueueName(level);
            var queueEntity = new QueueEntity(id, queueName, true, false, false, null);

            var lowExchangeName = level == 0 ? "workflow" : GetExchangeName(level - 1);

            queueEntity.QueueArguments.Add("x-dead-letter-exchange", lowExchangeName);

            var ttl = 1000L * (1L << level);

            queueEntity.QueueArguments.Add("x-message-ttl", ttl);

            return(queueEntity);
        }
コード例 #20
0
        public void QueueConverterEntityToModelTest()
        {
            QueueEntity entity = new QueueEntity
            {
                Id          = 23,
                Name        = Guid.NewGuid().ToString(),
                Description = Guid.NewGuid().ToString()
            };

            IQueueConverter converter = new QueueConverter(LoggerFactory);

            QueueModel actual = converter.Convert(entity);

            Assert.AreEqual(entity.Id, actual.Id);
            Assert.AreEqual(entity.Name, actual.Name);
            Assert.AreEqual(entity.Description, actual.Description);
        }
コード例 #21
0
        public override void Action()
        {
            // A: Required. The operand must be PosInteger.
            if (this.A_QueueEntityId == null)
            {
                throw new ModelingException("QUEUE: Operand A is required operand!");
            }
            int entityId = (int)this.A_QueueEntityId.GetValue();

            if (entityId <= 0)
            {
                throw new ModelingException("QUEUE: Operand A must be PosInteger!");
            }

            // B: The default is 1. The operand must be PosInteger.
            int units = this.B_NumberOfUnits == null ? 1 : (int)this.B_NumberOfUnits.GetValue();

            if (units <= 0)
            {
                throw new ModelingException("QUEUE: Operand B must be PosInteger!");
            }

            this.CreateEntity(entityId);

            Transaction transaction = this.Simulation.ActiveTransaction;

            this.EntryCount++;

            QueueEntity queue = (QueueEntity)this.Simulation.GetEntity(entityId);

            queue.Queue(units);

            Console.WriteLine("Queued  \tTime: " + this.Simulation.Clock + transaction, ConsoleColor.DarkYellow);
            Console.WriteLine("\tQueueSize: " + queue.CurrentContent);
            transaction.ChangeOwner(this);
            this.NextSequentialBlock.PassTransaction(transaction);
            this.Simulation.CurrentEventChain.AddAhead(transaction);
        }
コード例 #22
0
        public void ToString_ReturnsEntityName(string name)
        {
            var entity = new QueueEntity(name);

            entity.ToString().ShouldBe(name);
        }
コード例 #23
0
        private QueueBindingEntity CreateQueueBinding(int level, ExchangeEntity srcExchange, QueueEntity dstQueue)
        {
            var id         = GetNextId();
            var routingKey = GetRoutingKey(level, false);

            return(new QueueBindingEntity(id, srcExchange, dstQueue, routingKey, null));
        }
コード例 #24
0
        public void Constructor_InitializesInstance(string name)
        {
            var entity = new QueueEntity(name);

            entity.Name.ShouldBe(name);
        }
コード例 #25
0
        public QueueHandle CreateQueue(QueueDescription queueDescription)
        {
            var queue = new QueueEntity(GetNextId(), queueDescription);

            return(Queues.GetOrAdd(queue));
        }
コード例 #26
0
ファイル: QueryService.cs プロジェクト: vvucetic/Pulse
 public bool UpdateQueue(QueueEntity queueEntity, Expression <Func <QueueEntity, object> > fields, DbConnection connection, DbTransaction transaction = null)
 {
     return(connection.Update <QueueEntity>(queueEntity, fields, transaction));
 }
コード例 #27
0
 public IActionResult PullNewEntity([FromForm] QueueEntity entity)
 {
     return(Ok(repo.PullEntityFromQueue(entity)));
 }