public async void Execute(CoroutineExecutionContext context)
        {
            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "OK",
                AnimateShow           = true,
                AnimateHide           = false
            };
            IDialogCoordinator coordinator = IoC.Get <IDialogCoordinator>();

            DialogContent.CloseButton.Click += async(s, e) =>
            {
                Result = (T)DialogContent.Combo.SelectedItem;
                await coordinator.HideMetroDialogAsync(context.Target, DialogContent);

                var args = new ResultCompletionEventArgs()
                {
                    WasCancelled = Result == null
                };
                this.Completed(this, args);
            };

            DialogContent.Title = Title;

            await coordinator.ShowMetroDialogAsync(context.Target, DialogContent);
        }
        protected override bool HandleException(CoroutineExecutionContext context, Exception ex)
        {
            var method = context.Target.GetType().GetMethod(this.MethodName, new[] { typeof(Exception) });

            if (method == null)
            {
                return(false);
            }

            try
            {
                var result = method.Invoke(context.Target, new object[] { ex });
                if (result is bool)
                {
                    return((bool)result);
                }
                else
                {
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
        public void Execute(CoroutineExecutionContext 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.Instance.Contains(assembly))
                        .Apply(x => AssemblySource.Instance.Add(x));
                    }
                    else
                    {
                        Loader.Hide().Execute(context);
                    }

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

                catalog.DownloadAsync();
            }
        }
        void IResult.Execute(CoroutineExecutionContext context)
        {
            if (!this.CanExecute(context))
            {
                this._completedEvent.Invoke(this, new ResultCompletionEventArgs {
                    WasCancelled = true
                });
                return;
            }

            try
            {
                EventHandler <ResultCompletionEventArgs> onCompletion = null;
                onCompletion = (o, e) =>
                {
                    this._inner.Completed -= onCompletion;
                    this.AfterExecute(context);
                    this.FinalizeExecution(context, e.WasCancelled, e.Error);
                };
                this._inner.Completed += onCompletion;

                this.BeforeExecute(context);
                this.Execute(this._inner, context);
            }
            catch (Exception ex)
            {
                this.FinalizeExecution(context, false, ex);
            }
        }
        protected override bool HandleException(CoroutineExecutionContext context, Exception ex)
        {
            var method = context.Target.GetType().GetMethod(this.MethodName, new[] { typeof(Exception) });
            if (method == null)
            {
                return false;
            }

            try
            {
                var result = method.Invoke(context.Target, new object[] { ex });
                if (result is bool)
                {
                    return (bool)result;
                }
                else
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }
 public void Execute(CoroutineExecutionContext context)
 {
     Backend.Send(query, response => {
         Response = response;
         Caliburn.Micro.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
     });
 }
        public override void Execute(CoroutineExecutionContext context)
        {
            var window = _windowLocator();

            if (_setData != null)
            {
                _setData(window);
            }

            if (_onConfigure != null)
            {
                _onConfigure(window);
            }

            window.Deactivated += (s, e) =>
            {
                if (e.WasClosed)
                {
                    if (_onShutDown != null)
                    {
                        _onShutDown(window);
                    }

                    OnCompleted(null, false);
                }

                return(System.Threading.Tasks.Task.CompletedTask);
            };

            WindowManager.ShowWindowAsync(window);
        }
        public void Execute(CoroutineExecutionContext context) {
            var documentWorkspace = screen.Parent as IDocumentWorkspace;
            if (documentWorkspace != null)
                documentWorkspace.Edit(screen);

            closeCheck(Shell.Dialogs, result => Completed(this, new ResultCompletionEventArgs { WasCancelled = !result }));
        }
Exemple #9
0
        public override void Execute(CoroutineExecutionContext context)
        {
            var tool = _toolLocator();

            if (_setData != null)
            {
                _setData(tool);
            }

            if (_onConfigure != null)
            {
                _onConfigure(tool);
            }

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

                if (_onShutDown != null)
                {
                    _onShutDown(tool);
                }

                OnCompleted(null, false);
            };

            _shell.ShowTool(tool);
        }
