The AppLife Update Blog

  • How to Hide the Error When Out of Network Range

    All of the visual updating controls that ship with AppLife Update show an error icon and message whenever an update check fails.  Sometimes though this isn't the most desirable behavior.  For instance, if your application runs on a laptop that is frequently moving in and out of network coverage.  In a situation like this, an update check failure is expected and you probably don’t want to display a concerning error icon to your end user.

     

    image

     

    To address this, we can look at the results of an update check and check to see why the error occurred.  If the issue is a network connection error, and we expect spotty network connectivity, we can choose to hide the control, instead of displaying an error to the user.

    By listening for the CheckForUpdateCompleted event of the Update Controller, information about the error can be inspected and we can hide the control if a connectivity issue is discovered.

       1:  private void updateController1_CheckForUpdateCompleted(object sender,
       2:       Kjs.AppLife.Update.Controller.CheckForUpdateCompletedEventArgs e) {
       3:      if(e.Error != null &&
       4:          e.Error.InnerException != null &&
       5:          e.Error.InnerException is WebException) {
       6:          WebException ex = e.Error.InnerException as WebException;
       7:          if(ex.Status == WebExceptionStatus.NameResolutionFailure ||
       8:             ex.Status == WebExceptionStatus.ConnectFailure) {
       9:          //There is connectivity issue. 
      10:          //Hide the update control, instead of showing an error.
      11:              this.updateDisplay1.Visible = false;
      12:          }
      13:      }
      14:  }

    Another Alternative

    It might be more preferable to display the control but show that no updates are available. We can accomplish this as well by including with the application a Director.Xml file that contains no updates.  Just copy the Director.Xml file from your publish location and remove all Version nodes. With this file present, instead of hiding the control, we can change the update location to the local application path and initiate another update check.  This time no updates will be found and the control will indicate this.

       1:  Kjs.AppLife.Update.Controller.CheckForUpdateCompletedEventArgs e) {
       2:  if(e.Error != null &&
       3:      e.Error.InnerException != null &&
       4:      e.Error.InnerException is WebException) {
       5:      WebException ex = e.Error.InnerException as WebException;
       6:      if(ex.Status == WebExceptionStatus.NameResolutionFailure ||
       7:          ex.Status == WebExceptionStatus.ConnectFailure) {
       8:          //There is connectivity issue. 
       9:          //Start an update check that will not find an update.
      10:          string appDir = Path.GetDirectoryName(Application.ExecutablePath);
      11:          this.updateController1.UpdateLocation = appDir;
      12:          this.updateController1.CheckForUpdateAsync();
      13:      }
      14:  }

    With no network connectivity, this is what is displayed to the user.

    image 

    These techniques can be used with any of the visual updating controls and provides a method to customize the user experience when network connectivity is expectedly unreliable.

    Posted at 13 January, 2011 | By :Brian Haas | Categories : AppLife Update | Software Updating |