Example #1
0
        /// <summary>
        /// Executes the result within the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute(ResultExecutionContext context)
        {
            if (outcome.WasCancelled)
            {
                Completed(this, new ResultCompletionEventArgs {
                    WasCancelled = outcome.WasCancelled
                });
                return;
            }

            var element = context.Message.Source.UIElement;

            if (string.IsNullOrEmpty(context.Message.OutcomePath))
            {
                var target = element.FindNameExhaustive <DependencyObject>(context.Message.DefaultOutcomeElement, false);

                if (target != null)
                {
                    var defaults = conventionManager.FindElementConventionOrFail(target);
                    defaults.SetValue(target, outcome.Result);
                }
            }
            else
            {
                var parts = context.Message.OutcomePath.Split(Separator, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length < 2)
                {
                    Completed(
                        this,
                        new ResultCompletionEventArgs
                    {
                        Error = new CaliburnException(
                            string.Format("{0} is not a valid return path.", context.Message.OutcomePath)
                            )
                    });
                    return;
                }

                var target = element.FindNameExhaustive <object>(parts[0], true);
                var setter = CreateSetter(target, parts.Skip(1).ToArray());

                if (setter == null)
                {
                    Completed(
                        this,
                        new ResultCompletionEventArgs
                    {
                        Error = new CaliburnException(
                            string.Format("{0} is not a valid property path.", parts.Skip(1).Aggregate((a, c) => a + c))
                            )
                    });
                    return;
                }

                setter(outcome.Result);
            }

            Completed(this, new ResultCompletionEventArgs());
        }
Example #2
0
        /// <summary>
        /// Executes the result within the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute(ResultExecutionContext context)
        {
            if (_outcome.WasCancelled)
            {
                Completed(this, new ResultCompletionEventArgs {WasCancelled = _outcome.WasCancelled});
                return;
            }

            var element = context.Message.Source.UIElement;

            if (string.IsNullOrEmpty(context.Message.OutcomePath))
            {
                var target = element.FindNameExhaustive<DependencyObject>(context.Message.DefaultOutcomeElement, false);

                if (target != null)
                {
                    var defaults = _conventionManager.FindElementConventionOrFail(target);
                    defaults.SetValue(target, _outcome.Result);
                }
            }
            else
            {
                var parts = context.Message.OutcomePath.Split(_separator, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length < 2)
                {
                    Completed(
                        this,
                        new ResultCompletionEventArgs
                        {
                            Error = new CaliburnException(
                                string.Format("{0} is not a valid return path.", context.Message.OutcomePath)
                                )
                        });
                    return;
                }

                var target = element.FindNameExhaustive<object>(parts[0], true);
                var setter = CreateSetter(target, parts.Skip(1).ToArray());

                if (setter == null)
                {
                    Completed(
                        this,
                        new ResultCompletionEventArgs
                        {
                            Error = new CaliburnException(
                                string.Format("{0} is not a valid property path.", parts.Skip(1).Aggregate((a, c) => a + c))
                                )
                        });
                    return;
                }

                setter(_outcome.Result);
            }

            Completed(this, new ResultCompletionEventArgs());
        }
 public void Execute(ResultExecutionContext context)
 {
     ThreadPool.QueueUserWorkItem(state =>
     {
         _method();
         if (Completed != null)
             Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
     });
 }
 public void Execute(ResultExecutionContext context)
 {
     var res = new List<LatestAdditionItemViewModel>();
     for(var i=1;i<maxCount;i++)
     {
         res.Add(new LatestAdditionItemViewModel(DateTime.Now.AddDays(-i), "Subject " + i));
     }
     Result = res;
     Completed(this, new ResultCompletionEventArgs());
 }
Example #5
0
        public void Execute(ResultExecutionContext context)
        {
            var source = (FrameworkElement)context.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, new ResultCompletionEventArgs());
        }
        /// <inheritdoc/>
        public void Execute(ResultExecutionContext context)
        {
            Guard.NotNull(context, "context");

            var shellScreen = context.ServiceLocator.GetInstance<IShellScreen>();
            var sessionPresenter = context.ServiceLocator.GetInstance<ISessionScreen>();

            sessionPresenter.Player = CreateSessionPlayer();
            shellScreen.OpenScreen(sessionPresenter, delegate { });

            Completed(this, new ResultCompletionEventArgs());
        }
 public void Execute(ResultExecutionContext context)
 {
     DependencyObject view = GetView(_viewModel);
     DependencyObject validationSummary= view.FindName(_nameOfValidationSummary);
     if (validationSummary != null && validationSummary is ValidationSummary)
     {
         (validationSummary as ValidationSummary).Errors.Add(new ValidationSummaryItem(_message));
     }
     else
     {
         context.ServiceLocator.Log.Warn("validation summary {0} not found.",_nameOfValidationSummary);
     }
 }
Example #8
0
 /// <summary>
 /// Executes the result using the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Execute(ResultExecutionContext context)
 {
     if (innerTask.IsCompleted)
     {
         OnCompleted(innerTask);
     }
     else
     {
         innerTask.ContinueWith(OnCompleted,
                                System.Threading.SynchronizationContext.Current != null
                 ? TaskScheduler.FromCurrentSynchronizationContext()
                 : TaskScheduler.Current);
     }
 }