Exemple #10
0
        /// <summary>
        /// Resets the fields and create the new fields
        /// </summary>
        public void Execute(CoroutineExecutionContext context)
        {
            _playfield.Fields = new List <Field>();
            _playfield.Ships  = new List <Ship>();

            int rows    = _option.Rows;
            int columns = _option.Columns;

            List <Field> newFields = new List <Field>();

            for (int row = 0; row < rows; row++)
            {
                for (int column = 0; column < columns; column++)
                {
                    newFields.Add(new Field(_playfield)
                    {
                        YCoordinate = row,
                        XCoordinate = column,
                        Status      = FieldStatus.Unassigned
                    });
                }
            }

            _playfield.Fields = newFields;
            Completed(this, new ResultCompletionEventArgs());
        }
Exemple #11
0
        public static ResultCompletionEventArgs ExecuteAndWait(this IResult action, CoroutineExecutionContext context,
                                                               System.Action executeAfterActionStarted = null)
        {
            ResultCompletionEventArgs retVal = null;
            var handle = new System.Threading.ManualResetEventSlim(false);

            action.Completed += (sender, args) =>
            {
                if (args == null)
                {
                    throw new Exception("Args = null");
                }
                retVal = args;
                handle.Set();
            };
            action.Execute(context);
            if (executeAfterActionStarted != null)
            {
                executeAfterActionStarted();
            }
            handle.Wait();

            if (retVal == null)
            {
                throw new Exception("Completed not triggered");
            }
            return(retVal);
        }
Exemple #12
0
        public override async void Execute(CoroutineExecutionContext context)
        {
            var window = _windowLocator();

            if (_setData != null)
            {
                _setData(window);
            }

            if (_onConfigure != null)
            {
                _onConfigure(window);
            }

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

                if (_onShutDown != null)
                {
                    _onShutDown(window);
                }

                OnCompleted(null, false);
            };

            await WindowManager.ShowWindowAsync(window);
        }
Exemple #13
0
        public void Execute(CoroutineExecutionContext context)
        {
            var screen = IoC.Get <T>();

            initialization.Invoke(screen);

            Dialog = screen;
            WindowManager.ShowDialog(screen);

            var deactivated = screen as IDeactivate;

            if (deactivated == null)
            {
                Completed(this, new ResultCompletionEventArgs());
            }
            else
            {
                deactivated.Deactivated += (o, e) => {
                    if (e.WasClosed)
                    {
                        Completed(this, new ResultCompletionEventArgs());
                    }
                };
            }
        }
