Replicate Updates Locally
In situations where there are many deployed systems located on the same local network combined with a need to minimize bandwidth utilized in retrieving application updates it is advantageous to provide a means to download update packages only once for everyone. With a new feature of AppLife Update 5.0, creating this ability is quite easy.
After an Update Controller checks for and downloads available updates, you can now save the downloaded package(s) and Director.Xml file to a local folder by calling the Update Controllers SaveUpdatesToLocal method.
As an example, let’s modify the C# Simple Quick Start project that ships with AppLife Update to first check a local folder for updates before checking the public location. Any updates downloaded from the public location will be copied locally for other local systems to find. To accomplish this, we’ll add a few Main form variables to hold the Public and Local update locations.
1: public partial class Form1 : Form {
2: private string mPublicUpdatePath = @"http://www.kin…/SaveToLocalExample";
3: private string mLocalUpdatePath = @"P:\Updates\SaveToLocalExample";
This Quick Start uses the UpdateDisplay control to manage the update process. To integrate with that process, we will use the CheckForUpdateCompleted and the DownloadUpdateCompleted events of the Update Controller.
Basically we are going to initially check the local update folder for updates. If no updates are found locally, we’ll check the public update folder. If we find any updates in the public location, we’ll save them locally with the new SaveUpdatesToLocal method. So here goes.
Modify the Update Controller’s default Update Location to be the local update path, and then attach to the two events.
First, lets handle the CheckForUpdateCompleted event. This event fires whenever the Update Controller completes an update check. If the private location was checked, we’ll just switch to the public location and check again.
1: private void updateController1_CheckForUpdateCompleted
2: (object sender, CheckForUpdateCompletedEventArgs e) {
3: UpdateController c = sender as UpdateController;
4: if(c.UpdateLocation == mLocalUpdatePath) {
5: //we checked the local path. If we didnt find any
6: //updates, lets check the public path
7: c.UpdateLocation = mPublicUpdatePath;
8: c.CheckForUpdateAsync();
9: }
10: }
And then finally, in the DownloadUpdateCompleted event, we’ll look to see if the update that was just downloaded came from the public location. If so, we’ll save it to the local folder using the new method.
1: private void updateController1_DownloadUpdateCompleted
2: (object sender, AsyncCompletedEventArgs e) {
3: UpdateController c = sender as UpdateController;
4: if(c.UpdateLocation == mPublicUpdatePath) {
5: //downloaded an update from the public path. Save it locally
6: c.SaveUpdatesToLocal(mLocalUpdatePath, false);
7: }
8: }
If multiple update packages were downloaded as a chain collection, all of the update packages will be saved by the SaveUpdatesToLocal method.