Example #9
0
        /// <summary>
        /// Executes a coroutine.
        /// </summary>
        /// <param name="coroutine">The coroutine to execute.</param>
        /// <param name="context">The context to execute the coroutine within.</param>
        /// <param name="callback">The completion callback.</param>
        public static void BeginExecute(IEnumerator <IResult> coroutine, ResultExecutionContext context, EventHandler <ResultCompletionEventArgs> callback)
        {
            Log.Info("Executing coroutine.");

            var enumerator = createParentEnumerator(coroutine);

            builder.BuildUp(enumerator);

            if (callback != null)
            {
                enumerator.Completed += callback;
            }
            enumerator.Completed += Completed;

            enumerator.Execute(context);
        }
Example #10
0
        static Task <TResult> InternalExecuteAsync <TResult>(IResult result, ResultExecutionContext context)
        {
            var taskSource = new TaskCompletionSource <TResult>();

            EventHandler <ResultCompletionEventArgs> completed = null;

            completed = (s, e) => {
                result.Completed -= completed;

                if (e.Error != null)
                {
                    taskSource.SetException(e.Error);
                }
                else if (e.WasCancelled)
                {
                    taskSource.SetCanceled();
                }
                else
                {
                    var rr = result as IResult <TResult>;
                    taskSource.SetResult(rr != null ? rr.Result : default(TResult));
                }
            };

            try
            {
                IoC.BuildUp(result);
                result.Completed += completed;
                result.Execute(context ?? new ResultExecutionContext(IoC.Get <IServiceLocator>(), null, null));
            }
            catch (Exception ex)
            {
                result.Completed -= completed;
                taskSource.SetException(ex);
            }

            return(taskSource.Task);
        }
Example #11
0
        /// <summary>
        /// Executes a coroutine.
        /// </summary>
        /// <param name="coroutine">The coroutine to execute.</param>
        /// <param name="context">The context to execute the coroutine within.</param>
        public static void Execute(IEnumerator<IResult> coroutine, ResultExecutionContext context)
        {
            Log.Info("Executing coroutine.");

            var enumerator = CreateParentEnumerator(coroutine);
            IoC.BuildUp(enumerator);

            enumerator.Completed += Completed;
            enumerator.Execute(context);
        }
Example #12
0
 /// <summary>
 ///   Executes the result using the specified context.
 /// </summary>
 /// <param name = "context">The context.</param>
 public void Execute(ResultExecutionContext context)
 {
     this.context = context;
     ChildCompleted(null, new ResultCompletionEventArgs());
 }
Example #13
0
 /// <summary>
 /// Executes a coroutine.
 /// </summary>
 /// <param name="coroutine">The coroutine to execute.</param>
 /// <param name="context">The context to execute the coroutine within.</param>
 public static void BeginExecute(IEnumerator <IResult> coroutine, ResultExecutionContext context)
 {
     BeginExecute(coroutine, context, null);
 }
 public void Execute(ResultExecutionContext context)
 {
     _loadingViewModel.UpdateActionText(_actionText);
     Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
 }
 public void Execute(ResultExecutionContext context)
 {
     ModuleDomainContext moduleContext = new ModuleDomainContext();
     moduleContext.Load(moduleContext.GetListModulesQuery()).Completed += GetModulesCompleted;
 }
Example #16
0
 public void Execute(ResultExecutionContext context)
 {
     var bus = ServiceLocator.Current.GetInstance<IBackend>();
     bus.Send(_command);
     Completed(this, new ResultCompletionEventArgs());
 }
 public void Execute(ResultExecutionContext context)
 {
 }
Example #18
0
 /// <summary>
 /// Executes the result using the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Execute(ResultExecutionContext context)
 {
     this.context = context;
     ChildCompleted(null, new ResultCompletionEventArgs());
 }
 public void Execute(ResultExecutionContext context)
 {
     Completed(this, new ResultCompletionEventArgs());
 }
Example #20
0
 /// <summary>
 /// Executes an <see cref="IResult"/> asynchronous.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="result">The coroutine to execute.</param>
 /// <param name="context">The context to execute the coroutine within.</param>
 /// <returns>A task that represents the asynchronous coroutine.</returns>
 public static Task <TResult> ExecuteAsync <TResult>(this IResult <TResult> result,
                                                     ResultExecutionContext context = null)
 {
     return(InternalExecuteAsync <TResult>(result, context));
 }
Example #21
0
 /// <summary>
 /// Executes an <see cref="IResult"/> asynchronous.
 /// </summary>
 /// <param name="result">The coroutine to execute.</param>
 /// <param name="context">The context to execute the coroutine within.</param>
 /// <returns>A task that represents the asynchronous coroutine.</returns>
 public static Task ExecuteAsync(this IResult result, ResultExecutionContext context = null)
 {
     return(InternalExecuteAsync <object>(result, context));
 }