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

            MobileRepository.Send(info);
            return(true);
        }
Example #2
0
        /// <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);
        }
        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));
        }
        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));
        }
Example #5
0
        public void Post_Throws_WhenObjectDisposed()
        {
            var entity = new QueueEntity("s");

            entity.Dispose();

            Should.Throw <ObjectDisposedException>(() => entity.Post(new Amqp.Message()));
        }
Example #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));
        }
Example #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);
     }
 }
Example #8
0
        private void InsertJobInQueue(DbConnection conn, int jobId, string queueName)
        {
            var queue = new QueueEntity()
            {
                JobId = jobId,
                Queue = queueName,
            };

            conn.Insert(queue);
        }
Example #9
0
        /// <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);
        }
Example #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);
        }
Example #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);
        }
        public QueueEntity AddEntity(string name)
        {
            var entity = new QueueEntity
            {
                Name = name
            };

            _db.Add(entity);
            _db.SaveChanges();
            return(entity);
        }
Example #13
0
        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);
        }
Example #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);
        }
Example #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());
        }
Example #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)
                );
        }
Example #17
0
        public void Dispose_CanBeCalledMultipleTimes()
        {
            var entity = new QueueEntity("s");

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

            Should.NotThrow(() =>
            {
                entity.Dispose();
                entity.Dispose();
                entity.Dispose();
            });
        }
Example #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);
            }
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #22
0
        public void ToString_ReturnsEntityName(string name)
        {
            var entity = new QueueEntity(name);

            entity.ToString().ShouldBe(name);
        }
Example #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));
        }
Example #24
0
        public void Constructor_InitializesInstance(string name)
        {
            var entity = new QueueEntity(name);

            entity.Name.ShouldBe(name);
        }
        public QueueHandle CreateQueue(QueueDescription queueDescription)
        {
            var queue = new QueueEntity(GetNextId(), queueDescription);

            return(Queues.GetOrAdd(queue));
        }
Example #26
0
 public bool UpdateQueue(QueueEntity queueEntity, Expression <Func <QueueEntity, object> > fields, DbConnection connection, DbTransaction transaction = null)
 {
     return(connection.Update <QueueEntity>(queueEntity, fields, transaction));
 }
Example #27
0
 public IActionResult PullNewEntity([FromForm] QueueEntity entity)
 {
     return(Ok(repo.PullEntityFromQueue(entity)));
 }