Daniel's XL Toolbox NG
Bovender.Versioning.UpdaterViewModel Class Reference

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. More...

Inheritance diagram for Bovender.Versioning.UpdaterViewModel:
Collaboration diagram for Bovender.Versioning.UpdaterViewModel:

Public Member Functions

 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...
 
- 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. 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...
 

Properties

SemanticVersion NewVersion [get]
 
SemanticVersion CurrentVersion [get]
 
string UpdateSummary [get]
 
Uri DownloadUri [get]
 
bool IsUserAuthorized [get]
 
bool IsVerifiedDownload [get]
 
bool IsUpdatePending [get]
 
bool CanCheckForUpdate [get]
 
string DestinationFolder [get, set]
 
Exception DownloadException [get]
 
DelegatingCommand CheckForUpdateCommand [get]
 
DelegatingCommand ChooseDestinationFolderCommand [get]
 
DelegatingCommand DownloadUpdateCommand [get]
 
DelegatingCommand InstallUpdateCommand [get]
 
Message< ProcessMessageContentCheckForUpdateMessage [get]
 
Message< ViewModelMessageContentUpdateAvailableMessage [get]
 
Message< ProcessMessageContentReadyToDownloadMessage [get]
 
Message< ViewModelMessageContentUpdateAvailableButNotAuthorizedMessage [get]
 
Message< ViewModelMessageContentNoUpdateAvailableMessage [get]
 
Message< FileNameMessageContentChooseDestinationFolderMessage [get]
 
Message< ProcessMessageContentDownloadUpdateMessage [get]
 
Message< ViewModelMessageContentUpdateInstallableMessage [get]
 
Message< ViewModelMessageContentUpdateFailedVerificationMessage [get]
 
Message< ViewModelMessageContentNetworkFailureMessage [get]
 
- Properties inherited from Bovender.Mvvm.ViewModels.ViewModelBase
ICommand CloseViewCommand [get]
 
virtual string DisplayString [get, set]
 
bool IsSelected [get, set]
 
Dispatcher ViewDispatcher [get, set]
 
Dispatcher Dispatcher [get]
 Captures the dispatcher of the thread that the object was created in. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Bovender.Mvvm.ViewModels.ViewModelBase
virtual void OnPropertyChanged (string propertyName)
 
virtual bool CanCloseView ()
 
virtual void DoCloseView ()
 
 ViewModelBase ()
 Does not allow public instantiation of this class. More...
 
virtual void OnPropertyChanged (string propertyName)
 
virtual bool CanCloseView ()
 
virtual void DoCloseView ()
 
 ViewModelBase ()
 Does not allow public instantiation of this class. More...
 
- 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

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:
    1. UpdateAvailableMessage
    2. NoUpdateAvailableMessage
    3. UpdateAvailableButNotAuthorizedMessage (if the current user does not have write permissions to the assembly's folder)
    4. 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.

Constructor & Destructor Documentation

◆ UpdaterViewModel() [1/2]

Bovender.Versioning.UpdaterViewModel.UpdaterViewModel ( Updater  updater)
inline

◆ UpdaterViewModel() [2/2]

Bovender.Versioning.UpdaterViewModel.UpdaterViewModel ( Updater  updater)
inline

Member Function Documentation

◆ RevealModelObject() [1/2]

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.

◆ RevealModelObject() [2/2]

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.

Property Documentation

◆ CanCheckForUpdate

bool Bovender.Versioning.UpdaterViewModel.CanCheckForUpdate
get

◆ CheckForUpdateCommand

DelegatingCommand Bovender.Versioning.UpdaterViewModel.CheckForUpdateCommand
get

◆ CheckForUpdateMessage

Message< ProcessMessageContent > Bovender.Versioning.UpdaterViewModel.CheckForUpdateMessage
get

◆ ChooseDestinationFolderCommand

DelegatingCommand Bovender.Versioning.UpdaterViewModel.ChooseDestinationFolderCommand
get

◆ ChooseDestinationFolderMessage

Message< FileNameMessageContent > Bovender.Versioning.UpdaterViewModel.ChooseDestinationFolderMessage
get

◆ CurrentVersion

SemanticVersion Bovender.Versioning.UpdaterViewModel.CurrentVersion
get

◆ DestinationFolder

string Bovender.Versioning.UpdaterViewModel.DestinationFolder
getset

◆ DownloadException

Exception Bovender.Versioning.UpdaterViewModel.DownloadException
get

◆ DownloadUpdateCommand

DelegatingCommand Bovender.Versioning.UpdaterViewModel.DownloadUpdateCommand
get

◆ DownloadUpdateMessage

Message< ProcessMessageContent > Bovender.Versioning.UpdaterViewModel.DownloadUpdateMessage
get

◆ DownloadUri

Uri Bovender.Versioning.UpdaterViewModel.DownloadUri
get

◆ InstallUpdateCommand

DelegatingCommand Bovender.Versioning.UpdaterViewModel.InstallUpdateCommand
get

◆ IsUpdatePending

bool Bovender.Versioning.UpdaterViewModel.IsUpdatePending
get

◆ IsUserAuthorized

bool Bovender.Versioning.UpdaterViewModel.IsUserAuthorized
get

◆ IsVerifiedDownload

bool Bovender.Versioning.UpdaterViewModel.IsVerifiedDownload
get

◆ NetworkFailureMessage

Message< ViewModelMessageContent > Bovender.Versioning.UpdaterViewModel.NetworkFailureMessage
get

◆ NewVersion

SemanticVersion Bovender.Versioning.UpdaterViewModel.NewVersion
get

◆ NoUpdateAvailableMessage

Message< ViewModelMessageContent > Bovender.Versioning.UpdaterViewModel.NoUpdateAvailableMessage
get

◆ ReadyToDownloadMessage

Message< ProcessMessageContent > Bovender.Versioning.UpdaterViewModel.ReadyToDownloadMessage
get

◆ UpdateAvailableButNotAuthorizedMessage

Message< ViewModelMessageContent > Bovender.Versioning.UpdaterViewModel.UpdateAvailableButNotAuthorizedMessage
get

◆ UpdateAvailableMessage

Message< ViewModelMessageContent > Bovender.Versioning.UpdaterViewModel.UpdateAvailableMessage
get

◆ UpdateFailedVerificationMessage

Message< ViewModelMessageContent > Bovender.Versioning.UpdaterViewModel.UpdateFailedVerificationMessage
get

◆ UpdateInstallableMessage

Message< ViewModelMessageContent > Bovender.Versioning.UpdaterViewModel.UpdateInstallableMessage
get

◆ UpdateSummary

string Bovender.Versioning.UpdaterViewModel.UpdateSummary
get

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