Esempio n. 1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var baseUri = "http://search.twitter.com/";

            var restFacilitator = new RestFacilitator();

            var restService = new RestService(restFacilitator, baseUri);

            var asyncDelegation = new AsyncDelegation(restService);

            //call http://search.twitter.com/search.json?q=#haiku
            asyncDelegation.Get<Hash>("search.json", new { q = "#haiku" })
                           .WhenFinished(
                           result =>
                           {
                               List<string> tweets = new List<string>();
                               textBlockTweets.Text = "";
                               foreach (var tweetObject in result["results"].ToHashes())
                               {
                                   textBlockTweets.Text += HttpUtility.HtmlDecode(tweetObject["text"].ToString()) + Environment.NewLine + Environment.NewLine;
                               }
                           });

            asyncDelegation.Go();
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var baseUri = "http://search.twitter.com/";

            var restFacilitator = new RestFacilitator();

            var restService = new RestService(restFacilitator, baseUri);

            var asyncDelegation = new AsyncDelegation(restService);

            asyncDelegation.Get<TwitterProxy.twitterresults>("search.json", new { q = "#haiku" })
                           .WhenFinished(
                           result =>
                           {
                               List<string> tweets = new List<string>();
                               textBlockTweets.Text = "";
                               tweets = result.results.Select(s => s.text).ToList();
                               foreach (string tweet in tweets)
                               {
                                   textBlockTweets.Text += HttpUtility.HtmlDecode(tweet) + Environment.NewLine + Environment.NewLine;
                               }
                           });

            asyncDelegation.Go();
        }
 public override void ViewDidAppear(bool animated)
 {
     base.ViewDidAppear (animated);
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Get<Hash>("gamebyid", new { id = _gameId })
         .WhenFinished(
             result =>
             {
             Title = result["name"].ToString();
             JsonVisualization jsonVisualization = new JsonVisualization();
             jsonVisualization.Parse("root", result, 0);
             TextView.Text = jsonVisualization.JsonResult;
         });
     asyncDelegation.Go();
 }
        private void GetStoresForHotZone(Guid hotZoneId)
        {
            AsyncDelegation ad = new AsyncDelegation();
            ad.Get<List<StoreNode>>().ForRoute(() => new { controller = "Stores", action = "InHotZone", userId = _gameContext.UserId })
              .WhenFinished(r =>
              {
                  _mapPresenterView.RemoveStores(_visibleStores);

                  _visibleStores.Clear();
                  foreach (StoreNode safeHouse in r)
                  {
                      _visibleStores.Add(safeHouse);
                  }

                  _mapPresenterView.AddStores(_visibleStores);

                  CheckCanShop();
              });

            ad.Go();
        }
        void PullData()
        {
            var asyncDelegation = new AsyncDelegation(restService);

            asyncDelegation.Get<Hashes>("list", new { })
                .WhenFinished(
                    result =>
                    {
                    peeps.Clear();
                    foreach (var peep in result)
                    {
                        peeps.Add(peep["Name"].ToString());
                    }
                    table.ReloadData();
                });

            asyncDelegation.Go();
        }
        private void GetZombiePackInfo()
        {
            if (_currentZombiePackId == Guid.Empty) return;

            AsyncDelegation ad = new AsyncDelegation();
            ad.Get<ZombiePackProgress>(new
            {
                controller = "ZombiePacks",
                action = "DestructionProgress",
                userId = _gameContext.UserId,
                zombiePackId = _currentZombiePackId
            })
            .WhenFinished(r =>
            {
                _currentZombiePackInfo = r;
                _view.PopulateDestructionProgress(r.ZombiesLeft, r.MaxZombies, r.CostPerHunt);
            });

            ad.Go();
        }
        private void UpdateZombiePacksIfApplicable()
        {
            AsyncDelegation ad = new AsyncDelegation();
            ad.Get<GuidResult>(new { controller = "Users", action = "Zone", userId = _gameContext.UserId })
              .WhenFinished(r =>
                  {
                      if (r.Value == _currentHotZoneId)
                      {
                          UpdateHuntStatus();
                      }
                      else
                      {
                          _currentHotZoneId = r.Value;
                          GetZombiePacksForHotZone(_currentHotZoneId);
                      }
                  });

            ad.Go();
        }
