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> /// 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 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; }
public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { bool result=PermissionHelper.IsViewEnabled(_screenType); if(!result) message.AvailabilityEffect = AvailabilityEffect.Collapse; return result; }
/// <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; }
public static void Send(this DependencyObject origin, IRoutedMessage message, object context) { var node = origin.GetValue(DefaultRoutedMessageController.NodeProperty) as IInteractionNode; if (node != null) node.ProcessMessage(message, context); }
/// <summary> /// Processes the specified message. /// </summary> /// <param name="message">The message.</param> /// <param name="context">An object that provides additional context for message processing.</param> public void Process(IRoutedMessage message, object context) { var actionMessage = message as ActionMessage; if (actionMessage != null) _host.GetAction(actionMessage).Execute(actionMessage, _node, context); else throw new CaliburnException("The handler cannot process this message."); }
/// <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 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; }
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; }
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) { //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> /// 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 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); }
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 }; registry.RegisterTask(runningAction); bgTask.Completed += (o, e) => registry.UnregisterTask(runningAction); return(true); }
/// <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) { object result; if (RunMethodBeforeDialog) { result = RunMethod(message, handlingNode, exception); ShowDialog(exception); } else { ShowDialog(exception); result = RunMethod(message, handlingNode, exception); } if (_method.Info.ReturnType == typeof(bool)) { return((bool)result); } return(true); }
/// <summary> /// Determines the parameters that a method should be invoked with. /// </summary> /// <param name="message">The message to determine the parameters for.</param> /// <param name="requiredParameters">The requirements for method binding.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="context">The context.</param> /// <returns>The actual parameters</returns> public virtual object[] DetermineParameters(IRoutedMessage message, IList<RequiredParameter> requiredParameters, IInteractionNode handlingNode, object context) { if (requiredParameters == null || requiredParameters.Count == 0) return new object[] {}; var providedValues = message.Parameters.Select(x => x.Value).ToArray(); if (requiredParameters.Count == providedValues.Length) return CoerceValues(requiredParameters, providedValues, message.Source, context); if (providedValues.Length == 0) return LocateAndCoerceValues(requiredParameters, message.Source, handlingNode, context); throw new CaliburnException( string.Format( "Parameter count mismatch. {0} parameters were provided but {1} are required for {2}.", providedValues.Length, requiredParameters.Count, message ) ); }
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); } } var info = string.Format( "There was no handler found for the message {0}.", message ); if (shouldFail) { var exception = new CaliburnException(info); Log.Error(exception); throw exception; } Log.Info(info); } return(currentNode != null ? currentNode.MessageHandler : null); }
public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { var valid = true; var elementsToValidate = FieldSet.GetChildren(handlingNode.UIElement as FrameworkElement, fieldSetName); foreach (var element in elementsToValidate) { if (!element.IsVisible || !element.IsEnabled) { continue; } var propertyToValidate = FieldSet.GetPropertyToValidate(element); if (string.IsNullOrEmpty(propertyToValidate)) { continue; } var property = FieldSet.GetDependencyProperty(element.GetType(), propertyToValidate); 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); }
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; } } var info = string.Format( "There was no handler found for the message {0}.", message ); if (shouldFail) { var exception = new CaliburnException(info); Log.Error(exception); throw exception; } Log.Info(info); } return currentNode != null ? currentNode.MessageHandler : null; }
/// <summary> /// Processes the message. /// </summary> /// <param name="message">The message.</param> /// <param name="context">An object that provides additional context for message processing.</param> public void ProcessMessage(IRoutedMessage message, object context) { FindHandlerOrFail(message, true).Process(message, context); }
/// <summary> /// Processes the specified message. /// </summary> /// <param name="message">The message.</param> /// <param name="context">An object that provides additional context for message processing.</param> public void Process(IRoutedMessage message, object context) { if (message != this) { var ex = new CaliburnException("The handler cannot process the message."); Log.Error(ex); throw ex; } CreateActionMessage(); action.Execute(actionMessage, Source, context); Log.Info("Processed {0} on command {1}.", actionMessage, Command); }
/// <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) { object result; if (RunMethodBeforeDialog) { result = RunMethod(message, handlingNode, exception); ShowDialog(exception); } else { ShowDialog(exception); result = RunMethod(message, handlingNode, exception); } if (_method.Info.ReturnType == typeof(bool)) return (bool)result; return true; }
private object RunMethod(IRoutedMessage message, IInteractionNode handlingNode, Exception exception) { return _method.Invoke(handlingNode.MessageHandler.Unwrap(), GetParameters(message, handlingNode, exception)); }
/// <summary> /// Indicates whether this instance can handle the speicified message. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public bool Handles(IRoutedMessage message) { return(message == this); }
/// <summary> /// Parses the specified message text. /// </summary> /// <param name="target">The target.</param> /// <param name="messageText">The message text.</param> /// <returns>The triggers parsed from the text.</returns> protected virtual IMessageTrigger ParseMessage(string messageText, DependencyObject target) { var triggerPlusMessage = messageText.Split('='); string messageDetail = triggerPlusMessage.Last() .Replace("[", string.Empty) .Replace("]", string.Empty) .Trim(); IRoutedMessage message = null; foreach (var keyValuePair in messageParsers) { if (messageDetail.StartsWith(keyValuePair.Key, StringComparison.CurrentCultureIgnoreCase)) { message = keyValuePair.Value .Parse(target, messageDetail.Remove(0, keyValuePair.Key.Length).Trim()); break; } } if (message == null) { message = messageParsers[defaultMessageParserKey] .Parse(target, messageDetail); Log.Info("Using default parser {0} for {1} on {2}.", defaultMessageParserKey, messageText, target); } IMessageTrigger trigger = null; if (triggerPlusMessage.Length == 1) { var defaults = conventionManager.FindElementConventionOrFail(target); trigger = defaults.CreateTrigger(); Log.Info("Using default trigger {0} for {1} on {2}.", trigger, messageText, target); } else { var triggerDetail = triggerPlusMessage[0] .Replace("[", string.Empty) .Replace("]", string.Empty) .Trim(); foreach (var keyValuePair in triggerParsers) { if (triggerDetail.StartsWith(keyValuePair.Key, StringComparison.CurrentCultureIgnoreCase)) { trigger = keyValuePair.Value .Parse(target, triggerDetail.Remove(0, keyValuePair.Key.Length).Trim()); break; } } } if (trigger == null) { var exception = new CaliburnException("Could not determine trigger type."); Log.Error(exception); throw exception; } trigger.Message = message; return(trigger); }
private object RunMethod(IRoutedMessage message, IInteractionNode handlingNode, Exception exception) { return(_method.Invoke(handlingNode.MessageHandler.Unwrap(), GetParameters(message, handlingNode, exception))); }
/// <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) { Role clientRole = new Role{ Name = ClientInfo.Instance.Role}; foreach (Role acceptRole in AcceptRoles) { if (acceptRole.Equals(clientRole)) return true; } return false; }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> public bool Equals(IRoutedMessage other) { return ReferenceEquals(this, other); }
public bool Equals(IRoutedMessage other) { throw new NotImplementedException(); }
public object[] DetermineParameters(IRoutedMessage message, IList <RequiredParameter> requiredParameters, IInteractionNode handlingNode, object context) { throw new NotImplementedException(); }
/// <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)) { Log.Info("Rescue applied for {0}.", this); return true; } } Log.Warn("Rescue not applied for {0}.", this); return false; }
//Note: The code that will execute before the action. public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { return Thread.CurrentPrincipal.IsInRole(_role); }
public object[] DetermineParameters(IRoutedMessage message, IList<RequiredParameter> requiredParameters, IInteractionNode handlingNode, object context) { throw new NotImplementedException(); }
/// <summary> /// Determines whethyer the target can handle the specified action. /// </summary> /// <param name="message">The action details.</param> /// <returns></returns> public bool Handles(IRoutedMessage message) { var actionMessage = message as ActionMessage; return(actionMessage != null && FindActionHandler(actionMessage) != null); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> public bool Equals(IRoutedMessage other) { return(ReferenceEquals(this, other)); }
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); }
void IPostProcessor.Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { ServiceLocator.Current.GetInstance <IWindowManager>().ShowDialog(outcome.Result); }
/// <summary> /// Indicates whether this instance can handle the speicified message. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public bool Handles(IRoutedMessage message) { return message == this; }
bool Caliburn.PresentationFramework.Filters.IPreProcessor.Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { // 因为 IBeforeProcessor 也继承 IPreProcessor, 为了让 CustomSynchronousAction 避免执行 2 次, 此方法空跑不做任何事情. // 交由 IBeforeProcessor 的实例 BeforeExecute 执行 return(true); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> public bool Equals(IRoutedMessage other) { if(other is ActionMessage) return ReferenceEquals(actionMessage, other); return ReferenceEquals(this, other); }
/// <summary> /// Determines whethyer the target can handle the specified action. /// </summary> /// <param name="message">The action details.</param> /// <returns></returns> public bool Handles(IRoutedMessage message) { var actionMessage = message as ActionMessage; return(actionMessage != null && _host.GetAction(actionMessage) != null); }
//Note: The code that will execute before the action. public bool Execute(IRoutedMessage message, IInteractionNode handlingNode, object[] parameters) { return CurrentUser.IsInRole(_role); }
/// <summary> /// Determines whethyer the target can handle the specified action. /// </summary> /// <param name="message">The action details.</param> /// <returns></returns> public bool Handles(IRoutedMessage message) { var actionMessage = message as ActionMessage; return actionMessage != null && FindActionHandler(actionMessage) != null; }
/// <summary> /// Processes the message. /// </summary> /// <param name="message">The message.</param> /// <param name="context">An object that provides additional context for message processing.</param> public void ProcessMessage(IRoutedMessage message, object context) { FindHandlerOrFail(message, true).Process(message, context); }
/// <summary> /// Processes the specified message. /// </summary> /// <param name="message">The message.</param> /// <param name="context">An object that provides additional context for message processing.</param> public void Process(IRoutedMessage message, object context) { var actionMessage = message as ActionMessage; if (actionMessage != null) { FindActionHandler(actionMessage).Execute(actionMessage, _node, context); Log.Info("Processed message {0}.", actionMessage); } else { var ex = new CaliburnException("The handler cannot process this message."); Log.Error(ex); throw ex; } }
/// <summary> /// Determines whether this node can handle the specified message. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public bool Handles(IRoutedMessage message) { return _messageHandler != null && _messageHandler.Handles(message); }
/// <summary> /// Determines whether this node can handle the specified message. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public bool Handles(IRoutedMessage message) { return(_messageHandler != null && _messageHandler.Handles(message)); }