/// <summary> /// Executes the command. /// </summary> /// <param name="param">The param.</param> public virtual void DoExecute(object param) { // Invoke the executing command, allowing the command to be cancelled. CancelCommandEventArgs args = new CancelCommandEventArgs() { Parameter = param, Cancel = false }; InvokeExecuting(args); // If the event has been cancelled, bail now. if (args.Cancel) { return; } // Call the action or the parameterized action, whichever has been set. InvokeAction(param); //await Task.Factory.StartNew(InvokeAction, param); // Call the executed function. InvokeExecuted(new CommandEventArgs() { Parameter = param }); }
void LoadSceneCommand_Executing(object sender, CancelCommandEventArgs args) { // Use the serialization engine. var engine = SharpGL.Serialization.SerializationEngine.Instance; // Create an open file dialog. OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = engine.Filter; // Show the dialog. if (openFileDialog.ShowDialog() != true) { // Cancel any loading. args.Cancel = true; return; } // Load the scene. Scene scene = engine.LoadScene(openFileDialog.FileName); // Set the args. args.Parameter = scene; // Create in the current OpenGL context. scene.CreateInContext(viewModel.Scene.CurrentOpenGLContext); // Switch the scene over. viewModel.SelectedElements.Clear(); viewModel.Scene = scene; }
private void UninstallAssembliesCommand_Executing(object sender, Apex.MVVM.CancelCommandEventArgs args) { // Double check with the user. args.Cancel = MessageBox.Show(Resources.Prompt_Uninstall, Resources.Title_Uninstall, MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes; }
protected void InvokeExecuting(CancelCommandEventArgs args) { CancelCommandEventHandler executing = Executing; // Call the executed event. if (executing != null) { executing(this, args); } }
/// <summary> /// Invokes the executing event. /// </summary> /// <param name="args">The <see cref="Apex.MVVM.CancelCommandEventArgs"/> instance containing the event data.</param> protected void InvokeExecuting(CancelCommandEventArgs args) { // Get the event. var theEvent = Executing; // Call the executed event. if (theEvent != null) { theEvent(this, args); } }
/// <summary> /// Handles the Executing event of the FileSaveAsCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CancelCommandEventArgs"/> instance containing the event data.</param> void FileSaveAsCommand_Executing(object sender, CancelCommandEventArgs args) { // Create a Save File Dialog. SaveFileDialog saveFileDialog = new SaveFileDialog(); // If the user cancels, end the command. if (saveFileDialog.ShowDialog() != true) { // Cancel the command. args.Cancel = true; return; } // Set the parameter to the path. args.Parameter = saveFileDialog.FileName; }
/// <summary> /// Handles the Executing event of the LoadDataCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CancelCommandEventArgs"/> instance containing the event data.</param> void LoadDataCommand_Executing(object sender, CancelCommandEventArgs args) { // Create an open file dialog. OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = SerializationEngine.Instance.Filter; // Show the dialog. if (openFileDialog.ShowDialog() != true) { // Cancel any loading. args.Cancel = true; return; } // Load the scene. Scene scene = SerializationEngine.Instance.LoadScene(openFileDialog.FileName); // Set the args. args.Parameter = scene; }
void SaveCommand_Executing(object sender, CancelCommandEventArgs args) { var sglSerializer = new SharpGL.Serialization.SharpGL.SharpGLXmlFormat(); // Create an open file dialog. SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = sglSerializer.Filter; // Show the dialog. if (saveFileDialog.ShowDialog() != true) { // Cancel any loading. args.Cancel = true; return; } // Set the args. args.Parameter = saveFileDialog.FileName; }
void DeleteContactCommand_Executing(object sender, CancelCommandEventArgs args) { args.Cancel = MessageBox.Show("Are you sure?", "Sure?", MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes; }
/// <summary> /// Handles the Executed event of the DealNewGameCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void SpiderDealNewGameCommand_Executing(object sender, CancelCommandEventArgs args) { // If we've made any moves, update the stats. if (SpiderSolitaireViewModel.Moves > 0) SpiderSolitaireStatistics.UpdateStatistics(SpiderSolitaireViewModel); Save(); }
/// <summary> /// Handles the Executing event of the FileExitCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CancelCommandEventArgs"/> instance containing the event data.</param> void FileExitCommand_Executing(object sender, CancelCommandEventArgs args) { // Close the application. Close(); }
/// <summary> /// Executes the command. /// </summary> /// <param name="param">The param.</param> public override void DoExecute(object param) { // If we are already executing, do not continue. if (IsExecuting) { return; } // Invoke the executing command, allowing the command to be cancelled. CancelCommandEventArgs args = new CancelCommandEventArgs() { Parameter = param, Cancel = false }; InvokeExecuting(args); // If the event has been cancelled, bail now. if (args.Cancel) { return; } // We are executing. IsExecuting = true; // Store the calling dispatcher. #if !SILVERLIGHT callingDispatcher = Dispatcher.CurrentDispatcher; #else callingDispatcher = System.Windows.Application.Current.RootVisual.Dispatcher; #endif // Run the action on a new thread from the thread pool (this will therefore work in SL and WP7 as well). ThreadPool.QueueUserWorkItem( (state) => { // Invoke the action. InvokeAction(param); // Fire the executed event and set the executing state. ReportProgress( () => { // We are no longer executing. IsExecuting = false; // If we were cancelled, invoke the cancelled event - otherwise invoke executed. if (IsCancellationRequested) { InvokeCancelled(new CommandEventArgs() { Parameter = param }); } else { InvokeExecuted(new CommandEventArgs() { Parameter = param }); } // We are no longer requesting cancellation. IsCancellationRequested = false; } ); } ); }
/// <summary> /// Executes the command. /// </summary> /// <param name="param">The param.</param> public override void DoExecute(object param) { // If we are already executing, do not continue. if (IsExecuting) { return; } // Invoke the executing command, allowing the command to be cancelled. var args = new CancelCommandEventArgs { Parameter = param, Cancel = false }; InvokeExecuting(args); // If the event has been cancelled, bail now. if (args.Cancel) { return; } // We are executing. IsExecuting = true; // If we disable during execution, disable now. if (DisableDuringExecution) { CanExecute = false; } // Store the calling dispatcher. Use the Consistency object // so that the same call works properly in WPF/SL/WP7. callingDispatcher = Consistency.DispatcherHelper.CurrentDispatcher; // Run the action on a new thread from the thread pool (this will therefore work in SL and WP7 as well). ThreadPool.QueueUserWorkItem( state => { // Invoke the action. InvokeAction(param); // Fire the executed event and set the executing state. ReportProgress( () => { // We are no longer executing. IsExecuting = false; // If we were cancelled, invoke the cancelled event - otherwise invoke executed. if (IsCancellationRequested) { InvokeCancelled(new CommandEventArgs { Parameter = param }); } else { InvokeExecuted(new CommandEventArgs { Parameter = param }); } // We are no longer requesting cancellation. IsCancellationRequested = false; // If we disable during execution, re-enable now. if (DisableDuringExecution) { CanExecute = true; } } ); } ); }
protected void InvokeExecuting(CancelCommandEventArgs args) { Executing?.Invoke(this, args); }
protected void InvokeExecuting(CancelCommandEventArgs args) { CancelCommandEventHandler executing = Executing; // Call the executed event. if (executing != null) executing(this, args); }
/// <summary> /// Executes the command. /// </summary> /// <param name="param">The param.</param> public virtual void DoExecute(object param) { // Invoke the executing command, allowing the command to be cancelled. CancelCommandEventArgs args = new CancelCommandEventArgs() { Parameter = param, Cancel = false }; InvokeExecuting(args); // If the event has been cancelled, bail now. if (args.Cancel) return; // Call the action or the parameterized action, whichever has been set. InvokeAction(param); // Call the executed function. InvokeExecuted(new CommandEventArgs() { Parameter = param }); }