Advertisement
Guest User

Daniel Neri

a guest
Jul 19th, 2009
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.quikchek.util
  2. {
  3.     import flash.events.Event;
  4.     import flash.events.EventDispatcher;
  5.     import flash.net.Responder;
  6.     import flash.utils.clearInterval;
  7.     import flash.utils.setInterval;
  8.    
  9.     import mx.core.Application;
  10.    
  11.     //Tell flex we intend to broadcast two events
  12.     [Event("checkVersion")]
  13.     [Event("updateVersion")]
  14.    
  15.     public class VersionManager extends EventDispatcher {
  16.        
  17.       private var _pollTime:Number;
  18.       private var _applicationVersionNumber:Number;
  19.       private var _latestVersionNumber:Number;
  20.    
  21.       private var pollInterval:Number;
  22.    
  23.    
  24.       /* The requestVersionCheck function is called periodically
  25.          via the SetInterval. It dispatches an event asking for
  26.          the latest version of the software available */
  27.       private function requestVersionCheck():void {
  28.         //Cancel our current interval.
  29.         //We will wait for a response before we ask again
  30.         clearInterval(   pollInterval  );
  31.    
  32.         //We need to find out the current version of this software
  33.         dispatchEvent(new Event("checkVersion"));
  34.       }  
  35.      
  36.      
  37.    
  38.       /*getter/setter functions for the version number
  39.         of this application  */
  40.       public function set applicationVersionNumber( value:Number ):void
  41.       {
  42.         //This is the version number of our local application
  43.         _applicationVersionNumber = value;
  44.       }
  45.    
  46.       public function get applicationVersionNumber():Number
  47.       {
  48.         return _applicationVersionNumber;
  49.       }
  50.    
  51.       /* getter/setter functions for the latest version number of
  52.          this application according to an outside authority  */
  53.       public function set latestVersionNumber( value:Number ):void
  54.       {
  55.         //This is the latest available version number of the application
  56.         _latestVersionNumber = value;
  57.        
  58.         //We check if we are up to date
  59.         if ( applicationVersionNumber < latestVersionNumber )    {
  60.           //We need to update.  We inform whomever may be listening
  61.           dispatchEvent(new Event("updateVersion"));
  62.         } else {
  63.           //We have a current version for the moment.
  64.           //We will check again later
  65.           this.pollInterval = setInterval( requestVersionCheck, pollTime );
  66.         }
  67.       }
  68.    
  69.       public function get latestVersionNumber():Number {
  70.         return _latestVersionNumber;
  71.       }
  72.    
  73.       //getter/setter functions for our polling interval
  74.       public function set pollTime( value:Number ):void
  75.       {
  76.         if ( value < 1800000 ) {
  77.           /*For our purposes, we are going to constrain the poll
  78.             period so that it cannot be less 30 minutes
  79.           */
  80.          
  81.           //default to one hour, 3600 seconds * 1000
  82.           value = 1800000;
  83.         }
  84.        
  85.         _pollTime = value;
  86.       }
  87.    
  88.       public function get pollTime():Number {
  89.         return _pollTime;
  90.       }
  91.    
  92.       /*We call this method when we are ready to begin
  93.         managing the version of our application */
  94.       public function manageVersion():void  {
  95.         /*immediately request a version check on startup.  
  96.           we want to find out if a new version exists before
  97.           the user gets to far into using the application */
  98.         requestVersionCheck();
  99.       }
  100.      
  101.       private function onFault(obj:Object):void
  102.       {
  103.        
  104.       }
  105.     }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement