Created
October 16, 2013 09:51
-
-
Save jamie94bc/7005369 to your computer and use it in GitHub Desktop.
Interfaces for an upgrade service to handle changes between versions on an application. If required, IUpgradeService should be implemented in a PCL with the CurrentAppVersion left as abstract to implement on a per device basis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Defines an interface which upgrades | |
/// the application from a version which is great | |
/// or equal to <see cref="IUpgrade.FromVersion"/> | |
/// and before <see cref="IUpgrade.ToVersion"/>. | |
/// </summary> | |
public interface IUpgrade { | |
Version FromVersion { get; } | |
Version ToVersion { get; } | |
/// <summary> | |
/// Attempts to upgrade the the application. | |
/// </summary> | |
/// <returns> | |
/// True if the upgrade was successful. ie. | |
/// false will be returned when an upgrade | |
/// was attempted but no data was present. | |
/// </returns> | |
System.Threading.Tasks.Task<bool> DoUpgradeAsync(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IUpgradeService { | |
/// <summary> | |
/// Ascertains whether the application | |
/// requires an upgrade by comparing | |
/// the current <see cref="CurrentAppVersion"/> | |
/// with the stored version. | |
/// | |
/// An upgrade is only required when an <see cref="IUpgrade"/> | |
/// has been registered which can upgrade the previous version | |
/// (or greater) to the current version. | |
/// </summary> | |
bool RequiresUpgrade { get; } | |
/// <summary> | |
/// The previously upgraded (or stored) application | |
/// version. | |
/// | |
/// This will be null if it's the first time the user | |
/// has opened the app. | |
/// </summary> | |
Version PreviousAppVersion { get; } | |
/// <summary> | |
/// Returns the current version of the application. | |
/// </summary> | |
Version CurrentAppVersion { get; } | |
/// <summary> | |
/// Adds an upgrade to the upgrade service. | |
/// </summary> | |
/// <typeparam name="TUpgrade"> | |
/// The type of upgrade to add. | |
/// </typeparam> | |
/// <exception cref="InvalidOperationException"> | |
/// Thrown if the same type is attempted to | |
/// be registered twice. | |
/// </exception> | |
void RegisterUpgrade<TUpgrade>() where TUpgrade : IUpgrade; | |
/// <summary> | |
/// Attempts to upgrade the application. | |
/// | |
/// Silently fails if <see cref="RequiresUpgrade"/> | |
/// is false. | |
/// </summary> | |
/// <exception cref="InvalidOperationException"> | |
/// Thrown when the one of the registered upgrade's | |
/// <see cref="IUpgrade.ToVersion"/> | |
/// is greater than the application's current version. | |
/// </exception> | |
Task DoUpgradeAsync(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment