Created
February 28, 2011 02:56
-
-
Save mikeminutillo/846867 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface IUpdaterUI { | |
void UpdateStatus(int? progress = null, string message = null); | |
void SoftwareUpdateComplete(); | |
void DataUpdateComplete(); | |
} | |
class MyForm : IUpdaterUI { | |
public void UpdateStatus(int? progress = null, string message = null) { | |
if(progress.HasValue) SetProgress(progress.Value); | |
if(message != null) MessageLabel.Do(ctl => ctl.Text = message); | |
} | |
public void SoftwareUpdateComplete() { this.Do(frm => frm.Close(); } | |
public void DataUpdateComplete() { | |
Cancel.Do(ctl => ctl.Hide()); | |
ContinueButton.Do(ctl => ctl.Show()); | |
} | |
private void DownloadUpdates() { | |
try { | |
new Updater(this).Update(); | |
} catch(Exception ex) { | |
// same error handler code | |
} | |
} | |
} | |
class Updater { | |
private readonly IUpdaterUI ui; | |
public Updater(IUpdaterUI ui) { this.ui = ui; } | |
public void Update() { | |
ui.UpdateStatus(progress: 5, message: AvailableUpdate.DownloadingUpdateLabelText); | |
if(AvailableUpdate.SoftwareUpdateAvailable) | |
DoSoftwareUpdate(); | |
else if(AvailableUpdate.DataUpdateAvailable) | |
DoDataUpdate(); | |
} | |
private void DoSoftwareUpdate() { | |
ui.UpdateStatus(progress: 50); | |
UpdateSoftware(); | |
ui.UpdateStatus(progress: 100); | |
ui.SoftwareUpdateCompleted(); | |
} | |
private void DoDataUpdate() { | |
ui.UpdateStatus(progress: 50); | |
UpdateData(); | |
ui.UpdateStatus(progress: 100, message: AvailableUpdate.DownloadCompleteUpdateLabelText); | |
ui.DataUpdateComplete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment