/// <summary> /// Wires the trigger into the interactin hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { InputGesture gesture; if (Key != Key.None) { gesture = new UnrestrictedKeyGesture(Key, Modifiers); } else { gesture = new MouseGesture(MouseAction, Modifiers); } var uiElement = node.UIElement as UIElement; if (uiElement == null) { var ex = new CaliburnException( string.Format( "You cannot use a GestureMessageTrigger with an instance of {0}. The source element must inherit from UIElement.", node.UIElement.GetType().FullName ) ); Log.Error(ex); throw ex; } FindOrCreateLookup(uiElement, gesture) .AddTrigger(this); base.Attach(node); }
public bool BeforeExecute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var methodName = message.As<ActionMessage>().MethodName; var questionPresenter = ServiceLocator.Current.GetInstance<IQuestionPresenter>(); var param = parameters.Add(questionPresenter).ToArray(); var target = handlingNode.MessageHandler.Unwrap(); var targetParams = target.GetType().GetMethod(methodName).GetParameters(); //Prepare if (_prepareMethod.IsNotNull()) { var prepareParams = InvocationExtension.GetArguments(param, targetParams, _prepareMethod.Info.GetParameters()); var prepareResult = _prepareMethod.Invoke(target, prepareParams); if (prepareResult != null) { if (prepareResult is bool) return (bool) prepareResult; } } //Show ServiceLocator.Current.GetInstance<IWindowManager>().ShowDialog(questionPresenter); //Callback if (_callbackMethod.IsNull()) return questionPresenter.Answer == Answer.Yes; var callbackParams = InvocationExtension.GetArguments(param, targetParams, _callbackMethod.Info.GetParameters()); var result = _callbackMethod.Invoke(target, callbackParams); if (_callbackMethod.Info.ReturnType == typeof(bool)) return (bool)result; return true; }
/// <summary> /// Tries to update trigger. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="forceDisabled">if set to <c>true</c> [force disabled].</param> protected virtual void TryUpdateTrigger(ActionMessage actionMessage, IInteractionNode handlingNode, bool forceDisabled) { if (!BlockInteraction) { return; } foreach (var messageTrigger in actionMessage.Source.Triggers) { if (!messageTrigger.Message.Equals(actionMessage)) { continue; } if (forceDisabled) { messageTrigger.UpdateAvailabilty(false); return; } if (this.HasTriggerEffects()) { bool isAvailable = ShouldTriggerBeAvailable(actionMessage, handlingNode); messageTrigger.UpdateAvailabilty(isAvailable); } else { messageTrigger.UpdateAvailabilty(true); } return; } }
protected override void given_the_context_of() { _conventionManager = Mock<IConventionManager>(); _binder = new DefaultMessageBinder(_conventionManager); _handlingNode = Stub<IInteractionNode>(); _sourceNode = Stub<IInteractionNode>(); }
/// <summary> /// Executes the filter. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var result = _method.Invoke(handlingNode.MessageHandler.Unwrap(), parameters); if (_method.Info.ReturnType == typeof(bool)) return (bool)result; return true; }
public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { bool result=PermissionHelper.IsViewEnabled(_screenType); if(!result) message.AvailabilityEffect = AvailabilityEffect.Collapse; return result; }
/// <summary> /// Resolves the special value. /// </summary> /// <param name="potential">The possible special value.</param> /// <param name="sourceNode">The source node.</param> /// <param name="context">The context.</param> /// <returns></returns> protected virtual object ResolveSpecialValue(string potential, IInteractionNode sourceNode, object context) { var splits = potential.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (splits.Length == 0) { return(potential); } var normalized = splits[0].TrimStart('$').ToLower(); object value; if (DetermineSpecialValue(normalized, sourceNode, context, out value)) { if (splits.Length > 1) { var getter = CreateGetter(value, splits.Skip(1).ToArray()); return(getter()); } return(value); } return(potential); }
/// <summary> /// Wires the trigger into the interactin hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { var element = (UIElement)node.UIElement; if (Key != Key.None) { element.KeyUp += element_KeyUp; } else if (MouseAction == MouseAction.LeftClick) { element.MouseLeftButtonUp += element_LeftClick; } else if (MouseAction == MouseAction.LeftDoubleClick) { element.MouseLeftButtonDown += element_LeftDoubleClick; } #if SILVERLIGHT_40 else if (MouseAction == MouseAction.RightClick) { element.MouseRightButtonUp += element_RightClick; } else if (MouseAction == MouseAction.RightDoubleClick) { element.MouseRightButtonDown += element_RightDoubleClick; } #endif base.Attach(node); }
/// <summary> /// Executes the specified this action on the specified target. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The node.</param> /// <param name="context">The context.</param> public override void Execute(ActionMessage actionMessage, IInteractionNode handlingNode, object context) { try { TryUpdateTrigger(actionMessage, handlingNode, true); var parameters = _messageBinder.DetermineParameters( actionMessage, _requirements, handlingNode, context ); var beforeProcessors = _filters.PreProcessors.OfType<IBeforeProcessor>(); foreach (var filter in _filters.PreProcessors.Except(beforeProcessors.Cast<IPreProcessor>())) { if (!filter.Execute(actionMessage, handlingNode, parameters)) return; } //Before foreach (var before in beforeProcessors.OrderByDescending(p => p.Priority)) { if (!before.BeforeExecute(actionMessage, handlingNode, parameters)) return; } CurrentBackgroundActionInfo = _filters.PostProcessors.OfType<IBackgroundActionInfo>().Single(); var container = handlingNode.MessageHandler.Unwrap() as IExtendedPresenter; CurrentBackgroundTask = container.GetMetadata<IBackgroundThreadTask>(); if (CurrentBackgroundTask == null) { CurrentBackgroundTask = TaskImplFactory.CreateTask(CurrentBackgroundActionInfo.TaskMode); container.WasShutdown += (s, e) => CurrentBackgroundTask.Dispose(); container.AddMetadata(CurrentBackgroundTask); AttachTaskEvents(actionMessage, handlingNode, parameters); } //Exectue Before method if (CurrentBackgroundActionInfo.BeforeMethod != null) { var result = CurrentBackgroundActionInfo.BeforeMethod.Invoke(container, parameters); bool canProceed = true; if (CurrentBackgroundActionInfo.BeforeMethod.Info.ReturnType == typeof(bool)) canProceed = result.As<bool>(); if (!canProceed) return; } DoExecute(actionMessage, handlingNode, parameters); } catch (Exception ex) { TryUpdateTrigger(actionMessage, handlingNode, false); if (!TryApplyRescue(actionMessage, handlingNode, ex)) throw; OnCompleted(); } }
private IRoutedMessageHandler FindHandlerOrFail(IRoutedMessage message, bool shouldFail) { IInteractionNode currentNode = this; while (currentNode != null && !currentNode.Handles(message)) { currentNode = currentNode.FindParent(); } if (currentNode == null) { foreach (var handler in message.GetDefaultHandlers(this)) { if (handler.Handles(message)) { RegisterHandler(handler); return(handler); } } if (shouldFail) { throw new CaliburnException( string.Format( "There was no handler found for the message {0}.", message ) ); } } return(currentNode != null ? currentNode.MessageHandler : null); }
protected override void given_the_context_of() { _node = Mock<IInteractionNode>(); _element = new FakeElement(); _message = new FakeMessage {AvailabilityEffect = Mock<IAvailabilityEffect>()}; }
/// <summary> /// Executes the specified this action on the specified target. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The node.</param> /// <param name="context">The context.</param> public override void Execute(ActionMessage actionMessage, IInteractionNode handlingNode, object context) { try { TryUpdateTrigger(actionMessage, handlingNode, true); var parameters = _messageBinder.DetermineParameters( actionMessage, _requirements, handlingNode, context ); CurrentTask = _method.CreateBackgroundTask(handlingNode.MessageHandler.Unwrap(), parameters); foreach (var filter in _filters.PreProcessors) { if (filter.Execute(actionMessage, handlingNode, parameters)) continue; TryUpdateTrigger(actionMessage, handlingNode, false); return; } DoExecute(actionMessage, handlingNode, parameters); } catch (Exception ex) { TryUpdateTrigger(actionMessage, handlingNode, false); if(!TryApplyRescue(actionMessage, handlingNode, ex)) throw; OnCompleted(); } }
public void Execute(IRoutedMessageWithOutcome message, IInteractionNode handlingNode) { FrameworkElement element = null; if(handlingNode != null) element = handlingNode.UIElement as FrameworkElement; if (element == null && message != null) element = message.Source.UIElement as FrameworkElement; if(element == null) { Completed(this, null); return; } var storyboard = (Storyboard)element.Resources[_animationKey]; if (_wait) storyboard.Completed += delegate { Completed(this, null); }; storyboard.Begin(); if (!_wait) Completed(this, null); }
protected override void given_the_context_of() { conventionManager = Mock <IConventionManager>(); binder = new DefaultMessageBinder(conventionManager); handlingNode = Stub <IInteractionNode>(); sourceNode = Stub <IInteractionNode>(); }
object HandleValue(IInteractionNode sourceNode, object context) { var ele = sourceNode.UIElement; var defaults = conventionManager.FindElementConventionOrFail(ele); return(defaults.GetValue(ele)); }
public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var valid = true; var elementsToValidate = GetFieldSetChildren(handlingNode.UIElement as FrameworkElement); foreach(var element in elementsToValidate) { if(!element.IsVisible || !element.IsEnabled) continue; var propertyToValidate = FieldSet.GetPropertyToValidate(element); if(string.IsNullOrEmpty(propertyToValidate)) continue; var fieldInfo = GetField(element.GetType(), string.Format("{0}Property", propertyToValidate)); if(fieldInfo == null) continue; var property = fieldInfo.GetValue(element) as DependencyProperty; if(property == null) continue; var expression = BindingOperations.GetBindingExpression(element, property); if(expression == null) continue; expression.UpdateSource(); var errors = Validation.GetErrors(element); if(errors != null && errors.Any()) valid = false; } return valid; }
/// <summary> /// Tries to update trigger. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="forceDisabled">if set to <c>true</c> [force disabled].</param> protected virtual void TryUpdateTrigger(ActionMessage actionMessage, IInteractionNode handlingNode, bool forceDisabled) { if (!BlockInteraction) { return; } Log.Info("Updating trigger for {0}.", this); foreach (var messageTrigger in actionMessage.Source.Triggers) { if (!messageTrigger.Message.Equals(actionMessage)) { continue; } if (forceDisabled) { messageTrigger.UpdateAvailabilty(false); return; } bool isAvailable = ShouldTriggerBeAvailable(actionMessage, handlingNode); messageTrigger.UpdateAvailabilty(isAvailable); return; } }
/// <summary> /// Determines how this instance affects trigger availability. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The node.</param> /// <returns> /// <c>true</c> if this instance enables triggers; otherwise, <c>false</c>. /// </returns> public virtual bool ShouldTriggerBeAvailable(ActionMessage actionMessage, IInteractionNode handlingNode) { if (!HasTriggerEffects()) { return(true); } var parameters = MessageBinder.DetermineParameters( actionMessage, UnderlyingRequirements, handlingNode, null ); Log.Info("Evaluating trigger effects for {0}.", this); foreach (var filter in UnderlyingFilters.TriggerEffects) { if (!filter.Execute(actionMessage, handlingNode, parameters)) { return(false); } } return(true); }
/// <summary> /// Configures the specified node. /// </summary> /// <param name="node">The node.</param> public void Configure(IInteractionNode node) { var fe = node.UIElement as FrameworkElement; if (fe != null) { RoutedEventHandler handler = null; handler = (s, e) => { this.Bind(node.UIElement, ElementName, Path); fe.Loaded -= handler; }; if ((bool)fe.GetValue(View.IsLoadedProperty)) { handler(null, null); } else { fe.Loaded += handler; } } else { this.Bind(node.UIElement, ElementName, Path); } }
public void Execute(IRoutedMessageWithOutcome message, IInteractionNode handlingNode) { var result = _dialog.ShowDialog().GetValueOrDefault(false); if(result) Completed(this, null); else Completed(this, new CancelResult()); }
/// <summary> /// Executes the filter. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="outcome">The outcome of processing the message</param> public virtual void Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { if(callback == null || outcome.WasCancelled) return; outcome.Result = callback.Invoke(handlingNode.MessageHandler.Unwrap(), outcome.Result); outcome.ResultType = callback.Info.ReturnType; }
/// <summary> /// Determines how this instance affects trigger availability. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The node.</param> /// <returns> /// <c>true</c> if this instance enables triggers; otherwise, <c>false</c>. /// </returns> public override bool ShouldTriggerBeAvailable(ActionMessage actionMessage, IInteractionNode handlingNode) { if (BlockInteraction && _runningCount > 0) { return(false); } return(base.ShouldTriggerBeAvailable(actionMessage, handlingNode)); }
private object[] GetParameters(IRoutedMessage message, IInteractionNode handlingNode, Exception exception) { var target = handlingNode.MessageHandler.Unwrap(); var callParameters = target.GetType().GetMethod(message.As <ActionMessage>().MethodName, BindingFlags.Instance | BindingFlags.Public).GetParameters(); var rescueParameters = _method.Info.GetParameters(); return(InvocationExtension.GetArguments(PrepareParameters(message.Parameters, exception), callParameters, rescueParameters)); }
private void OnComplete(Exception exception) { _enumerator = null; _message = null; _handlingNode = null; Completed(this, exception); }
public void Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { var content = LanguageKey.IsNullOrEmpty() ? Message : LanguageReader.GetValue(LanguageKey); ServiceLocator.Current.GetInstance <IAuditLogModel>().Write(new AuditLog { Action = content, CurrentUser = ApplicationCache.Get <string>(Global.LoggerId) }); }
public void Execute(IRoutedMessageWithOutcome message, IInteractionNode handlingNode) { if(_show) ServiceLocator.Current.GetInstance<ILoadScreen>().StartLoading(_message); else ServiceLocator.Current.GetInstance<ILoadScreen>().StopLoading(); Completed(this, null); }
/// <summary> /// Handles an <see cref="Exception"/>. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="exception">The exception.</param> /// <returns> /// true if the exception was handled, false otherwise /// </returns> public bool Handle(IRoutedMessage message, IInteractionNode handlingNode, Exception exception) { var result = _method.Invoke(handlingNode.MessageHandler.Unwrap(), exception); if(_method.Info.ReturnType == typeof(bool)) return (bool)result; return true; }
/// <summary> /// Executes the custom code. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> public void Execute(IRoutedMessageWithOutcome message, IInteractionNode handlingNode) { _message = message; _handlingNode = handlingNode; _enumerator = _children.GetEnumerator(); ChildCompleted(null, null); }
/// <summary> /// Initializes the message for interaction with the specified node. /// </summary> /// <param name="node">The node.</param> public void Initialize(IInteractionNode node) { _source = node; foreach (var parameter in Parameters) { parameter.ValueChanged += () => Invalidated(); } }
protected override void given_the_context_of() { node = Mock <IInteractionNode>(); element = new FakeElement(); message = new FakeMessage { AvailabilityEffect = Mock <IAvailabilityEffect>() }; }
/// <summary> /// Executes the filter. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var result = _method.Invoke(handlingNode.MessageHandler.Unwrap(), parameters); if (_method.Info.ReturnType == typeof(bool)) { return((bool)result); } return(true); }
/// <summary> /// Wires the trigger into the interaction hierarchy. /// </summary> /// <param name="node">The node.</param> public virtual void Attach(IInteractionNode node) { this.node = node; if (Message != null) { Message.Initialize(node); Message.Invalidated += () => Node.UpdateAvailability(this); } }
/// <summary> /// Initializes the message for interaction with the specified node. /// </summary> /// <param name="node">The node.</param> public void Initialize(IInteractionNode node) { _source = node; foreach (var parameter in Parameters) { parameter.Configure(node); parameter.ValueChanged += () => Invalidated(); } }
/// <summary> /// Wires the trigger into the interaction hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { EventHelper.WireEvent( node.UIElement, node.UIElement.GetType().GetEvent(EventName), OnEvent ); base.Attach(node); }
/// <summary> /// Handles an <see cref="Exception"/>. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="exception">The exception.</param> /// <returns> /// true if the exception was handled, false otherwise /// </returns> public bool Handle(IRoutedMessage message, IInteractionNode handlingNode, Exception exception) { var result = _method.Invoke(handlingNode.MessageHandler.Unwrap(), exception); if (_method.Info.ReturnType == typeof(bool)) { return((bool)result); } return(true); }
protected void DoExecute(ActionMessage actionMessage, IInteractionNode handlingNode, object[] parameters) { if (CurrentBackgroundActionInfo.BlockIfBusy && CurrentBackgroundTask.IsBusy) { return; } var context = new BackgroundActionContext(CurrentBackgroundActionInfo.BackgroundEndMode, () => _method.Invoke(handlingNode.MessageHandler.Unwrap(), parameters)); CurrentBackgroundTask.Enqueue(context); }
/// <summary> /// Executes the filter. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="outcome">The outcome of processing the message</param> public virtual void Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { if (_callback == null || outcome.WasCancelled) { return; } outcome.Result = _callback.Invoke(handlingNode.MessageHandler.Unwrap(), outcome.Result); outcome.ResultType = _callback.Info.ReturnType; }
/// <summary> /// Wires the trigger into the interaction hierarchy. /// </summary> /// <param name="node">The node.</param> public virtual void Attach(IInteractionNode node) { _node = node; if (Message != null) { Message.Initialize(node); Message.Invalidated += () => Node.UpdateAvailability(this); } }
/// <summary> /// Wires the trigger into the interactin hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { var element = (UIElement)node.UIElement; if (Key != Key.None) element.KeyUp += element_KeyUp; else if (MouseAction == MouseAction.LeftClick) element.MouseLeftButtonUp += element_MouseLeftButtonUp; base.Attach(node); }
protected override void given_the_context_of() { factory = new DefaultMethodFactory(); conventionManager = Mock<IConventionManager>(); binder = new DefaultMessageBinder(conventionManager); handlingNode = Stub<IInteractionNode>(); sourceNode = Stub<IInteractionNode>(); host = new ControlHost(); sourceNode.Stub(x => x.UIElement).Return(host).Repeat.Any(); }
public void Execute(IRoutedMessageWithOutcome message, IInteractionNode handlingNode) { var source = (FrameworkElement)message.Source.UIElement; var popup = source.FindName("detailsPopup") as Popup; popup.IsOpen = true; popup.CaptureMouse(); popup.Child.MouseLeave += (o, e) => popup.IsOpen = false; Completed(this, null); }
/// <summary> /// Wires the trigger into the interaction hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { var handler = EventHandlerFactory.Wire( node.UIElement, EventName ); handler.SetActualHandler(Event_Occurred); base.Attach(node); }
protected override void given_the_context_of() { factory = new DefaultMethodFactory(); conventionManager = Mock <IConventionManager>(); binder = new DefaultMessageBinder(conventionManager); handlingNode = Stub <IInteractionNode>(); sourceNode = Stub <IInteractionNode>(); host = new ControlHost(); sourceNode.Stub(x => x.UIElement).Return(host).Repeat.Any(); }
/// <summary> /// Applies the rescue or fails. /// </summary> /// <param name="message">The action message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="ex">The exception.</param> protected virtual bool TryApplyRescue(IRoutedMessage message, IInteractionNode handlingNode, Exception ex) { foreach (var rescue in _filters.Rescues) { if (rescue.Handle(message, handlingNode, ex)) { return(true); } } return(false); }
public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { message.AvailabilityEffect = Effect; var functionKeys = ApplicationCache.Get<ICollection<string>>(Global.LoginUserFunctionKeys); if (functionKeys == null || functionKeys.Count == 0) { //Admin return true; } return functionKeys.Contains(FunctionKey); }
bool IPreProcessor.Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var target = handlingNode.MessageHandler.Unwrap(); var inputPresenter = ServiceLocator.Current.GetInstance<IDialogBoxPresenter>(); inputPresenter.Invoker = target; inputPresenter.ConfirmDelegate = ConfirmDelegate; inputPresenter.PartView = PartView; parameters[0] = inputPresenter; return true; }
/// <summary> /// Executes the filter. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var target = handlingNode.MessageHandler.Unwrap(); if (target == null) return false; var result = Method.Invoke(target, parameters); if (Method.Info.ReturnType == typeof(bool)) return (bool)result; return true; }
public override void Execute(ActionMessage actionMessage, IInteractionNode handlingNode, object context) { try { var parameters = _messageBinder.DetermineParameters(actionMessage, _requirements, handlingNode, context); // IBeforeProcessor 继承 IPreProcessor 相当于一样 var processors = _filters.PreProcessors.OfType <IBeforeProcessor>(); // caliburn preProcessor (before) (针对 IBeforeProcessor) foreach (var filter in _filters.PreProcessors.Except(processors.Cast <IPreProcessor>())) { if (!filter.Execute(actionMessage, handlingNode, parameters)) { return; } } // before custom aop hehavior (针对IPreProcessor) foreach (var before in processors.OrderByDescending(p => p.Priority)) { if (!before.BeforeExecute(actionMessage, handlingNode, parameters)) { return; } } object result = null; // the method will excute result = _method.Invoke(handlingNode.MessageHandler.Unwrap(), parameters); var outcome = new MessageProcessingOutcome(result, _method.Info.ReturnType, false); // post foreach (var filter in _filters.PostProcessors) { filter.Execute(actionMessage, handlingNode, outcome); } HandleOutcome(actionMessage, handlingNode, outcome); } catch (Exception ex) { if (!TryApplyRescue(actionMessage, handlingNode, ex)) { throw; } OnCompleted(); } }
/// <summary> /// Determines if the key is a special value. /// </summary> /// <param name="possibleKey">The possible key.</param> /// <param name="sourceNode">The source node.</param> /// <param name="context">The context.</param> /// <param name="value">The value.</param> /// <returns></returns> protected virtual bool DetermineSpecialValue(string possibleKey, IInteractionNode sourceNode, object context, out object value) { Func <IInteractionNode, object, object> handler; if (valueHandlers.TryGetValue(possibleKey, out handler)) { value = handler(sourceNode, context); return(true); } value = null; return(false); }
public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { message.AvailabilityEffect = Effect; var functionKeys = ApplicationCache.Get <ICollection <string> >(Global.LoginUserFunctionKeys); if (functionKeys == null || functionKeys.Count == 0) { //Admin return(true); } return(functionKeys.Contains(FunctionKey)); }
bool IPreProcessor.Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var target = handlingNode.MessageHandler.Unwrap(); var inputPresenter = ServiceLocator.Current.GetInstance <IDialogBoxPresenter>(); inputPresenter.Invoker = target; inputPresenter.ConfirmDelegate = ConfirmDelegate; inputPresenter.PartView = PartView; parameters[0] = inputPresenter; return(true); }
private void HandleOutcome(IRoutedMessageWithOutcome message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { var result = _messageBinder.CreateResult(outcome); result.Completed += (r, ex) =>{ if(ex != null) { if(!TryApplyRescue(message, handlingNode, ex)) throw ex; } OnCompleted(); }; result.Execute(message, handlingNode); }
public void Execute(IRoutedMessageWithOutcome message, IInteractionNode handlingNode) { var client = new WebClient(); client.OpenReadCompleted += (s, e) =>{ if(e.Error != null) Core.Invocation.Execute.OnUIThread(() => Completed(this, e.Error)); else { Stream = e.Result; Core.Invocation.Execute.OnUIThread(() => Completed(this, null)); } }; client.OpenReadAsync(_uri); }
/// <summary> /// Wires the trigger into the interaction hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { var commandProperty = node.UIElement.GetType().GetProperty("Command"); if(commandProperty == null) { throw new CaliburnException( string.Format( "You cannot use a CommandMessageTrigger with an instance of {0}. The source element should be an ICommandSource.", node.UIElement.GetType().FullName ) ); } commandProperty.SetValue(node.UIElement, this, null); base.Attach(node); }
/// <summary> /// Executes the specified this action on the specified target. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The node.</param> /// <param name="context">The context.</param> public override void Execute(ActionMessage actionMessage, IInteractionNode handlingNode, object context) { try { var parameters = _messageBinder.DetermineParameters( actionMessage, _requirements, handlingNode, context ); TryUpdateTrigger(actionMessage, handlingNode, true); foreach (var filter in _filters.PreProcessors) { if (filter.Execute(actionMessage, handlingNode, parameters)) continue; TryUpdateTrigger(actionMessage, handlingNode, false); return; } var outcome = new MessageProcessingOutcome( _method.Invoke(handlingNode.MessageHandler.Unwrap(), parameters), _method.Info.ReturnType, false ); foreach (var filter in _filters.PostProcessors) { filter.Execute(actionMessage, handlingNode, outcome); } HandleOutcome(actionMessage, handlingNode, outcome); } catch (Exception ex) { TryUpdateTrigger(actionMessage, handlingNode, false); if(!TryApplyRescue(actionMessage, handlingNode, ex)) { Log.Error(ex); throw; } OnCompleted(); } }
bool IPreProcessor.Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { //TODO: support of syncronous tasks var bgTask = AsynchronousAction.CurrentTask; if(bgTask == null) throw new InvalidOperationException("ActionInfo attribute can only be used on asynchronous actions"); var runningAction = new RunningAction(bgTask, IsIndeterminate, IsCancellable) { Title = Title }; _runningActionPresenter.RegisterTask(runningAction); bgTask.Completed += (o, e) => _runningActionPresenter.UnregisterTask(runningAction); return true; }
/// <summary> /// Wires the trigger into the interaction hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { var element = node.UIElement as UIElement; if(element != null) element.AddHandler(RoutedEvent, new RoutedEventHandler(Event_Occurred)); else { throw new CaliburnException( string.Format( "You cannot use a RoutedEventMessageTrigger with an instance of {0}. The source element must inherit from UIElement.", node.UIElement.GetType().FullName ) ); } base.Attach(node); }