bovender framework
C# framework that implements MVVM and more
Bovender.Mvvm.ViewModels.ProcessViewModelBase Class Referenceabstract

Abstract base class for view models that deal with processes. More...

Inheritance diagram for Bovender.Mvvm.ViewModels.ProcessViewModelBase:
Bovender.Mvvm.ViewModels.ViewModelBase Bovender.UnitTests.Mvvm.ProcessViewModelForTesting Bovender.Versioning.ReleaseInfoViewModel Bovender.Versioning.UpdaterViewModel

Public Member Functions

virtual void StartProcess ()
 Entry point to starts the process. More...
 
virtual void CancelProcess ()
 Cancels the ongoing process. More...
 
override object RevealModelObject ()
 Returns the associated Bovender.Mvvm.Models.ProcessModel (if any). More...
 
- Public Member Functions inherited from Bovender.Mvvm.ViewModels.ViewModelBase
bool IsViewModelOf (object model)
 Determines whether the current object is a view model of a particular model object. More...
 
Window InjectInto< T > ()
 Injects the ViewModel into a newly created View and wires the RequestCloseView event. More...
 
Window InjectInto (Window view)
 Injects the view model into an existing view by setting the view's DataContext. More...
 
void InjectAndShowInThread< T > (IntPtr ownerForm)
 Creates a new thread that creates a new instance of the view T , sets its Forms owner and shows it modelessly. More...
 
void InjectAndShowInThread< T > ()
 Creates a new thread that creates a new instance of the view T and shows it modelessly. More...
 
void InjectAndShowDialogInThread< T > (IntPtr ownerForm)
 Creates a new thread that creates a new instance of the view T and shows it as a dialog. More...
 

Protected Member Functions

abstract void UpdateProcessMessageContent (ProcessMessageContent processMessageContent)
 Updates the given ProcessMessageContent with the current process. More...
 
 ProcessViewModelBase (Models.IProcessModel processModel)
 
virtual bool BeforeStartProcess ()
 Additional work to do before the process is started. More...
 
virtual void AfterStartProcess ()
 Additional work to do after the process has started. More...
 
virtual void SendProcessFinishedMessage ()
 Sends the ProcessMessageContent.CompletedMessage to signal that the process has finished. More...
 
- Protected Member Functions inherited from Bovender.Mvvm.ViewModels.ViewModelBase
 ViewModelBase ()
 Does not allow public instantiation of this class. More...
 
virtual void OnPropertyChanged (string propertyName)
 
virtual bool CanCloseView ()
 
virtual void DoCloseView ()
 
CancellationToken Dispatch (Action action)
 Dispatches an action in the current synchronization context if one exists, or using the Dispatcher. More...
 

Properties

Bovender.Mvvm.Models.IProcessModel ProcessModel [get, protected set]
 
bool IsProcessing [get]
 
bool IsIndeterminate [get]
 
bool WasCancelled [get]
 
bool WasSuccessful [get]
 
virtual Exception Exception [get, protected set]
 
Message< ProcessMessageContentShowProgressMessage [get]
 Message that signals that the process status may be displayed. More...
 
Message< ProcessMessageContentProcessFinishedMessage [get]
 Message that signals when the process succeeded. More...
 
virtual ProcessMessageContent ProcessMessageContent [get]
 Message content for the process message. More...
 
- Properties inherited from Bovender.Mvvm.ViewModels.ViewModelBase
virtual string DisplayString [get, set]
 
bool IsSelected [get, set]
 
Dispatcher ViewDispatcher [get, set]
 
ICommand CloseViewCommand [get]
 
Dispatcher Dispatcher [get]
 Captures the dispatcher of the thread that the object was created in. More...
 
TaskScheduler SyncContext [get]
 

Additional Inherited Members

- Events inherited from Bovender.Mvvm.ViewModels.ViewModelBase
EventHandler RequestCloseView
 Raised by the CloseView Command, signals that associated views are to be closed. More...
 
PropertyChangedEventHandler PropertyChanged
 

Detailed Description

Abstract base class for view models that deal with processes.

To show a progress bar, listen to the ProcessViewModelBase.ShowProgress message and create a Bovender.Mvvm.Views.ProcessView instance when it is sent:

myProcessViewModel.ShowProgress.Sent += (sender, args) =>
{
args.Content.CancelButtonText = Strings.Cancel;
args.Content.Caption = Strings.ExportCsvFile;
args.Content.CompletedMessage.Sent += (sender2, args2) =>
{
args.Content.CloseViewCommand.Execute(null);
};
args.Content.InjectAndShowInThread<Bovender.Mvvm.Views.ProcessView>();
};

When the process finishes successfully, the ProcessView will be closed automatically.

If the process encounters an error, the ProcessViewModelBase.ProcessFailedMessage will be sent, and you may want to listen for it to inform the user:

myProcessViewModel.ProcessFailedMessage.Sent += (sender, args) =>
{
MessageBox.Show(args.Content.Value, Strings.ExportCsvFile,
MessageBoxButton.OK, MessageBoxImage.Warning);
};

Note that this class does not deal with separate threads. Implementations should defer threading to a model or take care of it themselves.

Definition at line 69 of file ProcessViewModelBase.cs.

Member Function Documentation

virtual void Bovender.Mvvm.ViewModels.ProcessViewModelBase.AfterStartProcess ( )
inlineprotectedvirtual

Additional work to do after the process has started.

In the base implementation, this executes the CloseViewCommand.

Definition at line 218 of file ProcessViewModelBase.cs.

virtual bool Bovender.Mvvm.ViewModels.ProcessViewModelBase.BeforeStartProcess ( )
inlineprotectedvirtual

Additional work to do before the process is started.

This will be called synchronously.

Returns
True or false. If true, the process is started. If false, the process is not started.

Definition at line 207 of file ProcessViewModelBase.cs.

virtual void Bovender.Mvvm.ViewModels.ProcessViewModelBase.CancelProcess ( )
inlinevirtual

Cancels the ongoing process.

Definition at line 126 of file ProcessViewModelBase.cs.

override object Bovender.Mvvm.ViewModels.ProcessViewModelBase.RevealModelObject ( )
inlinevirtual

Returns the associated Bovender.Mvvm.Models.ProcessModel (if any).

Returns

Implements Bovender.Mvvm.ViewModels.ViewModelBase.

Definition at line 246 of file ProcessViewModelBase.cs.

virtual void Bovender.Mvvm.ViewModels.ProcessViewModelBase.SendProcessFinishedMessage ( )
inlineprotectedvirtual

Sends the ProcessMessageContent.CompletedMessage to signal that the process has finished.

Reimplemented in Bovender.Versioning.UpdaterViewModel, and Bovender.Versioning.ReleaseInfoViewModel.

Definition at line 228 of file ProcessViewModelBase.cs.

virtual void Bovender.Mvvm.ViewModels.ProcessViewModelBase.StartProcess ( )
inlinevirtual

Entry point to starts the process.

This method initializes the timer that updates the process status in regular intervals, then calls the Execute method followed by the EndProcess method.

Definition at line 112 of file ProcessViewModelBase.cs.

abstract void Bovender.Mvvm.ViewModels.ProcessViewModelBase.UpdateProcessMessageContent ( ProcessMessageContent  processMessageContent)
protectedpure virtual

Updates the given ProcessMessageContent with the current process.

Normally this involves setting the PercentCompleted property, but if a descendant class is used, other informational properties may be updated as well.

To make use of a descendant class of ProcessMessageContent, override the ProcessMessageContent property.

Implemented in Bovender.Versioning.UpdaterViewModel, Bovender.Versioning.ReleaseInfoViewModel, and Bovender.UnitTests.Mvvm.ProcessViewModelForTesting.

Property Documentation

Message<ProcessMessageContent> Bovender.Mvvm.ViewModels.ProcessViewModelBase.ProcessFinishedMessage
get

Message that signals when the process succeeded.

Definition at line 160 of file ProcessViewModelBase.cs.

virtual ProcessMessageContent Bovender.Mvvm.ViewModels.ProcessViewModelBase.ProcessMessageContent
getprotected

Message content for the process message.

This is where the status updates occur. Process views get a hold of this message content when the ShowProcess message is sent.

Definition at line 261 of file ProcessViewModelBase.cs.

Message<ProcessMessageContent> Bovender.Mvvm.ViewModels.ProcessViewModelBase.ShowProgressMessage
get

Message that signals that the process status may be displayed.

This is sent a short while after StartProcess was called. This message is sent only once. Subsequent status updates are written to the shared ProcessMessageContent object.

Definition at line 145 of file ProcessViewModelBase.cs.


The documentation for this class was generated from the following file: