Skip to content

Instantly share code, notes, and snippets.

@maximilian-krauss
Created February 25, 2012 18:29
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 maximilian-krauss/1909966 to your computer and use it in GitHub Desktop.
Save maximilian-krauss/1909966 to your computer and use it in GitHub Desktop.
updateSystem.NET - Asynchronous Updatecheck
#Region " Asynchroner Updatespaß "
Private Sub btnRunAsync_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRunAsync.Click
'Updatesuche anstoßen
upctrlMain.checkForUpdatesAsync()
End Sub
'Dieses Event wird in jedem Falle nach Abschluß der Updatesuche gefeuert.
'Also bei gefundenen Updates, keinen neuen Updates und auch im Fehlerfall.
Private Sub upctrlMain_checkForUpdatesCompleted(ByVal sender As Object, ByVal e As updateSystemDotNet.appEventArgs.checkForUpdatesCompletedEventArgs) Handles upctrlMain.checkForUpdatesCompleted
'Überprüfen ob ein Fehler auftrat:
'könnte man auch ne MessageBox anzeigen, aber das ist jedem selber überlassen.
If Not e.Error Is Nothing And Not e.Cancelled Then Throw e.Error
End Sub
'Dieses Event wird ausschließlich gefeuert, wenn bei der Updatesuche neue Aktualisierungen gefunden wurden.
Private Sub upctrlMain_updateFound(ByVal sender As Object, ByVal e As updateSystemDotNet.appEventArgs.updateFoundEventArgs) Handles upctrlMain.updateFound
'Dem Benutzer anzeigen das es neue Updates gibt, dazu bauen wir uns erst den Changelog zusammen
Dim sbChangelog As New StringBuilder
For Each package As updatePackage In e.Result.newUpdatePackages
sbChangelog.AppendLine("Änderungen in Version " + package.releaseInfo.Version)
sbChangelog.AppendLine(e.Result.Changelogs(package).germanChanges)
sbChangelog.AppendLine()
Next
'Neueste Version ermitteln
Dim latestVersion As String = e.Result.newUpdatePackages(e.Result.newUpdatePackages.Count - 1).releaseInfo.Version
If MessageBox.Show(String.Format("Es ist eine neue Version verfügbar: {0}" + Environment.NewLine + "Changelog:" + Environment.NewLine + "{1}" + Environment.NewLine + "Möchten Sie diese Installieren?", latestVersion, sbChangelog.ToString), "Testanwendung", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
upctrlMain.downloadUpdates()
End If
End Sub
Private Sub upctrlMain_downloadUpdatesCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles upctrlMain.downloadUpdatesCompleted
If Not e.Error Is Nothing Then Throw e.Error
upctrlMain.applyUpdate()
End Sub
Private Sub upctrlMain_downloadUpdatesProgressChanged(ByVal sender As Object, ByVal e As updateSystemDotNet.appEventArgs.downloadUpdatesProgressChangedEventArgs) Handles upctrlMain.downloadUpdatesProgressChanged
prgDownloadProgress.Value = e.ProgressPercentage
End Sub
#End Region
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment