|
| UpdaterViewModel (Updater updater) |
|
override object | RevealModelObject () |
| Returns the model object that this view model wraps or null if there is no wrapped model object. More...
|
|
| UpdaterViewModel (Updater updater) |
|
override object | RevealModelObject () |
| Returns the model object that this view model wraps or null if there is no wrapped model object. More...
|
|
bool | IsViewModelOf (object model) |
| Determines whether the current object is a view model of a particular model object. Returns false if either the model or the viewmodel's wrapped model object is null. 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. Use this to show views during asynchronous operations. More...
|
|
void | InjectAndShowInThread< T > () |
| Creates a new thread that creates a new instance of the view T and shows it modelessly. Use this to show views during asynchronous operations. 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. Use this to show dialogs during asynchronous operations. More...
|
|
bool | IsViewModelOf (object model) |
| Determines whether the current object is a view model of a particular model object. Returns false if either the model or the viewmodel's wrapped model object is null. 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. Use this to show views during asynchronous operations. More...
|
|
void | InjectAndShowInThread< T > () |
| Creates a new thread that creates a new instance of the view T and shows it modelessly. Use this to show views during asynchronous operations. 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. Use this to show dialogs during asynchronous operations. More...
|
|
Acts as a view model for the Updater class which is concerned with fetching version information and downloading the update. The view model implements related interactivity.
Views that subscribe to this view model should provide their own Updater class, since the base Updater class is abstract. Derived Updater classes provide project-specific information such as the download URI.
Checking for an available update and downloading it is a complex task that involves several interactions with a user (or a view, to stay with MVVM terminology). Basically, the process will be as follows:
-
The View subscribes to the UpdaterViewModel's CheckForUpdateMessage and executes the VM's CheckForUpdateCommand.
-
The VM then arranges for the Updater model to asynchronously fetch version information from the remote repository and sends the CheckForUpdateMessage.
-
Upon receiving the CheckForUpdateMessage, the View could, for example, invoke another view that displays an 'indeterminate progress'. It could however just silently wait for the update check to finish. In either case, some view should listen to one of four self-explanatory messages that the VM will send upon receiving the current version information:
-
UpdateAvailableMessage
-
NoUpdateAvailableMessage
-
UpdateAvailableButNotAuthorizedMessage (if the current user does not have write permissions to the assembly's folder)
-
NetworkFailureMessage if any exception occurred while downloading the current version information.
-
The last three of these messages could be dealt with by simply showing an informative view to the user, for example, or writing to a log file. If the view receives the UpdateAvailableMessage, it could show the update version information that is exposed in the VM's public properties to the user.
-
Before starting to download the update, the VM's ChooseDestinationFolderCommand must be executed. This will send the ChooseDestinationFolderMessage, whose content is a StringMessageContent that carries the last used destination folder (or the user's MyDocuments special folder).
-
The view can now optionally have the user choose the appropriate download folder and set the VM's DestinationFolder property accordingly (e.g. by data binding). If the view is a GUI (e.g. a WPF window), this is best done by invoking a ChooseFolderAction, since there is no ready-to-use folder picker in the WPF. The ChooseFolderAction responds to the VM's ChooseDestinationFolderMessage by calling the message's respond method.
-
The VM now examines the content of the ChooseDestinationFolderMessage; if the message content's Confirmed property is true, it will save the chosen folder in the assembly's properties and send the ReadyToDownloadMessage.
-
The view that invoked the ChooseFolderAction listens for the ReadyToDownloadMessage and executes the VM's DownloadUpdateCommand.
-
The DownloadUpdateCommand requests the Updater model to asynchronously download the update to the desired folder. It sends the DownloadUpdateMessage which contains the download progress (that can be data-bound to by a progress bar, for example) and whose CancelCommand can be invoked by a view to cancel downloading.
-
The view that executed the DownloadUpdateCommand listens for a DownloadUpdateMessage and could invoke a ShowViewAction with the message argument that shows a progress bar view which is data-bound to the DownloadUpdateMessage's ProcessMessageContent.
-
When the download is finished, the VM compares the file's Sha1 checksum with the expected checksum that was announced in the update version information and issues an UpdateInstallableMessage or a UpdateFailedVerificationMessage as appropriate. It may also send a NetworkFailureMessage if some exception occurred while downloading.
-
Finally, upon receiving the UpdateInstallableMessage, the view may execute the VM's InstallUpdateCommand. The VM's InstallUpdateCommand logic will proceed with executing the downloaded file (by calling the updater model's InstallUpdate method), or send an UpdateFailedVerificationMessage.
Note: Views (or code) that subscribe to the UpdaterViewModel do not necessarily have to listen and respond to all of the VM's messages. For example, it is not necessary to execute the ChooseDestinationFolderCommand, listen for the ChooseDestinationFolderMessage, respond to it, and listen for the ReadyToDownloadMessage. These commands and messages serve to facilitate displaying GUI views in the MVVM pattern. If the code that wishes to check for an available update (e.g., in the background without the user's attention) has another way to set the destination folder or is happy with the last used or default destination folder, it may just proceed with executing the DownloadUpdate command.
override object Bovender.Versioning.UpdaterViewModel.RevealModelObject |
( |
| ) |
|
|
inlinevirtual |
Returns the model object that this view model wraps or null if there is no wrapped model object.
This is a method rather than a property to make data binding more difficult (if not impossible), because binding directly to the model object is discouraged. However, certain users such as a ViewModelCollection might need access to the wrapped model object.
- Returns
- Model object.
Implements Bovender.Mvvm.ViewModels.ViewModelBase.
override object Bovender.Versioning.UpdaterViewModel.RevealModelObject |
( |
| ) |
|
|
inlinevirtual |
Returns the model object that this view model wraps or null if there is no wrapped model object.
This is a method rather than a property to make data binding more difficult (if not impossible), because binding directly to the model object is discouraged. However, certain users such as a ViewModelCollection might need access to the wrapped model object.
- Returns
- Model object.
Implements Bovender.Mvvm.ViewModels.ViewModelBase.