Exemple #14
0
        public void Execute(CoroutineExecutionContext context)
        {
            Exception error  = null;
            var       worker = new BackgroundWorker();

            worker.DoWork += (s, e) =>
            {
                try
                {
                    _work();
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            };

            worker.RunWorkerCompleted += (s, e) =>
            {
                if (error == null && _onSuccess != null)
                {
                    _onSuccess.OnUIThread();
                }

                if (error != null && _onFail != null)
                {
                    Caliburn.Micro.Execute.OnUIThread(() => _onFail(error));
                }

                Completed(this, new ResultCompletionEventArgs {
                    Error = error
                });
            };
            worker.RunWorkerAsync();
        }
Exemple #15
0
        /// <summary>
        /// Executes this action.
        /// </summary>
        /// <param name="context">The execution context</param>
        public async void Execute(CoroutineExecutionContext context)
        {
            //var result = MessageBox.Show(
            //    this.Question,
            //    this.Title,
            //    this.AllowCancel ? MessageBoxButton.YesNoCancel : MessageBoxButton.YesNo,
            //    MessageBoxImage.Question,
            //    MessageBoxResult.Yes);

            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText    = "Save and Close",
                NegativeButtonText       = "Cancel",
                FirstAuxiliaryButtonText = "Close Window Without Saving",
                AnimateShow = true,
                AnimateHide = false
            };
            IDialogCoordinator coordinator = IoC.Get <IDialogCoordinator>();
            var result = await coordinator.ShowMessageAsync(context.Target, this.Title,
                                                            this.Question,
                                                            MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings);

            this.Result = result == MessageDialogResult.Affirmative;
            var args = new ResultCompletionEventArgs()
            {
                WasCancelled = result == MessageDialogResult.Negative,
            };

            this.Completed(this, args);
        }
        public void Execute(CoroutineExecutionContext 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.Instance.Contains(assembly))
                            .Apply(x => AssemblySource.Instance.Add(x));
                    }
                    else Loader.Hide().Execute(context);

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

                catalog.DownloadAsync();
            }
        }
        void IResult.Execute(CoroutineExecutionContext context)
        {
            if (!this.CanExecute(context))
            {
                this._completedEvent.Invoke(this, new ResultCompletionEventArgs { WasCancelled = true });
                return;
            }

            try
            {
                EventHandler<ResultCompletionEventArgs> onCompletion = null;
                onCompletion = (o, e) =>
                    {
                        this._inner.Completed -= onCompletion;
                        this.AfterExecute(context);
                        this.FinalizeExecution(context, e.WasCancelled, e.Error);
                    };
                this._inner.Completed += onCompletion;

                this.BeforeExecute(context);
                this.Execute(this._inner, context);
            }
            catch (Exception ex)
            {
                this.FinalizeExecution(context, false, ex);
            }
        }
        public async override void Execute(CoroutineExecutionContext context)
        {
            var dialog = new MessageDialog(_content, _title);

            await dialog.ShowAsync();

            OnCompleted();
        }
Exemple #19
0
        public void Execute(CoroutineExecutionContext context)
        {
            MainViewModel targetViewModel = context.Target as MainViewModel;

            targetViewModel.StatusText = String.Concat(targetViewModel.LoadedData.Length, " bytes loaded");

            Completed(this, new ResultCompletionEventArgs());
        }
 /// <summary>
 /// Executes the result using the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Execute(CoroutineExecutionContext context)
 {
     Result = MessageBox.Show(Text, Caption, Button, Image);
     if (Completed != null)
     {
         Completed(this, new ResultCompletionEventArgs());
     }
 }
Exemple #21
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(CoroutineExecutionContext context)
        {
            var messageService = (IMessageService)IoC.GetAllInstances(typeof(IMessageService)).FirstOrDefault() ??
                                 new MessageService();

            Result = messageService.Show(message, caption, button, image);
            Completed(this, new ResultCompletionEventArgs());
        }
        public override void Execute(CoroutineExecutionContext context)
        {
            var window = Window.GetWindow(context.View as DependencyObject);

            window.Close();

            base.Execute(context);
        }
        public void Execute(CoroutineExecutionContext context)
        {
            var result = _commonDialog.ShowDialog().GetValueOrDefault(false);

            Completed(this, new ResultCompletionEventArgs {
                WasCancelled = !result
            });
        }
        public async override void Execute(CoroutineExecutionContext context)
        {
            var dialog = new MessageDialog(_content, _title);

            await dialog.ShowAsync();

            OnCompleted();
        }
Exemple #25
0
        public override async void Execute(CoroutineExecutionContext context)
        {
            //var dialog = new MessageDialog(content, title);

            //await dialog.ShowAsync();

            OnCompleted();
        }
