public EventCommandHandler GetEventCommandHandler() { Mocker = new AutoMocker(); EventCommandHandler = Mocker.CreateInstance <EventCommandHandler>(); return(EventCommandHandler); }
public DCN500Client(string ip, int port) { try { if (OnSendData == null) { OnSendData += new EventCommandHandler(DCN500Client_OnSendData); } client_ip = ip; client_port = port; InitialClient(); } catch (Exception ex) { throw ex; } }
public EventCommandHandlerTests() { _fixture = new EventCommandHandlerFixture(); _handler = _fixture.GetEventCommandHandler(); }
/// <summary>When implemented in a derived class, returns an object that is provided as the value of the target property for this markup extension. </summary> /// <returns>The object value to set on the property where the extension is applied. </returns> /// <param name="serviceProvider">A service provider helper that can provide services for the markup extension.</param> public override object ProvideValue(IServiceProvider serviceProvider) { var provider = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget)); if (!(provider.TargetObject is FrameworkElement target)) { throw new ArgumentException("Event bindings can only be set on types derived from FrameworkElement."); } var handledEvent = provider.TargetProperty as EventInfo; Type eventType; if (handledEvent == null) { // Some events are handled via Add*Handler methods on other classes. // Examples of this are MouseEnter (Mouse.AddMouseEnterHandler) and LostFocus (FocusManager.AddLostFocusHandler). // In these cases, the event handler type is the second parameter of that method. var handledMethod = provider.TargetProperty as MethodInfo; if (handledMethod == null) { throw new ArgumentException("Event bindings can only be set on events."); } eventType = handledMethod.GetParameters() .Last() .ParameterType; } else { eventType = handledEvent.EventHandlerType; } var eventArgsType = eventType.GetMethod("Invoke") .GetParameters() .Last() .ParameterType; var tempTarget = new BindingTarget(); var useTarget = false; var binding = new Binding(); if (RelativeSource != null) { binding.RelativeSource = RelativeSource; useTarget = true; } else if (Source != null) { binding.Source = Source; useTarget = true; } else if (ElementName != null) { binding.ElementName = ElementName; useTarget = true; } else { tempTarget.DataContext = target.DataContext; } binding.UpdateSourceTrigger = UpdateSourceTrigger; binding.NotifyOnSourceUpdated = NotifyOnSourceUpdated; binding.NotifyOnTargetUpdated = NotifyOnTargetUpdated; binding.NotifyOnValidationError = NotifyOnValidationError; binding.Converter = Converter; binding.ConverterParameter = ConverterParameter; binding.ConverterCulture = ConverterCulture; binding.IsAsync = IsAsync; binding.AsyncState = AsyncState; binding.Mode = BindingMode.OneWay; binding.XPath = XPath; binding.ValidatesOnDataErrors = ValidatesOnDataErrors; binding.ValidatesOnNotifyDataErrors = ValidatesOnNotifyDataErrors; binding.BindsDirectlyToSource = BindsDirectlyToSource; binding.ValidatesOnExceptions = ValidatesOnExceptions; binding.Path = Path; binding.UpdateSourceExceptionFilter = UpdateSourceExceptionFilter; if (ValidationRules != null) { foreach (var validationRule in ValidationRules) { binding.ValidationRules.Add(validationRule); } } ICommand command; if (useTarget) { BindingOperations.SetBinding(target, CommandProperty, binding); command = GetCommand(target); } else { BindingOperations.SetBinding(tempTarget, BindingTarget.CommandProperty, binding); command = tempTarget.Command; } var handler = new EventCommandHandler(command); // TODO: add "update" logic for if/when the binding updates var handlerMethod = typeof(EventCommandHandler).GetMethod(nameof(handler.Handle)) .MakeGenericMethod(eventArgsType); return(Delegate.CreateDelegate(eventType, handler, handlerMethod)); }
public CommandBus(EventCommandHandler eventCommandHandler) { _eventCommandHandler = eventCommandHandler; }