home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / com / althea / client / shufflr / model / NavMapProxy.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  13.3 KB  |  377 lines

  1. package com.althea.client.shufflr.model
  2. {
  3.    import com.althea.client.shufflr.ApplicationFacade;
  4.    import com.althea.client.shufflr.controller.errors.ApplicationError;
  5.    import flash.events.TimerEvent;
  6.    import flash.utils.Timer;
  7.    import flash.utils.getQualifiedClassName;
  8.    import mx.collections.ArrayCollection;
  9.    import mx.logging.ILogger;
  10.    import mx.logging.Log;
  11.    import mx.logging.LogEventLevel;
  12.    import mx.rpc.AsyncToken;
  13.    import mx.rpc.Fault;
  14.    import mx.rpc.IResponder;
  15.    import mx.rpc.events.FaultEvent;
  16.    import mx.rpc.http.HTTPService;
  17.    import mx.utils.ObjectProxy;
  18.    import org.puremvc.as3.multicore.patterns.proxy.Proxy;
  19.    
  20.    public class NavMapProxy extends Proxy implements IResponder
  21.    {
  22.       public static var serverUrl:String;
  23.       
  24.       public static var analyticServerUrl:String;
  25.       
  26.       public static const NAME:String = "NavMapProxy";
  27.       
  28.       private var navMapData:ArrayCollection = new ArrayCollection();
  29.       
  30.       private var msgData:Object = new Object();
  31.       
  32.       private var channelsOnHome:ArrayCollection = new ArrayCollection();
  33.       
  34.       private var initItems:ArrayCollection = new ArrayCollection();
  35.       
  36.       private var ticker:Timer;
  37.       
  38.       private var ctrlItems:ArrayCollection = new ArrayCollection();
  39.       
  40.       private var homeViewRefreshRate:ArrayCollection = new ArrayCollection();
  41.       
  42.       private var navMapVersion:Number = 0.1;
  43.       
  44.       private var writeLog:ILogger;
  45.       
  46.       private var service:HTTPService;
  47.       
  48.       private var _timerDuration:uint = 2000;
  49.       
  50.       private var read_Navmap_Once:Boolean = false;
  51.       
  52.       private var welcomeMsg:String;
  53.       
  54.       public function NavMapProxy(param1:Object = null)
  55.       {
  56.          super(NAME,param1);
  57.          var _loc2_:String = getQualifiedClassName(this).replace("::",".");
  58.          this.writeLog = Log.getLogger(_loc2_);
  59.          this.service = new HTTPService();
  60.          this.service.method = "GET";
  61.          this.service.requestTimeout = 20;
  62.       }
  63.       
  64.       private function startTimer() : void
  65.       {
  66.          this.ticker.start();
  67.       }
  68.       
  69.       public function loadCtrlItems() : ArrayCollection
  70.       {
  71.          var _loc3_:Object = null;
  72.          var _loc1_:ArrayCollection = new ArrayCollection();
  73.          var _loc2_:int = 0;
  74.          _loc2_ = 0;
  75.          while(_loc2_ < this.ctrlItems.length)
  76.          {
  77.             _loc3_ = new Object();
  78.             _loc3_.name = this.ctrlItems[_loc2_].name;
  79.             _loc3_.title = this.ctrlItems[_loc2_].title;
  80.             _loc3_.thumbnail = this.ctrlItems[_loc2_].thumbnail;
  81.             _loc3_.thumbnail.url = this.ctrlItems[_loc2_].thumbnail.url;
  82.             _loc3_.link = this.ctrlItems[_loc2_].link;
  83.             _loc3_.notification = this.ctrlItems[_loc2_].notification;
  84.             _loc3_.view = this.ctrlItems[_loc2_].view;
  85.             _loc3_.dataType = this.ctrlItems[_loc2_].dataType;
  86.             _loc1_.addItem(_loc3_);
  87.             _loc2_++;
  88.          }
  89.          return _loc1_;
  90.       }
  91.       
  92.       public function getChannelOnHome() : ArrayCollection
  93.       {
  94.          var _loc3_:Object = null;
  95.          var _loc1_:ArrayCollection = new ArrayCollection();
  96.          var _loc2_:int = 0;
  97.          _loc2_ = 0;
  98.          while(_loc2_ < this.channelsOnHome.length)
  99.          {
  100.             _loc3_ = new Object();
  101.             _loc3_.name = this.channelsOnHome[_loc2_].name;
  102.             _loc3_.title = this.channelsOnHome[_loc2_].title;
  103.             _loc3_.description = this.channelsOnHome[_loc2_].description;
  104.             _loc3_.sf_id = this.channelsOnHome[_loc2_].sf_id;
  105.             _loc3_.thumbnail = this.channelsOnHome[_loc2_].thumbnail;
  106.             _loc3_.thumbnail.url = this.channelsOnHome[_loc2_].thumbnail.url;
  107.             _loc3_.link = this.channelsOnHome[_loc2_].link;
  108.             _loc3_.view = this.channelsOnHome[_loc2_].view;
  109.             _loc3_.dataType = this.channelsOnHome[_loc2_].dataType;
  110.             _loc1_.addItem(_loc3_);
  111.             _loc2_++;
  112.          }
  113.          return _loc1_;
  114.       }
  115.       
  116.       private function setupInitItems() : void
  117.       {
  118.          var _loc2_:ArrayCollection = null;
  119.          var _loc3_:String = null;
  120.          var _loc1_:int = 0;
  121.          while(_loc1_ < this.initItems.length)
  122.          {
  123.             _loc2_ = this.loadMenuData(this.initItems[_loc1_].link);
  124.             _loc3_ = this.initItems[_loc1_].dataType;
  125.             sendNotification(_loc3_,_loc2_);
  126.             _loc1_++;
  127.          }
  128.       }
  129.       
  130.       public function loadNavMapData() : void
  131.       {
  132.          this.sendRequest();
  133.       }
  134.       
  135.       private function get duration() : uint
  136.       {
  137.          return this._timerDuration;
  138.       }
  139.       
  140.       public function result(param1:Object) : void
  141.       {
  142.          var rpcEvent:Object = param1;
  143.          var menuBarItems:ArrayCollection = null;
  144.          var ctrlBarItems:ArrayCollection = null;
  145.          var msg:Object = null;
  146.          try
  147.          {
  148.             this.navMapVersion = rpcEvent.result.navMap.version as Number;
  149.             this.timerDuration = rpcEvent.result.navMap.expiryTime as uint;
  150.             this.navMapData = rpcEvent.result.navMap.items.item as ArrayCollection;
  151.             this.initItems = rpcEvent.result.navMap.initItems.item as ArrayCollection;
  152.             this.homeViewRefreshRate = rpcEvent.result.navMap.homeViewRefreshRate.item as ArrayCollection;
  153.             if(rpcEvent.result.navMap.channelsOnHome.item is ArrayCollection)
  154.             {
  155.                this.channelsOnHome = rpcEvent.result.navMap.channelsOnHome.item as ArrayCollection;
  156.             }
  157.             else if(rpcEvent.result.navMap.channelsOnHome.item is ObjectProxy)
  158.             {
  159.                this.channelsOnHome = new ArrayCollection();
  160.                this.channelsOnHome.addItem(rpcEvent.result.navMap.channelsOnHome.item);
  161.             }
  162.             this.ctrlItems = rpcEvent.result.navMap.ctrlItems.item as ArrayCollection;
  163.             serverUrl = rpcEvent.result.navMap.server as String;
  164.             analyticServerUrl = rpcEvent.result.navMap.analyticServer as String;
  165.             this.welcomeMsg = rpcEvent.result.navMap.welcomeMsg as String;
  166.             this.msgData = rpcEvent.result.navMap.msg as Object;
  167.             menuBarItems = this.loadMenuBarData();
  168.             ctrlBarItems = this.loadCtrlItems();
  169.             msg = this.loadMsg();
  170.             this.sendNotification(ApplicationFacade.NAVMAP_READ);
  171.             this.sendNotification(ApplicationFacade.LOAD_MENU_BAR,menuBarItems);
  172.             this.sendNotification(ApplicationFacade.LOAD_CONTROL_BAR,ctrlBarItems);
  173.             this.sendNotification(ApplicationFacade.SET_WELCOME_MSG,this.welcomeMsg);
  174.             this.sendNotification(ApplicationFacade.SET_MSG,msg);
  175.             this.setupInitItems();
  176.             this.read_Navmap_Once = false;
  177.          }
  178.          catch(errObj:Error)
  179.          {
  180.             trace(errObj.message);
  181.          }
  182.       }
  183.       
  184.       public function getHomeRefreshRate() : ArrayCollection
  185.       {
  186.          var _loc3_:Object = null;
  187.          var _loc1_:ArrayCollection = new ArrayCollection();
  188.          var _loc2_:int = 0;
  189.          _loc2_ = 0;
  190.          while(_loc2_ < this.homeViewRefreshRate.length)
  191.          {
  192.             _loc3_ = new Object();
  193.             _loc3_.name = this.homeViewRefreshRate[_loc2_].name;
  194.             _loc3_.time = this.homeViewRefreshRate[_loc2_].time;
  195.             _loc1_.addItem(_loc3_);
  196.             _loc2_++;
  197.          }
  198.          return _loc1_;
  199.       }
  200.       
  201.       public function fault(param1:Object) : void
  202.       {
  203.          var _loc2_:Fault = null;
  204.          var _loc3_:ApplicationError = null;
  205.          if(this.read_Navmap_Once == true)
  206.          {
  207.             this.sendRequestAgain();
  208.          }
  209.          else
  210.          {
  211.             _loc2_ = FaultEvent(param1).fault;
  212.             this.writeLog.error(_loc2_.faultDetail);
  213.             _loc3_ = new ApplicationError(LogEventLevel.ERROR,ApplicationFacade.ERR_NUM_NAVMAP,ApplicationFacade.ERR_NAVMAP);
  214.             sendNotification(ApplicationFacade.ERROR,_loc3_,ApplicationFacade.ERR_NAVMAP);
  215.          }
  216.       }
  217.       
  218.       private function stopTimer() : void
  219.       {
  220.          this.ticker.stop();
  221.       }
  222.       
  223.       private function fetchItems(param1:ArrayCollection, param2:Array) : ArrayCollection
  224.       {
  225.          var _loc3_:Object = null;
  226.          var _loc4_:Object = null;
  227.          if(param1 == null && param2.length != 0)
  228.          {
  229.             return null;
  230.          }
  231.          if(param1 == null && param2.length == 0)
  232.          {
  233.             return null;
  234.          }
  235.          if(param1 != null && param2.length == 0)
  236.          {
  237.             return param1;
  238.          }
  239.          var _loc5_:Number = 0;
  240.          while(_loc5_ < param1.length)
  241.          {
  242.             _loc4_ = param1.getItemAt(_loc5_);
  243.             if(_loc4_.name == param2[0])
  244.             {
  245.                _loc3_ = _loc4_;
  246.                break;
  247.             }
  248.             _loc5_++;
  249.          }
  250.          if(_loc3_ != null && Boolean(_loc3_.items))
  251.          {
  252.             param1 = _loc3_.items.item;
  253.          }
  254.          else
  255.          {
  256.             param1 = null;
  257.          }
  258.          param2.shift();
  259.          return this.fetchItems(param1,param2);
  260.       }
  261.       
  262.       private function sendRequest() : void
  263.       {
  264.          this.service.url = "http://shufflr.s3.amazonaws.com/app/config/pre_alpha/0_83/NavMap.xml";
  265.          var _loc1_:Object = {};
  266.          _loc1_["version"] = this.navMapVersion;
  267.          var _loc2_:AsyncToken = this.service.send(_loc1_);
  268.          _loc2_.addResponder(this);
  269.          this.read_Navmap_Once = true;
  270.       }
  271.       
  272.       private function onTick(param1:TimerEvent) : void
  273.       {
  274.          this.sendRequest();
  275.       }
  276.       
  277.       public function loadMenuData(param1:String) : ArrayCollection
  278.       {
  279.          var _loc2_:ArrayCollection = null;
  280.          var _loc5_:int = 0;
  281.          var _loc6_:Object = null;
  282.          var _loc3_:Array = param1.split("/");
  283.          _loc3_.shift();
  284.          var _loc4_:ArrayCollection = this.fetchItems(this.navMapData,_loc3_);
  285.          if(_loc4_ != null)
  286.          {
  287.             _loc2_ = new ArrayCollection();
  288.             _loc5_ = 0;
  289.             _loc5_ = 0;
  290.             while(_loc5_ < _loc4_.length)
  291.             {
  292.                _loc6_ = new Object();
  293.                _loc6_.name = _loc4_[_loc5_].name;
  294.                _loc6_.title = _loc4_[_loc5_].title;
  295.                _loc6_.sf_id = _loc4_[_loc5_].sf_id;
  296.                _loc6_.thumbnail = _loc4_[_loc5_].thumbnail;
  297.                _loc6_.thumbnail.url = _loc4_[_loc5_].thumbnail.url;
  298.                _loc6_.link = _loc4_[_loc5_].link;
  299.                _loc6_.notification = _loc4_[_loc5_].notification;
  300.                _loc6_.view = _loc4_[_loc5_].view;
  301.                _loc6_.dataType = _loc4_[_loc5_].dataType;
  302.                _loc6_.description = _loc4_[_loc5_].description;
  303.                _loc2_.addItem(_loc6_);
  304.                _loc5_++;
  305.             }
  306.          }
  307.          return _loc2_;
  308.       }
  309.       
  310.       private function createTimer() : void
  311.       {
  312.          this.ticker = new Timer(this._timerDuration);
  313.          this.ticker.addEventListener(TimerEvent.TIMER,this.onTick);
  314.       }
  315.       
  316.       private function set timerDuration(param1:uint) : void
  317.       {
  318.          this._timerDuration = Math.floor(param1 * 1000);
  319.          this.resetTimer();
  320.       }
  321.       
  322.       private function resetTimer() : void
  323.       {
  324.          if(this.ticker != null && this.ticker.running)
  325.          {
  326.             this.stopTimer();
  327.             this.ticker.reset();
  328.             this.ticker.removeEventListener(TimerEvent.TIMER,this.onTick);
  329.          }
  330.          this.createTimer();
  331.       }
  332.       
  333.       public function loadMenuBarData() : ArrayCollection
  334.       {
  335.          var _loc3_:Object = null;
  336.          var _loc1_:ArrayCollection = new ArrayCollection();
  337.          var _loc2_:int = 0;
  338.          _loc2_ = 0;
  339.          while(_loc2_ < this.navMapData.length)
  340.          {
  341.             _loc3_ = new Object();
  342.             _loc3_.name = this.navMapData[_loc2_].name;
  343.             _loc3_.title = this.navMapData[_loc2_].title;
  344.             _loc3_.thumbnail = this.navMapData[_loc2_].thumbnail;
  345.             _loc3_.thumbnail.url = this.navMapData[_loc2_].thumbnail.url;
  346.             _loc3_.link = this.navMapData[_loc2_].link;
  347.             _loc3_.notification = this.navMapData[_loc2_].notification;
  348.             _loc3_.view = this.navMapData[_loc2_].view;
  349.             _loc3_.dataType = this.navMapData[_loc2_].dataType;
  350.             _loc1_.addItem(_loc3_);
  351.             _loc2_++;
  352.          }
  353.          return _loc1_;
  354.       }
  355.       
  356.       private function sendRequestAgain() : void
  357.       {
  358.          this.service.url = "http://ec2-184-73-30-243.compute-1.amazonaws.com/shufflr.tv/app/config/pre_alpha/0_83/NavMap.xml";
  359.          var _loc1_:Object = {};
  360.          _loc1_["version"] = this.navMapVersion;
  361.          var _loc2_:AsyncToken = this.service.send(_loc1_);
  362.          _loc2_.addResponder(this);
  363.          this.read_Navmap_Once = false;
  364.       }
  365.       
  366.       private function loadMsg() : Object
  367.       {
  368.          var _loc1_:Object = new Object();
  369.          _loc1_.msgId = this.msgData.msgId;
  370.          _loc1_.msgText1 = this.msgData.msgText1;
  371.          _loc1_.msgText2 = this.msgData.msgText2;
  372.          return _loc1_;
  373.       }
  374.    }
  375. }
  376.  
  377.