Exemplo n.º 1
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(ResultExecutionContext context)
        {
            var viewModel     = locateViewModel(context);
            var windowManager = context.ServiceLocator.GetInstance <IWindowManager>();

            windowManager.ShowNotification(viewModel, durationInMilliseconds);
        }
Exemplo n.º 2
0
        public void Execute(ResultExecutionContext context)
        {
            DeploymentCatalog catalog;

            if (Catalogs.TryGetValue(uri, out catalog))
            {
                Completed(this, new ResultCompletionEventArgs());
            }
            else
            {
                catalog = new DeploymentCatalog(new Uri("/ClientBin/" + uri, UriKind.RelativeOrAbsolute));
                catalog.DownloadCompleted += (s, e) => {
                    if (e.Error == null)
                    {
                        Catalogs[uri] = catalog;
                        Catalog.Catalogs.Add(catalog);
                        catalog.Parts
                        .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                        .Where(assembly => !AssemblySource.Contains(assembly))
                        .Apply(x => AssemblySource.Add(x));
                    }
                    else
                    {
                        Loader.Hide().Execute(context);
                    }

                    Completed(this, new ResultCompletionEventArgs {
                        Error        = e.Error,
                        WasCancelled = false
                    });
                };

                catalog.DownloadAsync();
            }
        }
Exemplo n.º 3
0
 public void Execute(ResultExecutionContext context)
 {
     Backend.Send(query, response => {
         Response = response;
         Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
     });
 }
        public void Execute(ResultExecutionContext context)
        {
            var result = _commonDialog.ShowDialog()
                .GetValueOrDefault(false);

            Completed(this, new ResultCompletionEventArgs {WasCancelled = !result});
        }
Exemplo n.º 5
0
        public void Execute(ResultExecutionContext context)
        {
            var questionDialog = context.ServiceLocator.GetInstance<IQuestionDialog>();
            var windowManager = context.ServiceLocator.GetInstance<IWindowManager>();

            var question = new Question(
                Text,
                _possibleAnswers
                );

            questionDialog.Setup(
                Caption,
                new[] {question}
                );

            questionDialog.Deactivated += (s,e) => {
                if (!e.WasClosed)
                    return;

                if(_handleResult != null)
                    _handleResult(question.Answer);
                else if(question.Answer == Answer.No || question.Answer == Answer.Cancel)
                {
                    Completed(this, new ResultCompletionEventArgs {WasCancelled = true});
                    return;
                }

                Completed(this, new ResultCompletionEventArgs());
            };

            windowManager.ShowDialog(questionDialog, null);
        }
Exemplo n.º 6
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            if (isDeposit)
            {
                proxy.DepositCompleted += OnSavingCompleted;
                proxy.DepositAsync(userId: userId,
                                   accountId: accountId,
                                   operationDate: operationDate,
                                   price: price,
                                   quantity: quantity,
                                   comment: comment,
                                   categoryId: categoryId
                                   );
            }
            else
            {
                proxy.WithdrawalCompleted += OnSavingCompleted;
                proxy.WithdrawalAsync(userId: userId,
                                      accountId: accountId,
                                      operationDate: operationDate,
                                      price: price,
                                      quantity: quantity,
                                      comment: comment,
                                      categoryId: categoryId
                                      );
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(ResultExecutionContext context)
        {
            FrameworkElement element = null;

            if (context.HandlingNode != null)
            {
                element = context.HandlingNode.UIElement as FrameworkElement;
            }

            if (element == null && context.Message != null)
            {
                element = context.Message.Source.UIElement as FrameworkElement;
            }

            if (element == null)
            {
                Completed(this, new ResultCompletionEventArgs());
                return;
            }

            var storyboard = (Storyboard)element.Resources[key];

            if (wait)
            {
                EventHandler handler = null;
                handler = delegate {
                    storyboard.Completed -= handler;
                    Completed(this, new ResultCompletionEventArgs());
                };
                storyboard.Completed += handler;
            }

            switch (action)
            {
            case AnimationAction.Begin:
                storyboard.Begin();
                break;

            case AnimationAction.Pause:
                storyboard.Pause();
                break;

            case AnimationAction.Resume:
                storyboard.Resume();
                break;

            case AnimationAction.Stop:
                storyboard.Stop();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (!wait)
            {
                Completed(this, new ResultCompletionEventArgs());
            }
        }
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(ResultExecutionContext context)
        {
            var result = commonDialog.ShowDialog()
                         .GetValueOrDefault(false);

            Completed(this, new ResultCompletionEventArgs {
                WasCancelled = !result
            });
        }
Exemplo n.º 9
0
        public void Execute(ResultExecutionContext context)
        {
            var screen = !string.IsNullOrEmpty(name)
                ? context.ServiceLocator.GetInstance <object>(name)
                : context.ServiceLocator.GetInstance(screenType, null);

            Shell.ActivateItem(screen);
            Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 10
0
        public void Execute(ResultExecutionContext context)
        {
            var inputManager = context.ServiceLocator.GetInstance<IInputManager>();

            if(string.IsNullOrEmpty(_property))
                inputManager.Focus(_model);
            else inputManager.Focus(_model, _property);

            Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 11
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());
        }
Exemplo n.º 12
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.DeleteTransactionCompleted += OnDeleteCompleted;
            proxy.DeleteTransactionAsync(userId,
                                         accountId,
                                         transactionId,
                                         DateTime.UtcNow
                                         );
        }
Exemplo n.º 13
0
        public void Execute(ResultExecutionContext context)
        {
            var documentWorkspace = screen.Parent as IDocumentWorkspace;

            if (documentWorkspace != null)
            {
                documentWorkspace.Edit(screen);
            }

            closeCheck(Shell.Dialogs, result => Completed(this, new ResultCompletionEventArgs {
                WasCancelled = !result
            }));
        }
Exemplo n.º 14
0
        public void Execute(ResultExecutionContext context)
        {
            object sourceViewModel = null;

            if(context.HandlingNode != null)
                sourceViewModel = context.HandlingNode.MessageHandler.Unwrap();

            if(_isBusy)
                context.ServiceLocator.GetInstance<IBusyService>().MarkAsBusy(sourceViewModel, _busyViewModel);
            else context.ServiceLocator.GetInstance<IBusyService>().MarkAsNotBusy(sourceViewModel);

            Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 15
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.TransferCompleted += OnTransferCompleted;
            proxy.TransferAsync(user1Id,
                                account1Id,
                                user2Id,
                                account2Id,
                                operationDate,
                                amount,
                                comment
                                );
        }
Exemplo n.º 16
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(ResultExecutionContext context)
        {
            var inputManager = context.ServiceLocator.GetInstance <IInputManager>();

            if (string.IsNullOrEmpty(property))
            {
                inputManager.Focus(model);
            }
            else
            {
                inputManager.Focus(model, property);
            }

            Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 17
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.UpdateTransactionCompleted += OnUpdateTransactionCompleted;
            proxy.UpdateTransactionAsync(transactionId,
                                         userId,
                                         accountId,
                                         operationDate,
                                         price,
                                         quantity,
                                         comment,
                                         categoryId,
                                         isDeposit
                                         );
        }
Exemplo n.º 18
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void Execute(ResultExecutionContext context)
        {
            var parent = locateParent(context);
            var child  = locateChild(context);

            if (onConfigure != null)
            {
                onConfigure(child);
            }

            EventHandler <ActivationProcessedEventArgs> processed = null;

            processed = (s, e) => {
                parent.ActivationProcessed -= processed;

                if (e.Success)
                {
                    OnOpened(parent, child);

                    var deactivator = child as IDeactivate;
                    if (deactivator != null && onClose != null)
                    {
                        EventHandler <DeactivationEventArgs> handler = null;
                        handler = (s2, e2) => {
                            if (!e2.WasClosed)
                            {
                                return;
                            }

                            deactivator.Deactivated -= handler;
                            onClose(child);
                        };

                        deactivator.Deactivated += handler;
                    }

                    OnCompleted(null, false);
                }
                else
                {
                    OnCompleted(null, true);
                }
            };

            parent.ActivationProcessed += processed;
            parent.ActivateItem(child);
        }
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void Execute(ResultExecutionContext context)
        {
            var factory = context.ServiceLocator.GetInstance <IViewModelFactory>();

            subjectSpecification.CreateSubjectHost(factory, host => {
                if (onConfigure != null)
                {
                    onConfigure(host);
                }

                var deactivator = host as IDeactivate;
                if (deactivator != null)
                {
                    EventHandler <DeactivationEventArgs> handler = null;
                    handler = (s, e) => {
                        deactivator.Deactivated -= handler;

                        if (!e.WasClosed)
                        {
                            return;
                        }

                        if (onClose != null)
                        {
                            onClose(host);
                        }

                        OnCompleted(null, false);
                    };

                    deactivator.Deactivated += handler;
                }

                var windowManager = context.ServiceLocator.GetInstance <IWindowManager>();

#if !SILVERLIGHT
                DialogResult = windowManager.ShowDialog(host, null);
#else
                windowManager.ShowDialog(host, null);
#endif

                if (deactivator == null)
                {
                    OnCompleted(null, false);
                }
            });
        }
Exemplo n.º 20
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void Execute(ResultExecutionContext context)
        {
            var child = locateModal(context);

            if (onConfigure != null)
            {
                onConfigure(child);
            }

            var deactivator = child as IDeactivate;

            if (deactivator != null)
            {
                EventHandler <DeactivationEventArgs> handler = null;
                handler = (s, e) => {
                    if (!e.WasClosed)
                    {
                        return;
                    }

                    deactivator.Deactivated -= handler;

                    if (onClose != null)
                    {
                        onClose(child);
                    }

                    OnCompleted(null, false);
                };

                deactivator.Deactivated += handler;
            }

            var dialogManager = context.ServiceLocator.GetInstance <IWindowManager>();

#if !SILVERLIGHT
            DialogResult = dialogManager.ShowDialog(child, null);
#else
            dialogManager.ShowDialog(child, null);
#endif

            if (deactivator == null)
            {
                OnCompleted(null, false);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(ResultExecutionContext context)
        {
            var windowManager = context.ServiceLocator.GetInstance <IWindowManager>();

            windowManager.ShowMessageBox(Text, Caption, answer => {
                Answer = answer;

                if (answer == Answer.No || answer == Answer.Cancel)
                {
                    Completed(this, new ResultCompletionEventArgs {
                        WasCancelled = true
                    });
                    return;
                }

                Completed(this, new ResultCompletionEventArgs());
            }, possibleAnswers);
        }
Exemplo n.º 22
0
        public void Execute(ResultExecutionContext context)
        {
            var client = new WebClient();

            client.OpenReadCompleted += (s, e) =>
            {
                if (e.Error != null)
                    PresentationFramework.Invocation.Execute.OnUIThread(
                        () => Completed(this, new ResultCompletionEventArgs { Error = e.Error }));
                else
                {
                    Stream = e.Result;
                    PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
                }
            };

            client.OpenReadAsync(_uri);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void Execute(ResultExecutionContext context)
        {
            var parent = locateParent(context);

            parent.ActivateSubject(subjectSpecification, success => {
                if (success)
                {
                    var child = parent
                                .GetChildren()
                                .OfType <IHaveSubject>()
                                .FirstOrDefault(subjectSpecification.Matches);

                    if (onConfigure != null)
                    {
                        onConfigure(child);
                    }

                    OnOpened(parent, child);

                    var deactivator = child as IDeactivate;
                    if (deactivator != null && onClose != null)
                    {
                        EventHandler <DeactivationEventArgs> handler = null;
                        handler = (s2, e2) =>
                        {
                            if (e2.WasClosed)
                            {
                                deactivator.Deactivated -= handler;
                                onClose(child);
                            }
                        };

                        deactivator.Deactivated += handler;
                    }

                    OnCompleted(null, false);
                }
                else
                {
                    OnCompleted(null, true);
                }
            });
        }
Exemplo n.º 24
0
        public void Execute(ResultExecutionContext context)
        {
            FrameworkElement element = null;

            if(context.HandlingNode != null)
                element = context.HandlingNode.UIElement as FrameworkElement;

            if(element == null && context.Message != null)
                element = context.Message.Source.UIElement as FrameworkElement;

            if(element == null)
            {
                Completed(this, new ResultCompletionEventArgs());
                return;
            }

            var storyboard = (Storyboard)element.Resources[_key];

            if(_wait)
                storyboard.Completed += delegate { Completed(this, new ResultCompletionEventArgs()); };

            switch(_action)
            {
                case AnimationAction.Begin:
                    storyboard.Begin();
                    break;
                case AnimationAction.Pause:
                    storyboard.Pause();
                    break;
                case AnimationAction.Resume:
                    storyboard.Resume();
                    break;
                case AnimationAction.Stop:
                    storyboard.Stop();
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            if(!_wait)
                Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 25
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void Execute(ResultExecutionContext context)
        {
            var viewModel = locateModel(context);

            if (onConfigure != null)
            {
                onConfigure(viewModel);
            }

            var deactivator = viewModel as IDeactivate;

            if (deactivator != null && onClose != null)
            {
                EventHandler <DeactivationEventArgs> handler = null;
                handler = (s2, e2) => {
                    if (!e2.WasClosed)
                    {
                        return;
                    }

                    deactivator.Deactivated -= handler;
                    onClose(viewModel);
                };

                deactivator.Deactivated += handler;
            }

            if (settings == null)
            {
                settings = new Dictionary <string, object>();
            }
            if (!settings.ContainsKey("PlacementTarget"))
            {
                settings.Add("PlacementTarget", context.Message.Source.UIElement);
            }

            var windowManager = context.ServiceLocator.GetInstance <IWindowManager>();

            windowManager.ShowPopup(viewModel, null, settings);

            OnCompleted(null, false);
        }
Exemplo n.º 26
0
        public void Execute(ResultExecutionContext context)
        {
            //just demonstrating the power of a custom IExecutableResult

            var source = (FrameworkElement)context.Message.Source.UIElement;
            var popup = source.FindName("dirtyPopup") as Popup;

            var itemsControl = (ItemsControl)popup.FindName("messageHost");
            itemsControl.ItemsSource = _results;

            var visualOffset = source.TransformToVisual(Application.Current.RootVisual).Transform(new Point(0, 0));
            var popupOffset = popup.TransformToVisual(Application.Current.RootVisual).Transform(new Point(0, 0));

            popup.HorizontalOffset = (visualOffset.X - popupOffset.X) / 2;
            popup.IsOpen = true;
            popup.CaptureMouse();

            popup.Child.MouseLeave += delegate { popup.IsOpen = false; };

            Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 27
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.GetAllAccountsCompleted += (s, e) =>
            {
                if (e.Error != null)
                {
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(
                        () => Completed(this, new ResultCompletionEventArgs {
                        Error = e.Error
                    }));
                }
                else
                {
                    Accounts = e.Result;
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
                }
            };

            proxy.GetAllAccountsAsync(userId: userId);
        }
Exemplo n.º 28
0
        public void Execute(ResultExecutionContext context)
        {
            var view = context.HandlingNode.UIElement as FrameworkElement;

            while (view != null)
            {
                var busyIndicator = view as BusyIndicator;
                if (busyIndicator != null)
                {
                    if (!string.IsNullOrEmpty(message))
                    {
                        busyIndicator.BusyContent = message;
                    }
                    busyIndicator.IsBusy = !hide;
                    break;
                }

                view = view.Parent as FrameworkElement;
            }

            Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 29
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(ResultExecutionContext context)
        {
            object sourceViewModel = null;

            if (context.HandlingNode != null)
            {
                sourceViewModel = context.HandlingNode.MessageHandler.Unwrap();
            }

            var busyService = context.ServiceLocator.GetInstance <IBusyService>();

            if (isBusy)
            {
                busyService.MarkAsBusy(sourceViewModel, busyViewModel);
            }
            else
            {
                busyService.MarkAsNotBusy(sourceViewModel);
            }

            Completed(this, new ResultCompletionEventArgs());
        }
Exemplo n.º 30
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.GetTransactionCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(
                        () => Completed(this, new ResultCompletionEventArgs {
                        Error = args.Error
                    }));
                }
                else
                {
                    Transaction = args.Result;
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
                }
            };
            proxy.GetTransactionAsync(userId,
                                      accountId,
                                      transactionId);
        }
Exemplo n.º 31
0
 public void Execute(ResultExecutionContext context)
 {
     Backend.Send(command);
     Completed(this, new ResultCompletionEventArgs());
 }
Exemplo n.º 32
0
 /// <summary>
 /// Executes the result using the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public abstract void Execute(ResultExecutionContext context);