/// <summary> /// 拦截 /// </summary> /// <param name="basicReturn">基本返回</param> /// <param name="invocation">拦截参数</param> /// <param name="attr">特性</param> /// <param name="isExecProceeded">是否已执行</param> protected override void Intercept(BasicReturnInfo basicReturn, IInvocation invocation, TransactionAttribute attr, out bool isExecProceeded) { isExecProceeded = true; BasicReturnInfo returnInfo = new BasicReturnInfo(); object connId = null; if (attr.ConnectionIdIndex == -1) { connId = invocation.GetArgumentValue(attr.ConnectionIdIndex); } IGetObject <IPersistenceConnection> getPerConn = AutofacTool.Resolve(invocation.TargetType) as IGetObject <IPersistenceConnection>; if (getPerConn == null) { basicReturn.SetFailureMsg("未实现IGetObject<IPersistenceConnection>接口"); return; } IPersistenceConnection perConn = getPerConn.Get(); string connectionId = null; // 当有连接ID传过来,判断是否存在该连接事务,存在则不开启新事务 if (connId != null) { string connIdStr = connId.ToString(); if (perConn.GetDbTransaction(connIdStr) != null) { invocation.Proceed(); return; } connectionId = connIdStr; } else { connectionId = perConn.NewConnectionId(); } IDbTransaction dbTransaction = null; try { dbTransaction = perConn.BeginTransaction(connectionId, attr); invocation.SetArgumentValue(attr.ConnectionIdIndex, connectionId); invocation.Proceed(); // 如果返回值为失败标识,也回滚 Type returnType = invocation.Method.ReturnType; if (invocation.Method.ReturnType.IsReturnType()) { BasicReturnInfo basicReturnInfo = invocation.ReturnValue as BasicReturnInfo; if (basicReturnInfo.Failure()) { dbTransaction.Rollback(); return; } } dbTransaction.Commit(); } catch (Exception ex) { if (dbTransaction != null) { dbTransaction.Rollback(); } throw new Exception(ex.Message, ex); } finally { perConn.Release(connectionId); } }
public void SetFactoryProjectile(IGetObject <IProjectile> bltFctr) { m_BulletFactory = bltFctr == null ? new EmptyFactoryProjectile() : bltFctr; }