Exemple #1
0
 public override void Execute(CoroutineExecutionContext context)
 {
     var window = Window.GetWindow(context.View as DependencyObject);
     window.Close();
     
     base.Execute(context);
 }
        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();
        }
        public async void Execute(CoroutineExecutionContext context)
        {
            await this.ProgressViewModel.ShowProgress();

            await Task.Run(() =>
            {
                var hashes = hashRepository.GetMurMurs();
                var dirs = hashes.GroupBy(x => Path.GetDirectoryName(x.Key).ToLower())
                    .Select(x => new { Dir = x.Key, Files = x.Select(f => f.Value).ToList() })
                    .ToList()
                    .AsParallel();

                CopyDirectories = dirs.SelectMany((x, i) => dirs.Skip(i + 1).Select(y => new DirectoryCopyResultModel
                {
                    Directory1 = x.Dir,
                    Directory2 = y.Dir,
                    Directory1Files = x.Files.Count,
                    Directory2Files = y.Files.Count,
                    CopyCount = Math.Max(x.Files.Count, y.Files.Count) - DiffCount(x.Files, y.Files)
                }))
                .Where(x => x.CopyCount > 0 && x.CopyPercentage >= 0.5)
                .OrderByDescending(x => x.CopyPercentage)
                .ThenByDescending(x => x.Directory1Files)
                .ToList();
            });

            await this.ProgressViewModel.CloseProgress();

            Completed(this, new ResultCompletionEventArgs());
        }
        /// <summary>
        /// Called by the bootstrapper's constructor at runtime to start the framework.
        /// </summary>B
        protected virtual void StartRuntime()
        {
            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 != null ? viewAware.GetView() : null;
                    var context = new CoroutineExecutionContext { Target = target, View = view };

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

            AssemblySourceCache.Install();
            AssemblySource.Instance.AddRange(SelectAssemblies());

            Configure();

            IoC.GetInstance = GetInstance;
            IoC.GetAllInstances = GetAllInstances;
            IoC.BuildUp = BuildUp;
        }
 public static void ExecuteSynchronized(this IResult result, CoroutineExecutionContext executionContext = null)
 {
     IoC.BuildUp(result);
     var reset = new ManualResetEvent(false);
     result.Completed+= (s,e)=>reset.Set();
     result.Execute(executionContext);
     reset.WaitOne();
 }
 public override void Execute(CoroutineExecutionContext context)
 {
     if(Workspace != null && Workspace.ReplExecutor != null)
     {
         Workspace.ReplExecutor.Execute(code, sourceFile);
         OnCompleted(null);
     }
 }
Exemple #7
0
        public void Execute(CoroutineExecutionContext context)
        {
            _lambda(context);

            var completedHandler = Completed;
            if (completedHandler != null)
                completedHandler(this, new ResultCompletionEventArgs());
        }
 /// <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.Error != null || !args.WasCancelled) {
         OnCompleted(new ResultCompletionEventArgs {Error = args.Error});
     }
     else {
         Log.Info(string.Format("Executing coroutine because {0} was cancelled.", innerResult.GetType().Name));
         Continue(context);
     }
 }
 public void Execute(CoroutineExecutionContext context)
 {
     var dialog = new FolderBrowserDialog();
     if(!String.IsNullOrEmpty(SelectedFolder))
         dialog.SelectedPath = SelectedFolder;
     var result = dialog.ShowDialog();
     SelectedFolder = dialog.SelectedPath;
     Completed(this, new ResultCompletionEventArgs { WasCancelled = result != DialogResult.OK });
 }
Exemple #10
0
 /// <summary>
 /// Executes the result using the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Execute(CoroutineExecutionContext context) {
     if (innerTask.IsCompleted)
         OnCompleted(innerTask);
     else
         innerTask.ContinueWith(OnCompleted,
             System.Threading.SynchronizationContext.Current != null
                 ? TaskScheduler.FromCurrentSynchronizationContext()
                 : TaskScheduler.Current);
 }
 public override void Execute(CoroutineExecutionContext context)
 {
     var windowManager = IoC.Get<IWindowManager>();
     if(dialogViewModel == null)
     {
         dialogViewModel = IoC.GetInstance(dialogViewModelType, null);
     }
     var result = windowManager.ShowDialog(dialogViewModel, settings:Settings);
     OnCompleted(null, result.HasValue && !result.Value);
 }
Exemple #12
0
            public void Execute(CoroutineExecutionContext context)
            {
                var result = System.Windows.MessageBoxResult.Yes;

                if (Settings.Default.ConfirmExit)
                {
                    result = MessageBox.Show("Are you sure you want to exit?", "Confirm", MessageBoxButton.YesNo);
                }

                Completed(this, new ResultCompletionEventArgs { WasCancelled = (result != System.Windows.MessageBoxResult.Yes) });
            }
 public override void Execute(CoroutineExecutionContext context)
 {
     try
     {
         Caliburn.Micro.Execute.OnUIThread(() => Application.Current.MainWindow.Close());
     }
     catch (Exception ex)
     {
         OnCompleted(ex);
     }
 }
Exemple #14
0
        public override void Execute(CoroutineExecutionContext context)
        {
            var dialog = Mode == FileDialogMode.Open ? new OpenFileDialog() as FileDialog : new SaveFileDialog();
            dialog.FileName = fileName;
            dialog.Title = title;
            dialog.Filter = filter;

            dialog.ShowDialog();
            File = dialog.FileName;

            base.Execute(context);
        }
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(CoroutineExecutionContext context) {
            this.context = context;

            try {
                innerResult.Completed += InnerResultCompleted;
                IoC.BuildUp(innerResult);
                innerResult.Execute(this.context);
            }
            catch (Exception ex) {
                InnerResultCompleted(innerResult, new ResultCompletionEventArgs { Error = ex });
            }
        }
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(CoroutineExecutionContext context) {
            var eventArgs = new ResultCompletionEventArgs();

            try {
                toExecute();
            }
            catch (Exception ex) {
                eventArgs.Error = ex;
            }

            Completed(this, eventArgs);
        }
Exemple #17
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 for the coroutine.</param>
        public static void BeginExecute(IEnumerator<IResult> coroutine, CoroutineExecutionContext context = null, EventHandler<ResultCompletionEventArgs> callback = null) {
            Log.Info("Executing coroutine.");

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

            if (callback != null) {
                ExecuteOnCompleted(enumerator, callback);
            }

            ExecuteOnCompleted(enumerator, Completed);
            enumerator.Execute(context ?? new CoroutineExecutionContext());
        }
 public override void Execute(CoroutineExecutionContext context)
 {
     try
     {
         //some of this is synchronous which can mess up the UI (especially on startup), so we execute it on a seperate thread
         Task.Factory.StartNew(() => workspace.SetWorkspaceDirectory(workspaceDirectory))
             .ContinueWith(t2 => OnCompleted(t2.Exception));
     }
     catch (Exception ex)
     {
         OnCompleted(ex);
     }
 }
        public void Execute(CoroutineExecutionContext context)
        {
            if (_templatesDirectory.Exists)
            {
                ZipFile.CreateFromDirectory(_templatesDirectory.FullName,
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                        string.Format("templates-{0}.zip", DateTime.Now.ToFileTime())),
                    CompressionLevel.Optimal,
                    true);
            }

            Completed(this, new ResultCompletionEventArgs());
        }
Exemple #20
0
        /// <summary>
        /// Executes a coroutine asynchronous.
        /// </summary>
        /// <param name="coroutine">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(IEnumerator<IResult> coroutine, CoroutineExecutionContext context = null) {
            var taskSource = new TaskCompletionSource<object>();

            BeginExecute(coroutine, context, (s, e) => {
                if (e.Error != null)
                    taskSource.SetException(e.Error);
                else if (e.WasCancelled)
                    taskSource.SetCanceled();
                else
                    taskSource.SetResult(null);
            });

            return taskSource.Task;
        }
            public async void Execute(CoroutineExecutionContext context)
            {
                var result = System.Windows.MessageBoxResult.Yes;
                var connectionHandler = IoC.Get<IConnectionHandler>();

                if (Settings.Default.Connection_ConfirmOnCloseConnected && connectionHandler.ConnectionRequestState == ConnectionRequestState.Start)
                {
                    result = MessageBox.Show("You are connected, you want to exit?", "Confirm", MessageBoxButton.YesNo);
                    if (result == System.Windows.MessageBoxResult.Yes)
                        await connectionHandler.StopSession();
                }

                if (Completed != null)
                    Completed(this, new ResultCompletionEventArgs { WasCancelled = (result != System.Windows.MessageBoxResult.Yes) });
            }
