Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Created February 28, 2011 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeminutillo/846867 to your computer and use it in GitHub Desktop.
Save mikeminutillo/846867 to your computer and use it in GitHub Desktop.
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