public static void Show(GameRoomItem item, SocketSession session)
        {
            GameRoomInfoDialog info = new GameRoomInfoDialog
            {
                UserSession = session,
                Title = item.DisplayName,
                Members = item.Members,
                Logo = "http://forums.pointgaming.com/assets/logo-3b643498dc7635d6ce4598843b5fcf0e.png",
                URL = item.URL
            };

            System.ComponentModel.ICollectionView mv = CollectionViewSource.GetDefaultView(info.Members);
            mv.GroupDescriptions.Add(new PropertyGroupDescription("TeamName"));
            info.listBoxMembership.DataContext = mv;

            info.ShowDialog();
        }
 public static void LookupGameRoom(UserDataManager userData, string id, Action<GameRoomItem> onLookupResponse)
 {
     RestResponse<GameRoomSinglePoco> response = null;
     userData.PgSession.BeginAndCallback(delegate
     {
         var url = userData.PgSession.GetWebAppFunction("/api", "/game_rooms/" + id, "include_bets=true");
         var client = new RestClient(url);
         var request = new RestRequest(Method.GET);
         response = (RestResponse<GameRoomSinglePoco>)client.Execute<GameRoomSinglePoco>(request);
     }, delegate
     {
         if (response.IsOk())
         {
             var gameRoom = response.Data.game_room;
             var item = new GameRoomItem(gameRoom);
             if (onLookupResponse != null)
                 onLookupResponse(item);
         }
     });
 }
 public bool TryGetItemById(string id, out GameRoomItem item)
 {
     item = null;
     foreach (var cur in _items)
     {
         if (id == cur.Id)
         {
             item = cur;
             break;
         }
     }
     return item != null;
 }
 private void HandleRemove(GameRoomItem room, int oldIndex)
 {
     var position = room.Position;
     int countAtPosition = GetCountAtPosition(position);
     if (countAtPosition == 1 && position <= MinRoomCount)
     {
         var fake = CreateFakeRoom(position);
         _items[oldIndex] = fake;
     }
     else
     {
         _items.RemoveAt(oldIndex);
     }
 }
            public void Move(GameRoomItem room, int position)
            {
                var oldIndex = IndexOf(room);
                HandleRemove(room, oldIndex);

                room.Position = position;
                Add(room);
                CleanEnd();
            }
 public bool Remove(GameRoomItem item)
 {
     var index = IndexOf(item);
     var shouldRemove = index >= 0;
     if (shouldRemove)
     {
         HandleRemove(item, index);
         CleanEnd();
     }
     return shouldRemove;
 }
 public void Add(GameRoomItem item)
 {
     bool isAdded = false;
     var position = item.Position;
     for (int i = 0; i < _items.Count; i++)
     {
         var oldItem = _items[i];
         if (oldItem.Position == position)
         {
             if (item.Id == null)
             {
                 isAdded = true;
                 break;
             }
             else if (oldItem.Id == null)
             {
                 _items[i] = item;
                 isAdded = true;
                 CleanEnd();
                 break;
             }
             // else add it later
         }
         else if (oldItem.Position > position)
         {
             _items.Insert(i, item);
             isAdded = true;
             break;
         }
     }
     if (!isAdded)
     {
         _items.Add(item);
         CleanEnd();
     }
 }
 public int IndexOf(GameRoomItem item)
 {
     for (int i = 0; i < _items.Count; i++)
     {
         var cur = _items[i];
         if (cur == item)
             return i;
     }
     return -1;
 }
        private IEnumerable<Action> LoadGameRooms2(List<GameRoomPoco> gameRooms)
        {
            foreach (var gameRoom in gameRooms)
            {
                if (gameRoom.owner == null) continue;

                var item = new GameRoomItem(gameRoom);
                yield return delegate { GameRoomManager.Add(item); };
            }

            yield return delegate
            {
                var call = LoadGameRoomsComplete;
                if (call != null)
                    call(this);
            };

            for (int i = 0; i < MinRoomCount; i++ )
            {
                var position = i + 1;
                var fake = CreateFakeRoom(position);
                yield return delegate { GameRoomManager.Add(fake); };
            }
        }
 private void UpdateActiveGames(GameRoomItem gameRoom)
 {
     var isPresentInList = false;
     var index = 0;
     foreach (var item in ActiveGames)
         if (item.Id == gameRoom.Id)
         {
             isPresentInList = true;
             index = ActiveGames.IndexOf(item);
             break;
         }
     if (gameRoom.IsAdvertising && !isPresentInList)
         ActiveGames.Add(gameRoom);
     else if (gameRoom.IsAdvertising && isPresentInList)
     {
         ActiveGames[index] = gameRoom;
     }
     else if (!gameRoom.IsAdvertising && isPresentInList)
         ActiveGames.Remove(gameRoom);
 }
 private static GameRoomItem CreateFakeRoom(int position)
 {
     var fakeRoom = new GameRoomItem
     {
         Position = position,
         Description = "",
         MaxMemberCount = DefaultMaxGameRoomMemberCount,
     };
     return fakeRoom;
 }
 public void ToggleDisplay(GameRoomItem item)
 {
     var call = DisplayToggled;
     if (call != null)
         call(item);
 }
 public void TakeOverRoomAt(GameRoomItem item, Action<string> onCreated)
 {
     RestResponse<GameRoomPoco> response = null;
     _userData.PgSession.BeginAndCallback(delegate
     {
         var url = _userData.PgSession.GetWebAppFunction("/api", "/game_rooms/" + item.Id + "/take_over");
         var client = new RestClient(url);
         var request = new RestRequest(Method.GET) { RequestFormat = RestSharp.DataFormat.Json };
         response = (RestResponse<GameRoomPoco>)client.Execute<GameRoomPoco>(request);
     }, delegate
     {
         if (response.IsOk() && response.Data != null)
         {
             var gameRoom = response.Data;
             if (onCreated != null)
                 onCreated(gameRoom._id);
         }
         else
         {
             string reason = String.IsNullOrEmpty(response.ErrorMessage) ? response.Content : response.ErrorMessage;
             MessageDialog.Show(_window, "Join Failed", reason);
         }
     });
 }
 public void OnGameRoomNew(GameRoomPoco poco)
 {
     var item = new GameRoomItem(poco);
     GameRoomManager.Add(item);
 }
 public bool CanTakeOverRoom(GameRoomItem gameRoom)
 {
     var url = PgSession.GetWebAppFunction("/api", "/game_rooms/" + gameRoom.Id + "/can_take_over");
     var client = new RestClient(url);
     var request = new RestRequest(Method.GET) { RequestFormat = RestSharp.DataFormat.Json };
     RestResponse response = (RestResponse)client.Execute(request);
     var result = Newtonsoft.Json.Linq.JObject.Parse(response.Content);
     return Convert.ToBoolean(((Newtonsoft.Json.Linq.JProperty)result.First).Value.ToString());
 }