Exemple #26
0
        private async Task Initialize()
        {
            //Initialize only once
            if (this._isInitialized)
            {
                return;
            }

            this._isInitialized = true;

            //Caliburn Micro Setup
            PlatformProvider.Current = new UwCorePlatformProvider();
            EventAggregator.HandlerResultProcessing = (target, result) =>
            {
                var task = result as Task;
                if (task != null)
                {
                    result = new IResult[] { task.AsResult() };
                }

                var coroutine = result as IEnumerable <IResult>;
                if (coroutine != null)
                {
                    var viewAware = target as IViewAware;
                    var view      = viewAware?.GetView();

                    var context = new CoroutineExecutionContext
                    {
                        Target = target,
                        View   = view
                    };

                    Coroutine.BeginExecute(coroutine.GetEnumerator(), context);
                }
            };

            AssemblySource.Assemblies.AddRange(this.SelectAssemblies());

            //Attach to application events
            this.Resuming           += this.OnResuming;
            this.Suspending         += this.OnSuspending;
            this.UnhandledException += this.OnUnhandledException;

            //Configure
            this.ConfigureContainer();
            this.ConfigureLogging();
            this.Configure();

            //Setup IoC
            IoC.GetInstance = (service, key) => this._container.IsRegistered(service)
                ? this._container.Resolve(service)
                : Activator.CreateInstance(service);
            IoC.GetAllInstances = service => ((IEnumerable)this._container.Resolve(typeof(IEnumerable <>).MakeGenericType(service))).OfType <object>();
            IoC.BuildUp         = instance => this._container.InjectUnsetProperties(instance);

            //Restore state
            await this._container.Resolve <IApplicationStateService>().RestoreStateAsync();
        }
        public void Execute(CoroutineExecutionContext context)
        {
            var screen = !string.IsNullOrEmpty(name)
                ? IoC.Get <object>(name)
                : IoC.GetInstance(screenType, null);

            Shell.ActivateItem(screen);
            Completed(this, new ResultCompletionEventArgs());
        }
Exemple #28
0
        public void Execute(CoroutineExecutionContext context)
        {
            gameTimer = new Timer(GAME_TIME_LIMIT);

            gameTimer.Elapsed += timerOnElapsed(context);
            gameTimer.Start();

            _windowManager.ShowDialog(this);
        }
Exemple #29
0
        public void Execute(CoroutineExecutionContext context)
        {
            var args = new ResultCompletionEventArgs()
            {
                WasCancelled = false
            };

            this.Completed(this, args);
        }
Exemple #30
0
        /// <summary>
        /// Gets the current playfield view and try to save it as png
        /// </summary>
        public void Execute(CoroutineExecutionContext context)
        {
            RenderTargetBitmap rtb  = GetRenderedPlayfield((UserControl)_playfieldViewModel.GetView());
            string             path = GetNewFileDirectory();

            SaveImage(path, rtb);

            Completed(this, new ResultCompletionEventArgs());
        }
Exemple #31
0
 /// <summary>
 /// Executes this action.
 /// </summary>
 /// <param name="context">The execution context.</param>
 public void Execute(CoroutineExecutionContext context)
 {
     this.Completed(
         this,
         new ResultCompletionEventArgs()
     {
         Error = this.Error
     });
 }
        public async void Execute(CoroutineExecutionContext context)
        {
            var numberOfPrimes = CountAllPrimeNumbersAsync();

            _windowManager.ShowDialog(this);

            ((ShellViewModel)context.Target).Result = (await numberOfPrimes).ToString();

            Completed(this, new ResultCompletionEventArgs());
        }
Exemple #33
0
        public override void Execute(CoroutineExecutionContext context)
        {
            MetroDialogSettings mds = new MetroDialogSettings()
            {
                AnimateShow = false, AnimateHide = false
            };

            this.dialogCoordinator.ShowMessageAsync(context.Target, title, content, MessageDialogStyle.Affirmative, mds);
            OnCancelled();
        }
