/// <summary> /// 增加错误处理错误; /// </summary> public void IncrementAsyncMessageHandleTimes(AbstractAsyncMessage msg) { DbContextExtension.ActionContext <TDbContext>(context => { context.Database.ExecuteSqlCommand(this.incrHandleSql, msg.Id); }, null, null); }
/// <summary> /// 删除此异步消息 /// </summary> public void DeleteAsyncMessage(AbstractAsyncMessage msg) { DbContextExtension.ActionContext <TDbContext>(context => { context.Database.ExecuteSqlCommand(this.deleteSql, msg.Id); }, null, null); }
/// <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); }
/// <summary> /// 转换异步消息为异步消息处理方法的参数类型; /// </summary> /// <returns></returns> private object ConvertMessageToType(AbstractAsyncMessage message) { dynamic result = JsonConvert.DeserializeObject(message.MessageContent, messageContentType); return(result.Data); }