void IOnBehalfAware.SetInterceptedComponentModel(ComponentModel target) { Contract.Ensures(_MetaInfo != null); Contract.Assume(target != null && target.Implementation != null); _MetaInfo = _Store.GetMetaFromType(target.Implementation); _State = InterceptorState.Initialized; }
private void SetInterceptedComponentModel(ParentServiceRequestInfo target) { Contract.Ensures(_MetaInfo != null); Contract.Assume(target.ImplementationType != null); _MetaInfo = _Store.GetMetaFromType(target.ImplementationType); _State = InterceptorState.Initialized; }
void IInterceptor.Intercept(IInvocation invocation) { Contract.Assume(_State == InterceptorState.Active || _State == InterceptorState.Initialized); Contract.Assume(invocation != null); var txManagerC = _Container.Resolve <TransactionManager>(); ITransactionManager txManager = txManagerC; var mTxMethod = _MetaInfo.Do(x => x.AsTransactional(invocation.MethodInvocationTarget ?? invocation.Method)); var mTxData = mTxMethod.Do(x => txManager.CreateTransaction(x)); _State = InterceptorState.Active; try { if (!mTxData.HasValue) { if (mTxMethod.HasValue && mTxMethod.Value.Mode == TransactionScopeOption.Suppress) { if (_Logger.IsEnabled(LogLevel.Information)) { _Logger.LogInformation("supressing ambient transaction"); } using (new TxScope(null, _AutoTxOptions.AmbientTransaction, _LoggerFactory.CreateChildLogger("TxScope", GetType()))) invocation.Proceed(); } else { invocation.Proceed(); } return; } var transaction = mTxData.Value.Transaction; Contract.Assume(transaction.State == TransactionState.Active, "from post-condition of ITransactionManager CreateTransaction in the (HasValue -> ...)-case"); if (mTxData.Value.ShouldFork) { if (_AutoTxOptions.AmbientTransaction == AmbientTransactionOption.Disabled) { throw new TransactionException("Forking is not supported if ambient transactions are disabled"); } var task = ForkCase(invocation, mTxData.Value); txManagerC.EnlistDependentTask(task); } else { SynchronizedCase(invocation, transaction); } } finally { _Container.Release(txManagerC); } }
void IInterceptor.Intercept(IInvocation invocation) { Contract.Assume(_State == InterceptorState.Active || _State == InterceptorState.Initialized); Contract.Assume(invocation != null); var txManagerC = _Kernel.Resolve <TransactionManager>(); ITransactionManager txManager = txManagerC; var mTxMethod = _MetaInfo.Do(x => x.AsTransactional(invocation.MethodInvocationTarget ?? invocation.Method)); var mTxData = mTxMethod.Do(x => txManager.CreateTransaction(x)); _State = InterceptorState.Active; try { if (!mTxData.HasValue) { if (mTxMethod.HasValue && mTxMethod.Value.Mode == TransactionScopeOption.Suppress) { _Logger.Info("supressing ambient transaction"); if (_Logger.IsInfoEnabled) { _Logger.Info("supressing ambient transaction"); } using (new TxScope(null, _Logger.CreateChildLogger("TxScope"))) invocation.Proceed(); } else { invocation.Proceed(); } return; } var transaction = mTxData.Value.Transaction; Contract.Assume(transaction.State == TransactionState.Active, "from post-condition of ITransactionManager CreateTransaction in the (HasValue -> ...)-case"); if (mTxData.Value.ShouldFork) { var task = ForkCase(invocation, mTxData.Value); txManagerC.EnlistDependentTask(task); } else if (typeof(Task).IsAssignableFrom(invocation.MethodInvocationTarget.ReturnType)) { AsyncCase(invocation, transaction); } else { SynchronizedCase(invocation, transaction); } } finally { _Kernel.ReleaseComponent(txManagerC); } }
public TransactionInterceptor(IKernel kernel, ITransactionMetaInfoStore store) { Contract.Requires(kernel != null, "kernel must be non null"); Contract.Requires(store != null, "store must be non null"); Contract.Ensures(_State == InterceptorState.Constructed); _Kernel = kernel; _Store = store; _State = InterceptorState.Constructed; }
public TransactionInterceptor(IKernel kernel, ITransactionMetaInfoStore store) { Contract.Requires(kernel != null, "kernel must be non null"); Contract.Requires(store != null, "store must be non null"); Contract.Ensures(_State == InterceptorState.Constructed); _Logger.Debug("created transaction interceptor"); _Kernel = kernel; _Store = store; _State = InterceptorState.Constructed; }
void IInterceptor.Intercept(IInvocation invocation) { Contract.Assume(_State == InterceptorState.Active || _State == InterceptorState.Initialized); Contract.Assume(invocation != null); var txManagerC = _Kernel.Resolve<TransactionManager>(); ITransactionManager txManager = txManagerC; var mTxMethod = _MetaInfo.Do(x => x.AsTransactional(invocation.Method.DeclaringType.IsInterface ? invocation.MethodInvocationTarget : invocation.Method)); var mTxData = mTxMethod.Do(x => txManager.CreateTransaction(x)); _State = InterceptorState.Active; try { if (!mTxData.HasValue) { if (mTxMethod.HasValue && mTxMethod.Value.Mode == TransactionScopeOption.Suppress) { if (_Logger.IsInfoEnabled) _Logger.Info("supressing ambient transaction"); using (new TxScope(null, _Logger.CreateChildLogger("TxScope"))) invocation.Proceed(); } else invocation.Proceed(); return; } var transaction = mTxData.Value.Transaction; Contract.Assume(transaction.State == TransactionState.Active, "from post-condition of ITransactionManager CreateTransaction in the (HasValue -> ...)-case"); if (mTxData.Value.ShouldFork) { var task = ForkCase(invocation, mTxData.Value); txManagerC.EnlistDependentTask(task); } else SynchronizedCase(invocation, transaction); } finally { _Kernel.ReleaseComponent(txManagerC); } }
public TransactionInterceptor(IContainer container, ITransactionMetaInfoStore store, ParentServiceRequestInfo parentServiceRequestInfo, AutoTxOptions autoTxOptions, ILoggerFactory loggerFactory) { Contract.Requires(container != null, "container must be non null"); Contract.Requires(store != null, "store must be non null"); Contract.Ensures(_State == InterceptorState.Constructed); _Container = container; _Store = store; _AutoTxOptions = autoTxOptions; _LoggerFactory = loggerFactory; _Logger = loggerFactory.CreateLogger(GetType()); _State = InterceptorState.Constructed; _Logger.LogDebug($"created transaction interceptor for {parentServiceRequestInfo.ImplementationType}"); SetInterceptedComponentModel(parentServiceRequestInfo); }
void IInterceptor.Intercept(IInvocation invocation) { Contract.Assume(_State == InterceptorState.Active || _State == InterceptorState.Initialized); Contract.Assume(invocation != null); var txManager = _Kernel.Resolve<ITransactionManager>(); var mTxMethod = _MetaInfo.Do(x => x.AsTransactional(invocation.Method.DeclaringType.IsInterface ? invocation.MethodInvocationTarget : invocation.Method)); var mTxData = mTxMethod.Do(x => txManager.CreateTransaction(x)); _State = InterceptorState.Active; if (!mTxData.HasValue) { if (mTxMethod.HasValue && mTxMethod.Value.Mode == TransactionScopeOption.Suppress) using (new TransactionScope(null)) invocation.Proceed(); else invocation.Proceed(); return; } var transaction = mTxData.Value.Transaction; Contract.Assume(transaction.State == TransactionState.Active, "from post-condition of ITransactionManager CreateTransaction in the (HasValue -> ...)-case"); // TODO 3.0GA: implement functionality for getting tasks and awating them #pragma warning disable 168 Task forkCase; #pragma warning restore 168 if (mTxData.Value.ShouldFork) // TODO: Handle case where child transaction aborts and task is never waited upon! ForkCase(invocation, mTxData.Value); else SynchronizedCase(invocation, transaction); }
public override void Update() { base.Update(); if (aggroed) { if (interceptorState == InterceptorState.Attack) { interceptDestination = AggroTarget.position + Vector3.up * interceptDistanceFromPlayer; MoveTowardsVector(interceptDestination); if (canFire && WithinFiringRange(AggroTarget)) { Shoot(); } if (Vector3.Distance(interceptDestination, transform.position) < 7.5f) { speedMultiplier = 1.0f; interceptorState = InterceptorState.LoopAround; } } else if (interceptorState == InterceptorState.LoopAround) { Vector3 targetDir = AggroTarget.position - transform.position; // The step size is equal to speed times frame time. float step = rotateSpeed * Time.deltaTime; Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f); // Move our position a step closer to the target. transform.rotation = Quaternion.LookRotation(newDir); transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); MoveInDirection(transform.forward, false); Vector3 targetPositionSameYPos = new Vector3(AggroTarget.position.x, transform.position.y, AggroTarget.position.z); Vector3 targetDirSameYPos = targetPositionSameYPos - transform.position; if (Vector3.Angle(transform.forward, targetDirSameYPos) < 10.0f) { speedMultiplier = 0.7f; interceptorState = InterceptorState.Attack; } } else { MoveTowardsTransform(AggroTarget); if (WithinFiringRange(AggroTarget)) { speedMultiplier = 0.7f; interceptorState = InterceptorState.Attack; } } } else { speedMultiplier = 1.0f; interceptorState = InterceptorState.Approach; MoveInDirection(transform.forward); } }