Пример #1
0
 private static AsyncDelegation NewAD(string baseUri)
 {
     RestFacilitator restFacilitator = new RestFacilitator();
     RestService restService = new RestService(restFacilitator, baseUri);
     AsyncDelegation asyncDelegation = new AsyncDelegation(restService);
     return asyncDelegation;
 }
Пример #2
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();
        }
Пример #3
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 void RightButtonPush()
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Post("add", new {Name="MonoTouch Name" })
         .WhenFinished(()=> {
             PullData();
         });
     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();
        }
Пример #8
0
 private void AddGame(string gameId, string gameName)
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation
         .Post("add", new { id = gameId, name=gameName })
             .WhenFinished(()=>{JoinGame(gameId);})
             .Go();
 }
        /// <summary>
        /// Request from the view to hunt.
        /// </summary>
        public void Hunt()
        {
            //return if the current zombie pack id is 0
            if (_currentZombiePackId == Guid.Empty)
            {
                return;
            }

            if (_currentZombiePackInfo != null && _currentZombiePackInfo.CostPerHunt > _gameContext.UserEnergy.CurrentEnergy)
            {
                _notificationView.Notify("You do not have enough energy to hunt here.  Use an item to replenish your energy, equip armor to raise your maximum energy, or simply wait for your energy to replenish.  You will regain energy over time.");
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            //perform hunt
            ad.Post(
              new
              {
                  controller = "ZombiePacks",
                  action = "Hunt",
                  userId = _gameContext.UserId,
                  zombiePackId = _currentZombiePackId
              })
                //when finished do nothing
              .WhenFinished(() => { })
              .ThenGet<UserInGameStats>(new { controller = "Users", action = "Stats", userId = _gameContext.UserId })
              .WhenFinished(
              (data) =>
              {
                  _gameContext.SetUserEnergy(data.EnergyResult);
                  _gameContext.SetUserInventory(data.Items);
                  _gameContext.SetUserAttackPower(data.AttackPower.Value);
                  _gameContext.SetMoney(data.Money.Value);
                  _gameContext.SetUserMaxItems(data.MaxItems.Value);
                  _gameContext.SetUserLevel(data.LevelResult);
              })
              //check to see if the zombie pack is cleared
              .ThenGet<BooleanResult>(
              new
              {
                  controller = "ZombiePacks",
                  action = "IsCleared",
                  userId = _gameContext.UserId,
                  zombiePackId = _currentZombiePackId
              })
                //when the zombie pack data is returned
              .WhenFinished(
              (booleanResult) =>
              {
                  //if the zombie pack has been destroyed
                  if (booleanResult.Value == true)
                  {
                      //find the zombie pack
                      Node node = _visibleZombiePacks.FirstOrDefault(c => c.Id == _currentZombiePackId);
                      if (node != null)
                      {
                          //remove the node from visible nodes
                          _visibleZombiePacks.Remove(node);

                          //notify to the game context that a zombie pack has been destroyed
                          List<Guid> nodes = new List<Guid>();
                          nodes.Add(node.Id);
                          _mapPresenterView.RemoveZombiePacks(nodes);

                          //set the zombie pack to guid.empty
                          _currentZombiePackId = Guid.Empty;

                          //if the zombie pack has been cleared, determine if the hotzone has been cleared and update the hunt status of the user
                          _gameContext.NotifyZombiePackDestroyed(node.Id);
                          UpdateHuntStatus();
                      }
                  }
                  else
                  {
                      //if the zombie pack hasn't been destroyed, update hunt status to reflect new destruction amounts.
                      UpdateHuntStatus();
                  }
              });

            ad.Go();
        }
Пример #10
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 ();
 }
        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();
            }
        }
        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 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();
 }
        internal void TransferItemFromSafeHouseToUser(Guid itemId)
        {
            if (_gameContext.UserInventory.Count >= _gameContext.UserMaxItems)
            {
                _notificationView.Notify("You cannot equip any more items.  Move items to the safe house first to create more space.");
                return;
            }

            SafeHouseNode currentSafeHouse = GetCurrentSafeHouse();
            if (currentSafeHouse == null)
            {
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            ad.Post(
                new
                {
                    controller = "SafeHouses",
                    action = "UserRetrieveItem",
                    userId = _gameContext.UserId,
                    safeHouseId = currentSafeHouse.Id,
                    itemId = itemId
                })
                .WhenFinished(() =>
                {
                    GetUserInventory();
                    GetSafeHouseInventory();
                });

            ad.Go();
        }
        public void Buy(Item item)
        {
            if (item.Price > _gameContext.Money)
            {
                _notificationView.Notify("You don't have enough money to buy this item.  Go hunt for more zombies and come back when you do.");
                return;
            }

            if (_gameContext.UserInventory.Count >= _gameContext.UserMaxItems)
            {
                _notificationView.Notify("You can't carry any more items.  Go to the safe house and drop some items off, then come back.");
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            ad.Post(
                new
                {
                    controller = "Users",
                    action = "BuyItem",
                    userId = _gameContext.UserId,
                    itemId = item.Id
                })
                .WhenFinished(() => { })
                .ThenGet<IntResult>(new { controller = "Users", action = "Money", userId = _gameContext.UserId })
                .WhenFinished(r =>
                {
                    _gameContext.SetMoney(r.Value);
                    GetUserMoney();
                    GetUserInventory();
                });

            ad.Go();

        }
Пример #16
0
 void ReadyForNextRound()
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Post("readyForNextRound", new {gameId = _gameId, playerId = Application.PlayerId})
         .WhenFinished(()=> {
             shouldPool = true;
             PollGameData();
         });
     asyncDelegation.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 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 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();
        }
Пример #20
0
 void JoinGame(string gameId)
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Post("joingame", new {gameId = gameId, playerId = Application.PlayerId, playerName = "Mono Touch"})
         .WhenFinished(()=> {
             var gameView = new GameViewController(gameId);
             this.NavigationController.PushViewController(gameView, true);
         });
     asyncDelegation.Go();
 }
        internal void TransferItemFromUserToSafeHouse(Guid itemId)
        {
            SafeHouseNode currentSafeHouse = GetCurrentSafeHouse();
            if (currentSafeHouse == null)
            {
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            ad.Post(
                new
                {
                    controller = "SafeHouses",
                    action = "StoreItem",
                    userId = _gameContext.UserId,
                    safeHouseId = currentSafeHouse.Id,
                    itemId = itemId
                })
                .WhenFinished(() =>
                {
                    GetUserInventory();
                    GetSafeHouseInventory();
                });

            ad.Go();
        }
Пример #22
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 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();
        }
        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();
        }
Пример #25
0
        void SelectCard(string cardId)
        {
            var asyncDelegation = new AsyncDelegation (restService);

            if (_isCzar) {
                asyncDelegation.Post ("selectWinner", new {gameId = _gameId, cardId = cardId})
                .WhenFinished (() => {
                    FetchGame ();
                });
                asyncDelegation.Go ();
            } else {
                asyncDelegation.Post ("selectCard", new {gameId = _gameId, playerId = Application.PlayerId, whiteCardId = cardId})
                    .WhenFinished (() => {
                        FetchGame ();
                    });
                asyncDelegation.Go ();
            }
        }
Пример #26
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 AddGame(Guid gameId, string gameName)
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation
         .Post("add", new { id = gameId.ToString(), name=gameName })
             .WhenFinished(() => FetchGames());
     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();
        }