protected override void PrepareOperationLog(AMSOperationContext context) { UserOperationLog log = new UserOperationLog(); log.Subject = this.GetOperationDescription(); log.ResourceID = this.EventID.ToString(); log.FillHttpContext(); context.Logs.Add(log); }
protected override object DoOperation(AMSOperationContext context) { try { return AMSEventSqlAdapter.Instance.AddChannel(this.EventID, this.ChannelIDs); } catch (System.Data.SqlClient.SqlException ex) { if (ex.Number == 2627) throw new SystemSupportException(string.Format("在事件{0}中不能增加重复的频道", this.EventID)); else throw; } }
protected override object DoOperation(AMSOperationContext context) { return AMSEventSqlAdapter.Instance.DeleteChannels(this.EventID, this.ChannelIDs); }
/// <summary> /// 准备数据,包括校验数据。这个操作在事务之外 /// </summary> /// <param name="context"></param> protected virtual void PrepareData(AMSOperationContext context) { }
/// <summary> /// 执行在事务内具体的数据操作,需要重载 /// </summary> /// <param name="context"></param> /// <returns></returns> protected abstract object DoOperation(AMSOperationContext context);
private void PersistOperationLog(AMSOperationContext context) { using (TransactionScope scope = TransactionScopeFactory.Create()) { context.Logs.ForEach(log => UserOperationLogSqlAdapter.Instance.Add(log)); scope.Complete(); } }
private object InternalExecute() { AMSOperationContext context = new AMSOperationContext(this.OperationType, this); ExecutionWrapper("PrepareData", () => PrepareData(context)); ExecutionWrapper("PrepareOperationLog", () => PrepareOperationLog(context)); object result = null; if (this.AutoStartTransaction) { using (TransactionScope scope = TransactionScopeFactory.Create()) { ExecutionWrapper("DoOperation", () => result = DoOperation(context)); ExecutionWrapper("PersistOperationLog", () => PersistOperationLog(context)); scope.Complete(); } } else { ExecutionWrapper("DoOperation", () => result = DoOperation(context)); ExecutionWrapper("PersistOperationLog", () => PersistOperationLog(context)); } return result; }
/// <summary> /// 准备操作日志 /// </summary> /// <param name="context"></param> protected virtual void PrepareOperationLog(AMSOperationContext context) { }