Esempio n. 8
0
        public void Calculate()
        {
            RestFacilitator rf;
            rf = new RestFacilitator();

            RestService rs = new RestService(rf, _baseUri);
            AsyncDelegation ad = new AsyncDelegation(rs);

            int temp = 0;

            ad.Get<dynamic>(
            "Calculator/Add",
            new
            {
                x = X,
                y = Y
            })
            .WhenFinished(r => temp = (int)r.Value)
            .ThenGet<dynamic>("Calculator/Subtract").ForRoute(
            () => new
            {
                x = temp,
                y = Subtract
            })
            .WhenFinished(r => temp = (int)r.Value)
            .ThenGet<dynamic>("Calculator/Multiply").ForRoute(
            () => new
            {
                x = temp,
                y = Multiply
            })
            .WhenFinished(r => Answer = (int)r.Value);

            ad.Go();
        }
        private void GetUserInventory()
        {
            AsyncDelegation ad = new AsyncDelegation();

            ad.Get<List<Item>>(
                new
                {
                    controller = "Users",
                    action = "Items",
                    userId = _gameContext.UserId
                })
                .WhenFinished(
                (items) =>
                {
                    _gameContext.SetUserInventory(items.OrderBy(i => i.Name).ToList());
                });

            ad.Go();
        }
        private void DetermineIfHotZoneCleared()
        {
            Guid previousHotZoneId = _currentHotZoneId;
            AsyncDelegation ad = new AsyncDelegation();

            //get teh current zone the user is in
            ad.Get<GuidResult>(new { controller = "Users", action = "Zone", userId = _gameContext.UserId })
                //for that zone, determine if there are any zombie packs left
              .WhenFinished(
              (result) =>
              {
                  _currentHotZoneId = result.Value;
                  ShowHideCurrentHotZone(previousHotZoneId, _currentHotZoneId, forceUpdate: false);
              })
              .ThenGet<IntResult>().ForRoute(() => new { controller = "HotZones", action = "ZombiePacksLeft", userId = _gameContext.UserId, hotZoneId = _currentHotZoneId })
                //updae the ZombiePacks count to reflect the counts returned by Hotzones/ZombiePacksLeft
              .WhenFinished(
              (zombiePackCount) =>
              {
                  //update zombie pack counts
                  KeyValuePair<Guid, int>? kvp = _zombiePackCounts.SingleOrDefault(c => c.Key == _currentHotZoneId);
                  if (kvp != null)
                  {
                      _zombiePackCounts.Remove(kvp.Value);
                      _zombiePackCounts.Add(new KeyValuePair<Guid, int>(_currentHotZoneId, zombiePackCount.Value));
                  }

                  //if the zombie pack count is 0 then that means the hotzone is destroyed.  Notify game context that the hotzone has been destroyed.
                  if (zombiePackCount.Value == 0)
                  {
                      _mapPresenterView.UpdateHotZoneClearedStatus(_currentHotZoneId, true);
                  }
              });

            ad.Go();
        }
        private void GetInventory()
        {
            StoreNode currentStore = _visibleStores.SingleOrDefault(c => c.Latitude == _gameContext.UserNode.Latitude && c.Longitude == _gameContext.UserNode.Longitude);
            if (currentStore == null)
            {
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();
            ad.Get<List<Item>>(new
            {
                controller = "Stores",
                action = "Items",
                storeId = currentStore.Id
            })
            .WhenFinished(
            (items) =>
            {
                _view.PopulateStoreInventory(items.OrderBy(i => i.Name).ToList());
            });

            ad.Go();
        }
        private void UpdateZone(bool forceUpdate)
        {
            Guid previousHotZoneId = _currentHotZoneId;
            //show the hotzone the user is currently associated with on the map
            AsyncDelegation ad = new AsyncDelegation();

            //get teh current zone the user is in
            ad.Get<GuidResult>(new { controller = "Users", action = "Zone", userId = _gameContext.UserId })
                //for that zone, determine if there are any zombie packs left
              .WhenFinished(
              (result) =>
              {
                  _currentHotZoneId = result.Value;
                  ShowHideCurrentHotZone(previousHotZoneId, _currentHotZoneId, forceUpdate);
              });

            ad.Go();
        }
        private void LoadHotZones()
        {
            //initalize the hotzones if they have not been initialized yet
            if (_hotZones == null)
            {
                //on the retrieval of hozones, populate honzones on the map.
                AsyncDelegation ad2 = new AsyncDelegation();

                ad2.Get<List<HotZoneNode>>(new { controller = "HotZones", action = "Index", userId = _gameContext.UserId })
                    .WhenFinished(
                    (hotZones) =>
                    {
                        _hotZones = hotZones;
                    })
                    .ThenGet<List<KeyValuePair<Guid, int>>>(new { controller = "HotZones", action = "Uncleared", userId = _gameContext.UserId })
                    .WhenFinished(
                    (uncleared) =>
                    {
                        _zombiePackCounts = uncleared;
                        List<Guid> clearedHotZones =
                            _hotZones.Where(h => _zombiePackCounts.Any(z => z.Key == h.Id) == false)
                                     .Select(h => h.Id)
                                     .ToList();

                        foreach (Guid id in clearedHotZones)
                        {
                            _mapPresenterView.UpdateHotZoneClearedStatus(id, true);
                        }

                        UpdateZone(forceUpdate: false);
                        DetermineIfOnHotZone();
                    });

                ad2.Go();
            }
        }
Esempio n. 14
0
 void FetchGame()
 {
     var asyncDelegation = new AsyncDelegation (restService);
     asyncDelegation.Get<Game> ("gamebyid", new {
         id = _gameId,
         playerId = Application.PlayerId
     }).WhenFinished (result =>  {
         InvokeOnMainThread (() =>  {
             UpdateView (result);
         });
     });
     asyncDelegation.Go ();
 }
Esempio n. 15
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var baseUri = "http://search.twitter.com/";

            var restFacilitator = new RestFacilitator();

            var restService = new RestService(restFacilitator, baseUri);

            var asyncDelegation = new AsyncDelegation(restService);

            asyncDelegation.Get<Hash>("search.json", new { q = "#haiku" })
                           .WhenFinished(
                               result =>
                               {
                                   JsonVisualization jsonVisualization = new JsonVisualization();
                                   jsonVisualization.Parse("root", result, 0);
                                   textBlockTweets.Text = jsonVisualization.JsonResult;
                               });

            asyncDelegation.Go();
        }
        private void GetZombiePacksForHotZone(Guid hotZoneId)
        {
            AsyncDelegation ad = new AsyncDelegation();
            ad.Get<List<ZombiePackNode>>().ForRoute(() => new { controller = "ZombiePacks", action = "InHotzone", userId = _gameContext.UserId })
              .WhenFinished(r =>
               {
                   _mapPresenterView.RemoveZombiePacks(_visibleZombiePacks.Select(s => s.Id).ToList());

                   _visibleZombiePacks.Clear();
                   foreach (ZombiePackNode zombiePack in r)
                   {
                       _visibleZombiePacks.Add(zombiePack);
                   }

                   _mapPresenterView.AddZombiePacks(_visibleZombiePacks);

                   UpdateHuntStatus();
               });

            ad.Go();
        }
 private void FetchGames()
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Get<Hashes>("list", new { q = "list" })
         .WhenFinished(
             result =>
             {
             // Web games Section
             var tGroup = new TableItemGroup{ Name = "Active Games"};
             foreach(var hash in result)
             {
                 tGroup.Items.Add(hash["name"].ToString());
                 tGroup.ItemIds.Add(new Guid(hash["id"].ToString()));
             }
             _games.Clear();
             _games.Add(tGroup);
             InvokeOnMainThread(GamesTable.ReloadData);
         });
     asyncDelegation.Go();
 }
        private void GetUserInventory()
        {
            AsyncDelegation ad = new AsyncDelegation();

            ad.Get<List<Item>>(
                new
                {
                    controller = "Users",
                    action = "Items",
                    userId = _gameContext.UserId
                })
                .WhenFinished(
                (items) =>
                {
                    var orderedList = items.OrderBy(s => s.Name).ToList();
                    _view.PopulateUserInventory(orderedList);
                    _gameContext.SetUserInventory(orderedList);
                });

            ad.Go();
        }