Exemple #34
0
        public override void Execute(CoroutineExecutionContext context)
        {
            if (configure != null)
            {
                configure(model);
            }

            windowManager.ShowDialog(model);

            base.Execute(context);
        }
        public override void Execute(CoroutineExecutionContext context)
        {
            if (!(context.View is Control))
                throw new InvalidOperationException("View must be a Control to use VisualStateResult");

            var view = (Control)context.View;

            VisualStateManager.GoToState(view, StateName, UseTransitions);

            OnCompleted();
        }
        public override async void Execute(CoroutineExecutionContext context)
        {
            //var dialog = new MessageDialog(content, title);

            //await dialog.ShowAsync();

            MessageBox.Show(content, title, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK,
                            MessageBoxOptions.None);

            OnCompleted();
        }
        public void Execute(CoroutineExecutionContext context)
        {
            var view = context.View 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());
        }
 /// <summary>
 /// Called when an exception was thrown during the action execution
 /// </summary>
 protected virtual bool HandleException(CoroutineExecutionContext context, Exception ex)
 {
     return false;
 }
 /// <summary>
 /// Check prerequisites
 /// </summary>
 protected virtual bool CanExecute(CoroutineExecutionContext context)
 {
     return true;
 }
Exemple #40
0
 public abstract void Execute(CoroutineExecutionContext context);
 protected override bool HandleException(CoroutineExecutionContext context, Exception ex)
 {
     this.SetBusy(context.Target as ICanBeBusy, false);
     return false;
 }
 /// <summary>
 /// Called just before execution (if prerequisites are met)
 /// </summary>
 protected virtual void BeforeExecute(CoroutineExecutionContext context)
 {
 }
 /// <summary>
 /// Allows to customize the dispatch of the execution
 /// </summary>
 protected virtual void Execute(IResult inner, CoroutineExecutionContext context)
 {
     inner.Execute(context);
 }
 /// <summary>
 /// Called after execution (if prerequisites are met)
 /// </summary>
 protected virtual void AfterExecute(CoroutineExecutionContext context)
 {
 }
 /// <summary>
 /// Called when the execution of the decorated CoTask has completed.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="innerCoTask">The decorated CoTask.</param>
 /// <param name="args">The <see cref="Caliburn.Light.CoTaskCompletedEventArgs" /> instance containing the event data.</param>
 protected override void OnInnerResultCompleted(CoroutineExecutionContext context, ICoTask innerCoTask,
     CoTaskCompletedEventArgs args)
 {
     OnCompleted(new CoTaskCompletedEventArgs(args.Error, false));
 }
        public override async void Execute(CoroutineExecutionContext context)
        {
            await Task.Delay(_milliseconds);

            OnCompleted();
        }
 protected override void AfterExecute(CoroutineExecutionContext context)
 {
     this.SetBusy(context.Target as ICanBeBusy, false);
 }
 protected override void BeforeExecute(CoroutineExecutionContext context)
 {
     this.SetBusy(context.Target as ICanBeBusy, true);
 }
        private void FinalizeExecution(CoroutineExecutionContext context, bool wasCancelled, Exception ex)
        {
            if (ex != null && this.HandleException(context, ex))
            {
                ex = null;
            }

            this._completedEvent.Invoke(this, new ResultCompletionEventArgs { WasCancelled = wasCancelled, Error = ex });
        }
 protected override bool CanExecute(CoroutineExecutionContext context)
 {
     return false;
 }
 protected override void Execute(IResult inner, CoroutineExecutionContext context)
 {
     ThreadPool.QueueUserWorkItem(state => { inner.Execute(context); });
 }
        /// <summary>
        /// Called when the execution of the decorated result has completed.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="innerResult">The decorated result.</param>
        /// <param name="args">The <see cref="ResultCompletionEventArgs" /> instance containing the event data.</param>
        protected override void OnInnerResultCompleted(CoroutineExecutionContext context, IResult innerResult, ResultCompletionEventArgs args) {
            if (args.WasCancelled)
                Log.Info(string.Format("Overriding WasCancelled from {0}.", innerResult.GetType().Name));

            OnCompleted(new ResultCompletionEventArgs { Error = args.Error });
        }