Exemple #1
0
 /// <summary>
 /// 增加错误处理错误;
 /// </summary>
 public void IncrementAsyncMessageHandleTimes(AbstractAsyncMessage msg)
 {
     DbContextExtension.ActionContext <TDbContext>(context =>
     {
         context.Database.ExecuteSqlCommand(this.incrHandleSql, msg.Id);
     }, null, null);
 }
Exemple #2
0
 /// <summary>
 /// 删除此异步消息
 /// </summary>
 public void DeleteAsyncMessage(AbstractAsyncMessage msg)
 {
     DbContextExtension.ActionContext <TDbContext>(context =>
     {
         context.Database.ExecuteSqlCommand(this.deleteSql, msg.Id);
     }, null, null);
 }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        public bool Handle(AbstractAsyncMessage message)
        {
            var parameter = ConvertMessageToType(message);

            /* if (this.isThreadSafe) //启动任务执行,不过谨慎使用,因为可能会一下子运行1000多个任务;
             * {
             *   //启动线程执行;
             *   Task.Factory.StartNew(() =>
             *   {
             *       var constructor = MessageHandleMethod.Type.GetConstructor(Type.EmptyTypes); //获取空构造函数
             *       var instance = constructor.Invoke(null);
             *       MessageHandleMethod.Method.Invoke(instance, parameter);
             *   });
             * }
             * else */
            var result = this.MessageHandleMethod.Invoke(new object[] { parameter });

            if (result == null)
            {
                return(false);
            }
            return((bool)result);
        }
Exemple #4
0
        /// <summary>
        /// 转换异步消息为异步消息处理方法的参数类型;
        /// </summary>
        /// <returns></returns>
        private object ConvertMessageToType(AbstractAsyncMessage message)
        {
            dynamic result = JsonConvert.DeserializeObject(message.MessageContent, messageContentType);

            return(result.Data);
        }