Exemple #22
0
 /// <summary>
 ///   Extension method to convert an IResult to <see cref="Task" />
 /// </summary>
 /// <param name="source"> The IResult to be converted. </param>
 /// <param name="context"> Optional execution context. </param>
 public static Task AsTask(this IResult source, CoroutineExecutionContext context = null)
 {
     var tcs = new TaskCompletionSource<bool>();
     source.Completed += (sender, args) =>
                             {
                                 if (args.WasCancelled)
                                     tcs.SetCanceled();
                                 else if (args.Error != null)
                                     tcs.SetException(args.Error);
                                 else
                                     tcs.SetResult(true);
                             };
     source.Execute(context);
     return tcs.Task;
 }
        public void Execute(CoroutineExecutionContext context)
        {
            if (_templatesDirectory.Parent != null)
            {
                using (ZipArchive archive = ZipFile.OpenRead(_importFile))
                {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        entry.ExtractToFile(Path.Combine(_templatesDirectory.FullName, entry.Name), true);
                    }
                }

            }

            Completed(this, new ResultCompletionEventArgs());
        }
        void Continue(CoroutineExecutionContext context) {
            IResult continueResult;
            try {
                continueResult = coroutine();
            }
            catch (Exception ex) {
                OnCompleted(new ResultCompletionEventArgs {Error = ex});
                return;
            }

            try {
                continueResult.Completed += ContinueCompleted;
                IoC.BuildUp(continueResult);
                continueResult.Execute(context);
            }
            catch (Exception ex) {
                ContinueCompleted(continueResult, new ResultCompletionEventArgs {Error = ex});
            }
        }
 public override void Execute(CoroutineExecutionContext context)
 {
     Exception ex = null;
     try
     {
         if (!String.IsNullOrEmpty(newFile))
         {
             document.SaveAs(newFile);
         }
         else if (document.IsDirty)
         {
             document.Save();
         }
     }
     catch(Exception e)
     {
         ex = e;
     }
     OnCompleted(ex);
 }
        /// <summary>
        /// Executes a coroutine asynchronous.
        /// </summary>
        /// <param name="coroutine">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(IEnumerator <IResult> coroutine, CoroutineExecutionContext context = null)
        {
            var taskSource = new TaskCompletionSource <object>();

            BeginExecute(coroutine, context, (s, e) => {
                if (e.Error != null)
                {
                    taskSource.SetException(e.Error);
                }
                else if (e.WasCancelled)
                {
                    taskSource.SetCanceled();
                }
                else
                {
                    taskSource.SetResult(null);
                }
            });

            return(taskSource.Task);
        }
        public void Execute(CoroutineExecutionContext context) {
            var view = context.View as FrameworkElement;

            //bottom up search
            while(view != null) {
                var indicator = view as BusyIndicator;
                if(indicator != null) {
                    indicator.IsBusy = !hide;
                    break;
                }
                view = view.Parent as FrameworkElement;
            }

            //top down search
            if(view == null) {
                var queue = new Queue<FrameworkElement>();
                queue.Enqueue(App.Current.RootVisual as FrameworkElement);

                while(queue.Count > 0) {
                    var current = queue.Dequeue();
                    if(current == null)
                        continue;

                    var indicator = current as BusyIndicator;
                    if(indicator != null) {
                        indicator.IsBusy = !hide;
                        break;
                    }

                    var count = VisualTreeHelper.GetChildrenCount(current);
                    for(var i = 0; i < count; i++) {
                        queue.Enqueue(VisualTreeHelper.GetChild(current, i) as FrameworkElement);
                    }
                }
            }

            Completed(this, new ResultCompletionEventArgs());
        }
        public void Execute(CoroutineExecutionContext context)
        {
            var path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(InstallContextAction)).Location);
            var psi = new ProcessStartInfo();
            psi.FileName = Path.Combine(path, "SlavApp.Minion.ElevatedRunner.exe");
            psi.Verb = "runas";
            if (Settings["context"] == "1")
            {
                psi.Arguments = "context uninstall";
                Settings["context"] = "0";
            }
            else
            {
                psi.Arguments = "context install";
                Settings["context"] = "1";
            }

            var process = new Process();
            process.StartInfo = psi;
            process.Start();
            process.WaitForExit();
            Settings.Save();
            Completed(this, new ResultCompletionEventArgs());
        }
Exemple #29
0
 /// <summary>
 ///   Executes the result using the specified context.
 /// </summary>
 /// <param name = "context">The context.</param>
 public void Execute(CoroutineExecutionContext context)
 {
     this.context = context;
     ChildCompleted(null, new ResultCompletionEventArgs());
 }
 public static void BeginExecute(this IResult result, CoroutineExecutionContext executionContext = null)
 {
     IEnumerable<IResult> results = new[] {result};
     results.BeginExecute(executionContext);
 }
 public static void BeginExecute(this IEnumerable<IResult> results, CoroutineExecutionContext executionContext = null)
 {
     Coroutine.BeginExecute(results.GetEnumerator(), executionContext);
 }
Exemple #32
0
 public void Execute(CoroutineExecutionContext context)
 {
     var view = (FrameworkElement)context.View;
     var storyboard = (Storyboard)view.Resources["AddCreditsStoryboard"];
     storyboard.Begin();
 }