/// <summary> /// Executes the result using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { var openFileDialog = new OpenFileDialog(); openFileDialog.RestoreDirectory = true; openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; openFileDialog.Multiselect = _multiselect; openFileDialog.Filter = _fileTypeFilter; openFileDialog.Title = _title; openFileDialog.InitialDirectory = _initialDirectory; var activeWindow = CoTaskHelper.GetActiveWindow(context); bool fileSelected; try { fileSelected = openFileDialog.ShowDialog(activeWindow).GetValueOrDefault(); } catch { if (string.IsNullOrEmpty(openFileDialog.InitialDirectory)) { throw; } openFileDialog.InitialDirectory = null; fileSelected = openFileDialog.ShowDialog(activeWindow).GetValueOrDefault(); } OnCompleted(openFileDialog, new CoTaskCompletedEventArgs(null, !fileSelected)); }
/// <summary> /// Resolves the value of this instance. /// </summary> /// <param name="context">The context.</param> /// <returns>The resolved value.</returns> public object Resolve(CoroutineExecutionContext context) { var sourceOverride = SourceOverride; if (sourceOverride != null) context.Source = sourceOverride; return context; }
/// <summary> /// Executes the coTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override async void BeginExecute(CoroutineExecutionContext context) { try { await _innerTask; } // ReSharper disable once EmptyGeneralCatchClause catch { } OnCompleted(_innerTask); }
/// <summary> /// Executes the coTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override async void BeginExecute(CoroutineExecutionContext context) { try { await _innerTask; } // ReSharper disable once EmptyGeneralCatchClause catch { } OnCompleted(_innerTask); }
/// <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="CoTaskCompletedEventArgs" /> instance containing the event data.</param> protected override void OnInnerResultCompleted(CoroutineExecutionContext context, ICoTask innerCoTask, CoTaskCompletedEventArgs args) { if (args.Error != null || !args.WasCancelled) { OnCompleted(new CoTaskCompletedEventArgs(args.Error, false)); } else { Continue(context); } }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { _context = context; try { _innerCoTask.Completed += InnerCoTaskCompleted; _innerCoTask.BeginExecute(_context); } catch (Exception ex) { InnerCoTaskCompleted(_innerCoTask, new CoTaskCompletedEventArgs(ex, false)); } }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { _context = context; try { _innerCoTask.Completed += InnerCoTaskCompleted; _innerCoTask.BeginExecute(_context); } catch (Exception ex) { InnerCoTaskCompleted(_innerCoTask, new CoTaskCompletedEventArgs(ex, false)); } }
/// <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) { var error = args.Error as TException; if (error == null) { OnCompleted(args); } else { Rescue(context, error); } }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { Exception error = null; try { _toExecute(); } catch (Exception ex) { error = ex; } OnCompleted(new CoTaskCompletedEventArgs(error, false)); }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { Exception error = null; try { _toExecute(); } catch (Exception ex) { error = ex; } OnCompleted(new CoTaskCompletedEventArgs(error, false)); }
/// <summary> /// Executes the result using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { var activeWindow = CoTaskHelper.GetActiveWindow(context); if (activeWindow != null) { Result = MessageBox.Show(activeWindow, _message, _caption, _button, _image); } else { Result = MessageBox.Show(_message, _caption, _button, _image); } OnCompleted(new CoTaskCompletedEventArgs(null, false)); }
private object[] DetermineParameters(MethodBase method, object eventArgs = null) { var requiredParameters = method.GetParameters(); if (requiredParameters.Length == 0) { return(new object[0]); } var parameterValues = Parameters.Select(x => ((Parameter)x).Value).ToArray(); if (requiredParameters.Length != parameterValues.Length) { throw new InvalidOperationException(string.Format("Inconsistent number of parameters for method {0}.", method.Name)); } var context = (CoroutineExecutionContext)null; for (var i = 0; i < requiredParameters.Length; i++) { var parameterType = requiredParameters[i].ParameterType; var parameterValue = parameterValues[i]; var specialValue = parameterValue as ISpecialValue; if (specialValue != null) { if (context == null) { context = new CoroutineExecutionContext { Source = AssociatedObject, Target = Target, EventArgs = eventArgs, } } ; parameterValue = specialValue.Resolve(context); } parameterValues[i] = ParameterBinder.CoerceValue(parameterType, parameterValue); } return(parameterValues); }
private static object DetermineParameter(object sender, object eventArgs) { var resolvedParameter = UIContext.GetCommandParameter(sender); var specialValue = resolvedParameter as ISpecialValue; if (specialValue != null) { var context = new CoroutineExecutionContext { Source = sender, EventArgs = eventArgs, }; resolvedParameter = specialValue.Resolve(context); } return(resolvedParameter ?? eventArgs); }
private object DetermineParameter(object eventArgs = null) { var resolvedParameter = CommandParameter; var specialValue = resolvedParameter as ISpecialValue; if (specialValue != null) { var context = new CoroutineExecutionContext { Source = AssociatedObject, EventArgs = eventArgs, }; resolvedParameter = specialValue.Resolve(context); } return(resolvedParameter ?? eventArgs); }
/// <summary> /// Executes the result using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { var saveFileDialog = new SaveFileDialog(); saveFileDialog.RestoreDirectory = true; saveFileDialog.AddExtension = true; saveFileDialog.CheckPathExists = true; saveFileDialog.Filter = _fileTypeFilter; saveFileDialog.DefaultExt = _defaultFileExtension; saveFileDialog.Title = _title; saveFileDialog.FileName = _fileName; saveFileDialog.CreatePrompt = _promptForCreate; saveFileDialog.OverwritePrompt = _promptForOverwrite; saveFileDialog.InitialDirectory = _initialDirectory; var activeWindow = CoTaskHelper.GetActiveWindow(context); bool fileSelected; try { fileSelected = saveFileDialog.ShowDialog(activeWindow).GetValueOrDefault(); } catch { if (string.IsNullOrEmpty(saveFileDialog.InitialDirectory)) { throw; } saveFileDialog.InitialDirectory = null; fileSelected = saveFileDialog.ShowDialog(activeWindow).GetValueOrDefault(); } if (fileSelected) { Result = new FileInfo(saveFileDialog.FileName); } OnCompleted(new CoTaskCompletedEventArgs(null, !fileSelected)); }
private static Task <TResult> InternalExecuteAsync <TResult>(ICoTask coTask, CoroutineExecutionContext context) { var taskSource = new TaskCompletionSource <TResult>(); EventHandler <CoTaskCompletedEventArgs> completed = null; completed = (s, e) => { ((ICoTask)s).Completed -= completed; if (e.Error != null) { taskSource.TrySetException(e.Error); } else if (e.WasCancelled) { taskSource.TrySetCanceled(); } else { var rr = s as ICoTask <TResult>; taskSource.TrySetResult(rr != null ? rr.Result : default(TResult)); } }; try { coTask.Completed += completed; coTask.BeginExecute(context ?? new CoroutineExecutionContext()); } catch (Exception ex) { coTask.Completed -= completed; taskSource.TrySetException(ex); } return(taskSource.Task); }
private void Continue(CoroutineExecutionContext context) { ICoTask continueCoTask; try { continueCoTask = _coroutine(); } catch (Exception ex) { OnCompleted(new CoTaskCompletedEventArgs(ex, false)); return; } try { continueCoTask.Completed += ContinueCompleted; continueCoTask.BeginExecute(context); } catch (Exception ex) { ContinueCompleted(continueCoTask, new CoTaskCompletedEventArgs(ex, false)); } }
private void Rescue(CoroutineExecutionContext context, TException exception) { ICoTask rescueCoTask; try { rescueCoTask = _coroutine(exception); } catch (Exception ex) { OnCompleted(new CoTaskCompletedEventArgs(ex, false)); return; } try { rescueCoTask.Completed += RescueCompleted; rescueCoTask.BeginExecute(context); } catch (Exception ex) { RescueCompleted(rescueCoTask, new CoTaskCompletedEventArgs(ex, false)); } }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { OnCompleted(new CoTaskCompletedEventArgs(_error, _wasCancelled)); }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { OnCompleted(new CoTaskCompletedEventArgs(_error, _wasCancelled)); }
private void InnerCoTaskCompleted(object sender, CoTaskCompletedEventArgs args) { _innerCoTask.Completed -= InnerCoTaskCompleted; OnInnerResultCompleted(_context, _innerCoTask, args); _context = null; }
/// <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="CoTaskCompletedEventArgs"/> instance containing the event data.</param> protected abstract void OnInnerResultCompleted(CoroutineExecutionContext context, ICoTask innerCoTask, CoTaskCompletedEventArgs args);
/// <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="CoTaskCompletedEventArgs"/> instance containing the event data.</param> protected abstract void OnInnerResultCompleted(CoroutineExecutionContext context, ICoTask innerCoTask, CoTaskCompletedEventArgs args);
/// <summary> /// Executes an <see cref="ICoTask<TResult>"/> asynchronous. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="coTask">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 ICoTask <TResult> coTask, CoroutineExecutionContext context = null) { return(InternalExecuteAsync <TResult>(coTask, context)); }
private static Window GetWindowFromContext(CoroutineExecutionContext context) { var view = context.Source as DependencyObject; return(view != null?Window.GetWindow(view) : null); }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public abstract void BeginExecute(CoroutineExecutionContext context);
private void InnerCoTaskCompleted(object sender, CoTaskCompletedEventArgs args) { _innerCoTask.Completed -= InnerCoTaskCompleted; OnInnerResultCompleted(_context, _innerCoTask, args); _context = null; }
private void OnComplete(Exception error, bool wasCancelled) { _context = null; _enumerator.Dispose(); OnCompleted(new CoTaskCompletedEventArgs(error, wasCancelled)); }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { _context = context; ChildCompleted(null, new CoTaskCompletedEventArgs(null, false)); }
public static Window GetActiveWindow(CoroutineExecutionContext context) { return GetWindowFromContext(context) ?? GetFirstActiveWindow(); }
public object Resolve(CoroutineExecutionContext context) { return ((ItemClickEventArgs)context.EventArgs).ClickedItem; }
/// <summary> /// Executes an <see cref="ICoTask"/> asynchronous. /// </summary> /// <param name="coTask">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 ICoTask coTask, CoroutineExecutionContext context = null) { return(InternalExecuteAsync <object>(coTask, context)); }
public static Window GetActiveWindow(CoroutineExecutionContext context) { return(GetWindowFromContext(context) ?? GetFirstActiveWindow()); }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public override void BeginExecute(CoroutineExecutionContext context) { _context = context; ChildCompleted(null, new CoTaskCompletedEventArgs(null, false)); }
/// <summary> /// Executes the CoTask using the specified context. /// </summary> /// <param name="context">The context.</param> public abstract void BeginExecute(CoroutineExecutionContext context);
private void OnComplete(Exception error, bool wasCancelled) { _context = null; _enumerator.Dispose(); OnCompleted(new CoTaskCompletedEventArgs(error, wasCancelled)); }
private static Window GetWindowFromContext(CoroutineExecutionContext context) { var view = context.Source as DependencyObject; return view != null ? Window.GetWindow(view) : null; }