protected override async Task<RawBusMessage> HandleMessage(ICallHandler handler, RawBusMessage message, bool redelivered, ulong deliveryTag) { try { RawBusMessage replyMessage = await base.HandleMessage(handler, message, redelivered, deliveryTag); Model.BasicAck(deliveryTag, false); return replyMessage; } catch (RejectMessageException) { // If reject message exception is thrown -> reject message without requeue it. // Message will be lost or transfered to dead letter exchange by broker Model.BasicNack(deliveryTag, false, false); throw; } catch (Exception ex) { bool requeue = _exceptionFilter.Filter(ex, message, redelivered, deliveryTag); Model.BasicNack(deliveryTag, false, requeue); if (requeue) { return null; } throw; } }
protected override RawBusMessage HandleMessage(ICallHandler handler, RawBusMessage message, bool redelivered, ulong deliveryTag) { try { RawBusMessage replyMessage = base.HandleMessage(handler, message, redelivered, deliveryTag); Model.BasicAck(deliveryTag, false); return(replyMessage); } catch (RejectMessageException) { // If reject message exception is thrown -> reject message without requeue it. // Message will be lost or transfered to dead letter exchange by broker Model.BasicNack(deliveryTag, false, false); throw; } catch (Exception) { Model.BasicNack(deliveryTag, false, true); throw; } }
protected override RawBusMessage HandleMessage(ICallHandler handler, RawBusMessage message, bool redelivered, ulong deliveryTag) { try { RawBusMessage replyMessage = base.HandleMessage(handler, message, redelivered, deliveryTag); Model.BasicAck(deliveryTag, false); return replyMessage; } catch (RejectMessageException) { // If reject message exception is thrown -> reject message without requeue it. // Message will be lost or transfered to dead letter exchange by broker Model.BasicNack(deliveryTag, false, false); throw; } catch (Exception) { Model.BasicNack(deliveryTag, false, true); throw; } }
public void CreateAuthorizationCallHandlerFromConfiguration() { PolicyInjectionSettings settings = new PolicyInjectionSettings(); PolicyData policyData = new PolicyData("policy"); AuthorizationCallHandlerData data = new AuthorizationCallHandlerData("foo", 2); policyData.MatchingRules.Add(new CustomMatchingRuleData("matchesEverything", typeof(AlwaysMatchingRule))); policyData.Handlers.Add(data); settings.Policies.Add(policyData); using (var configSource = new FileConfigurationSource("Authorization.config", false)) { IUnityContainer container = new UnityContainer().AddNewExtension <Interception>(); settings.ConfigureContainer(container, configSource); new UnityContainerConfigurator(container) .RegisterAll( configSource, (ITypeRegistrationsProvider)configSource.GetSection(SecuritySettings.SectionName)); InjectionFriendlyRuleDrivenPolicy policy = container.Resolve <InjectionFriendlyRuleDrivenPolicy>("policy"); ICallHandler handler = (policy.GetHandlersFor(new MethodImplementationInfo(null, (MethodInfo)MethodBase.GetCurrentMethod()), container)).ElementAt(0); Assert.IsNotNull(handler); Assert.AreEqual(handler.Order, data.Order); //Assert.AreSame(authorizationProvider, ((AuthorizationCallHandler)handler).AutorizationProvider); // TODO this test only checked for provider name, so it didn't fail even though the configuration source supplied didn't have the settings required to build it } }
protected override async Task <RawBusMessage> HandleMessage(ICallHandler handler, RawBusMessage message, bool redelivered, ulong deliveryTag) { try { RawBusMessage replyMessage = await base.HandleMessage(handler, message, redelivered, deliveryTag); Model.BasicAck(deliveryTag, false); return(replyMessage); } catch (RejectMessageException) { // If reject message exception is thrown -> reject message without requeue it. // Message will be lost or transfered to dead letter exchange by broker Model.BasicNack(deliveryTag, false, false); throw; } catch (Exception ex) { bool requeue = _exceptionFilter.Filter(ex, message, redelivered, deliveryTag); Model.BasicNack(deliveryTag, false, requeue); if (requeue) { return(null); } throw; } }
public MessageSubscribtionInfo(DataContractKey contractKey, ICallHandler handler, XmlObjectSerializer serializer, bool receiveSelfPublish, IEnumerable<BusHeader> filterHeaders) { _handler = handler; _serializer = serializer; _filterInfo = new MessageFilterInfo(contractKey, receiveSelfPublish, filterHeaders); }
public static TBase Of <TBase>(ICallHandler callHandler, params Type[] interfaceTypes) where TBase : class { var builder = new Proxy(typeof(TBase), interfaceTypes); var type = builder.GetProxyType(); return((TBase)Activator.CreateInstance(type, callHandler)); }
/// <summary> /// Creates a proxy object for the given interface. /// </summary> /// <typeparam name="T">Must be an interface.</typeparam> /// <param name="callHandler"> /// ICallHandler.HandleCall will be called on any method call on the proxy object. /// </param> public T Create <T>(ICallHandler callHandler) { if (callHandler == null) { throw new ArgumentNullException(nameof(callHandler)); } var interfaceType = typeof(T); if (!interfaceType.IsInterface) { throw new NotSupportedException("DynamicProxy can only generate proxies for interfaces."); } Type proxyType; lock (s_InterfaceToProxyCache) { if (!s_InterfaceToProxyCache.TryGetValue(interfaceType, out proxyType)) { proxyType = CreateInterfaceImplementation <T>(); s_InterfaceToProxyCache.Add(interfaceType, proxyType); } } return((T)Activator.CreateInstance(proxyType, callHandler)); }
public FunctionBuildController(ActionSet actionSet, ICallHandler callHandler, IGroupDeterminer determiner) { ActionSet = actionSet; Determiner = determiner; CallHandler = callHandler; _parameters = determiner.Parameters(); }
PolicySet GetPolicySet(ICallHandler handler) { RuleDrivenPolicy magicPolicy = new RuleDrivenPolicy(); magicPolicy.RuleSet.Add(new TagAttributeMatchingRule("Magic")); magicPolicy.Handlers.Add(handler); return new PolicySet(magicPolicy); }
public void AssembledProperlyPerfCounterHandler() { PolicyInjectionSettings settings = new PolicyInjectionSettings(); PolicyData policyData = new PolicyData("policy"); PerformanceCounterCallHandlerData data = new PerformanceCounterCallHandlerData("FooCallHandler", 2); policyData.MatchingRules.Add(new CustomMatchingRuleData("match everything", typeof(AlwaysMatchingRule))); policyData.Handlers.Add(data); settings.Policies.Add(policyData); DictionaryConfigurationSource dictConfigurationSource = new DictionaryConfigurationSource(); dictConfigurationSource.Add(PolicyInjectionSettings.SectionName, settings); IUnityContainer container = new UnityContainer().AddNewExtension <Interception>(); settings.ConfigureContainer(container); RuleDrivenPolicy policy = container.Resolve <RuleDrivenPolicy>("policy"); ICallHandler handler = (policy.GetHandlersFor(GetMethodImpl(MethodBase.GetCurrentMethod()), container)).ElementAt(0); Assert.IsNotNull(handler); Assert.AreEqual(handler.Order, data.Order); }
public void RemoveIncommingCallHandler(ICallHandler callHandler) { if (this.IncommingCallHandler == callHandler) { this.IncommingCallHandler = null; } }
public void TestCallHandlerCustomFactory() { PolicyInjectionSettings settings = new PolicyInjectionSettings(); PolicyData policyData = new PolicyData("policy"); ExceptionCallHandlerData data = new ExceptionCallHandlerData("exceptionhandler", "Swallow Exceptions"); data.Order = 5; policyData.Handlers.Add(data); policyData.MatchingRules.Add(new CustomMatchingRuleData("matchesEverything", typeof(AlwaysMatchingRule))); settings.Policies.Add(policyData); ExceptionPolicyData swallowExceptions = new ExceptionPolicyData("Swallow Exceptions"); swallowExceptions.ExceptionTypes.Add(new ExceptionTypeData("Exception", typeof(Exception), PostHandlingAction.None)); DictionaryConfigurationSource dictConfigurationSource = new DictionaryConfigurationSource(); IUnityContainer container = new UnityContainer().AddNewExtension <Interception>(); settings.ConfigureContainer(container); container.RegisterInstance("Swallow Exceptions", swallowExceptions.BuildExceptionPolicy()); RuleDrivenPolicy policy = container.Resolve <RuleDrivenPolicy>("policy"); ICallHandler handler = (policy.GetHandlersFor(new MethodImplementationInfo(null, (MethodInfo)MethodBase.GetCurrentMethod()), container)).ElementAt(0); Assert.IsNotNull(handler); Assert.AreEqual(handler.Order, data.Order); }
public void PushParameters(ICallHandler callHandler) { for (int i = 0; i < _parameters.Length; i++) { _parameters[i].Push(ActionSet, callHandler.ParameterValues[i]); } }
public MessageSubscribtionInfo(DataContractKey contractKey, ICallHandler handler, XmlObjectSerializer serializer, bool receiveSelfPublish, IEnumerable <BusHeader> filterHeaders) { _handler = handler; _serializer = serializer; _filterInfo = new MessageFilterInfo(contractKey, receiveSelfPublish, filterHeaders); }
public bool Register(Type type, MessageFilterInfo filterInfo, ICallHandler handler) { return(_subscriptions.TryAdd(type, new SubscriptionInfo { FilterInfo = filterInfo, Handler = handler })); }
public bool Subscribe(Type dataType, ICallHandler handler, IEnumerable <BusHeader> filter) { DataContractKey key = dataType.GetDataContractKey(); MessageFilterInfo filterInfo = new MessageFilterInfo(key, filter ?? Enumerable.Empty <BusHeader>()); return(_registrationAction(dataType, filterInfo, handler)); }
public static object Of(ICallHandler callHandler, Type[] interfaceTypes) { if (interfaceTypes == null || interfaceTypes.Length == 0) { throw new InvalidOperationException("No interface type specified"); } return(Of <object>(callHandler, interfaceTypes)); }
private PolicySet GetPolicySet(ICallHandler handler) { RuleDrivenPolicy magicPolicy = new RuleDrivenPolicy(); magicPolicy.RuleSet.Add(new TagAttributeMatchingRule("Magic")); magicPolicy.Handlers.Add(handler); return(new PolicySet(magicPolicy)); }
public bool Register(Type type, MessageFilterInfo filterInfo, ICallHandler handler) { return _subscriptions.TryAdd(type, new SubscriptionInfo { FilterInfo = filterInfo, Handler = handler }); }
public bool Subscribe(Type dataType, ICallHandler handler, bool receiveSelfPublish, IEnumerable <BusHeader> filter) { DataContract dataContract = new DataContract(dataType); return(RegisterType(dataContract.Key, new MessageSubscribtionInfo(dataContract.Key, handler, dataContract.Serializer, receiveSelfPublish, filter ?? Enumerable.Empty <BusHeader>()))); }
public bool Subscribe(Type dataType, ICallHandler handler, bool hierarchy, bool receiveSelfPublish, IEnumerable<BusHeader> filter) { if (hierarchy) { return SubscribeHierarchy(dataType, handler, receiveSelfPublish, filter); } return Subscribe(dataType, handler, receiveSelfPublish, filter); }
public bool Subscribe(Type dataType, ICallHandler handler, bool receiveSelfPublish, IEnumerable<BusHeader> filter) { DataContract dataContract = new DataContract(dataType); return RegisterType(dataContract.Key, new MessageSubscribtionInfo(dataContract.Key, handler, dataContract.Serializer, receiveSelfPublish, filter ?? Enumerable.Empty<BusHeader>())); }
public MessageProcessor(ICallHandler callHandler, string tag) { if (callHandler == null) { throw new ArgumentNullException("callHandler"); } this.callHandler = callHandler; this.tag = tag; }
public bool Subscribe(Type dataType, ICallHandler handler, bool hierarchy, IEnumerable <BusHeader> filter) { if (hierarchy) { return(SubscribeHierarchy(dataType, handler, filter)); } return(Subscribe(dataType, handler, filter)); }
/// <summary> /// Creates a proxy object for the given interface. /// </summary> /// <typeparam name="T">Must be an interface.</typeparam> /// <param name="callHandler"> /// ICallHandler.HandleCall will be called on any method call on the proxy object. /// </param> public T Create <T>(ICallHandler callHandler) { if (callHandler == null) { throw new ArgumentNullException(nameof(callHandler)); } var interfaceType = typeof(T); return((T)Create(interfaceType, callHandler)); }
public override void Context() { _call = mock <ICall>(); _firstHandler = mock <ICallHandler>(); _firstHandler.stub(x => x.Handle(_call)).Return(RouteAction.Continue()); _secondHandler = mock <ICallHandler>(); _secondHandler.stub(x => x.Handle(_call)).Return(RouteAction.Return(_valueToReturn)); _handlers = new[] { _firstHandler, _secondHandler }; }
public void RemoveHandler(ICallHandler handler) { if (this.IncommingCallHandler == handler) { this.IncommingCallHandler = null; } if (WaitingOutgoingCall == handler) { WaitingOutgoingCall = null; } }
public void CanCreateValidationCallHandlerThroughFactory() { ValidationCallHandlerData validationCallHandler = new ValidationCallHandlerData("validationHandler"); IUnityContainer container = new UnityContainer().AddNewExtension <Interception>(); RuleDrivenPolicy policy = CreatePolicySetContainingCallHandler(validationCallHandler, container); ICallHandler runtimeHandler = (policy.GetHandlersFor(new MethodImplementationInfo(null, (MethodInfo)MethodBase.GetCurrentMethod()), container)).ElementAt(0); Assert.IsNotNull(runtimeHandler); }
public void ShouldNotBeAbleToCastToUnimplementedInterfaces() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); IDal dal = factory.Create <MockDal, IDal>(); ICallHandler ch = dal as ICallHandler; Assert.IsNull(ch); }
/// <summary> /// 侦听板卡上所有外线的呼入事件,在一个循环中进行侦听并且不断的检查是否发出了停止信号(abort) /// </summary> protected override void Listen() { while (!abort) { int n; bool chnlRing = false; string callNumber; for (int i = 0; i < driver.ChannelCount; i++) { lock (D160X.SyncObj) { n = -1; callNumber = string.Empty; switch (driver.Channels[i].ChannelType) { case ChannelType.TRUNK: // 监听外线通道的呼入事件 if (D160X.RingDetect(i)) { n = i; //callNumber = GetCallerNumber(i); if (driver.Channels[i] != null) { driver.Channels[i].Logger.Info(String.Format("Call 事件分配器探测到通道 {0} 有呼入事件发生,呼入电话号码为: ", i, callNumber)); } } break; case ChannelType.USER: // 监听内线通道的呼出事件 if (D160X.OffHookDetect(i)) { n = i; callNumber = driver.Channels[i].ChannelAlias; if (driver.Channels[i] != null) { driver.Channels[i].Logger.Info(String.Format("Call 事件分配器探测到通道 {0} 有提机事件发生,呼出通道别名为: {1}", i, driver.Channels[i].ChannelAlias)); } } break; } // 分发事件到订阅者组件,此处不检查callNumber是否为空是因为没有来电显示D160X模拟卡 // 便无法取得主叫号码。 if (n != -1 && Subject.Invocations > 0) { ICallHandler handler = Subject as ICallHandler; handler.Call(n, callNumber); } } } System.Threading.Thread.Sleep(Interval); // 使事件侦听暂停一段时间 } }
public void CreatePerfCounterHandlerFromAttributes() { MethodInfo method = typeof(MonitorTarget).GetMethod("DoSomethingElse"); object[] attributes = method.GetCustomAttributes(typeof(PerformanceCounterCallHandlerAttribute), false); Assert.AreEqual(1, attributes.Length); PerformanceCounterCallHandlerAttribute attr = attributes[0] as PerformanceCounterCallHandlerAttribute; ICallHandler handler = attr.CreateHandler(null); Assert.IsNotNull(handler); Assert.AreEqual(3, handler.Order); }
public bool SubscribeHierarchy(Type baseType, ICallHandler handler, IEnumerable <BusHeader> filter) { var types = from type in baseType.Assembly.GetTypes() where type != baseType && baseType.IsAssignableFrom(type) select type; bool atLeastOne = false; foreach (Type type in types) { atLeastOne = Subscribe(type, handler, filter) || atLeastOne; } return(atLeastOne); }
public bool SubscribeHierarchy(Type baseType, ICallHandler handler, bool receiveSelfPublish, IEnumerable<BusHeader> filter) { var types = from type in baseType.Assembly.GetTypes() where type != baseType && baseType.IsAssignableFrom(type) select type; bool atLeastOne = false; foreach (Type type in types) { atLeastOne = Subscribe(type, handler, receiveSelfPublish, filter) || atLeastOne; } return atLeastOne; }
public void CanCreateValidationCallHandlerThroughFactory() { ValidationCallHandlerData validationCallHandler = new ValidationCallHandlerData("validationHandler"); IUnityContainer container = new UnityContainer().AddNewExtension <Interception>(); new UnityContainerConfigurator(container) .RegisterAll(new DictionaryConfigurationSource(), new ValidationTypeRegistrationProvider()); InjectionFriendlyRuleDrivenPolicy policy = CreatePolicySetContainingCallHandler(validationCallHandler, container); ICallHandler runtimeHandler = (policy.GetHandlersFor(new MethodImplementationInfo(null, (MethodInfo)MethodBase.GetCurrentMethod()), container)).ElementAt(0); Assert.IsNotNull(runtimeHandler); }
/// <summary> /// mock emit code /// </summary> /// <param name="i"></param> /// <returns></returns> public virtual int MockAopTest(int i) { int result = 0; MethodContext context = new MethodContext(); context.ClassName = "AopTestClass"; context.MethodName = "MockAopTest"; context.Executor = this; context.Parameters = new object[1]; context.Parameters[0] = i; context.Processed = false; context.ReturnValue = result; ICallHandler[] handlers = new ICallHandler[1]; NameValueCollection attrCollection = new NameValueCollection(); attrCollection.Add("CacheKey", "TestKey"); attrCollection.Add("DurationMinutes", "35"); handlers[0] = new CacheCallHandler(attrCollection); for (int c = 0; c < handlers.Length; ++c) { handlers[c].BeginInvoke(context); } if (context.Processed == false) { try { result = TestMethod2(i); context.ReturnValue = result; } catch (Exception ex) { context.Exception = ex; for (int c = 0; c < handlers.Length; ++c) { handlers[c].OnException(context); } } } for (int c = 0; c < handlers.Length; ++c) { handlers[c].EndInvoke(context); } return result; }
public MockInterfaceHandler( Type type, ICallHandler callHandler ) : base( type ) { this.callHandler = callHandler; }
protected virtual Task<RawBusMessage> HandleMessage(ICallHandler handler, RawBusMessage message, bool redelivered, ulong deliveryTag) { return handler.Dispatch(message); }
public bool Subscribe(Type dataType, ICallHandler handler, IEnumerable<BusHeader> filter) { DataContractKey key = dataType.GetDataContractKey(); MessageFilterInfo filterInfo = new MessageFilterInfo(key, filter ?? Enumerable.Empty<BusHeader>()); return _registrationAction(dataType, filterInfo, handler); }
protected virtual void HandleMessage(ICallHandler handler, RawBusMessage message, bool redelivered, ulong deliveryTag) { handler.Dispatch(message); }