예제 #1
0
        private void SteamId(string steamIdString)
        {
            ulong steamid;

            try
            {
                steamid = ulong.Parse(steamIdString);
            }
            catch (FormatException e)
            {
                MessageBox.Show(e.Message);
                return;
            }
            task = SteamServiceExt.GetPlayerSummaryAsync(steamid);
            task.ContinueWith((result) =>
            {
                Player user = result.Result.Players[0];
                Username    = user.PersonaName;
                SteamID     = user.SteamId;

                ImageSource image = SteamServiceExt.GetAvatar(user);
                image.Freeze();
                Avatar = image;

                steamlist.Username   = Username;
                steamlist.SteamID    = SteamID;
                steamlist.GameList   = new List <Game>();
                steamlist.IgnoreList = new List <Game>();

                OwnerViewModel.GameList   = new ObservableCollection <Game>(steamlist.GameList);
                OwnerViewModel.IgnoreList = new ObservableCollection <Game>(steamlist.IgnoreList);
                FileService.SaveFile(steamlist);
            });
        }
예제 #2
0
        private async void UpdateGameListAsync()
        {
            updateGameListWorking = true;
            var task = SteamServiceExt.GetOwnedGamesAsync(steamList.SteamID);
            await task.ContinueWith((result) =>
            {
                //After web response is received, continue here
                var newList      = result.Result.Games;
                var itemsTasks   = 0;
                var itemsAdded   = 0;
                object itemsLock = new object();
                var comparator   = new AlphabeticComparer();
                //Start adding games to the game list
                lock (itemsLock)
                {
                    foreach (Game item in newList)
                    {
                        // If item is in another list already, don't add it
                        if (ignoreList.BinarySearch(item, comparator) < 0)
                        {
                            itemsTasks++;
                            Application.Current.Dispatcher.BeginInvoke((ThreadStart) delegate
                            {
                                bool added = false;
                                lock (gameList)
                                {
                                    if (gameList.Count == 0)
                                    {
                                        gameList.Add(item);
                                        GameList.Add(item);
                                        OnPropertyChanged("GameList");
                                        added = true;
                                    }
                                    if (comparator.Compare(gameList[gameList.Count - 1], item) < 0)
                                    {
                                        gameList.Add(item);
                                        GameList.Add(item);
                                        OnPropertyChanged("GameList");
                                        added = true;
                                    }
                                    if (comparator.Compare(gameList[0], item) > 0)
                                    {
                                        gameList.Insert(0, item);
                                        GameList.Insert(0, item);
                                        OnPropertyChanged("GameList");
                                        added = true;
                                    }
                                    int index = gameList.BinarySearch(item, comparator);
                                    // If index is negative, item is not present in list. Positive index means item is present in the list.
                                    if (index < 0)
                                    {
                                        index = ~index;
                                        gameList.Insert(index, item);
                                        GameList.Insert(index, item);
                                        OnPropertyChanged("GameList");
                                        added = true;
                                    }
                                }
                                lock (itemsLock)
                                {
                                    itemsTasks--;
                                    if (added)
                                    {
                                        itemsAdded++;
                                    }
                                }
                            });
                        }
                    }
                    //Create thread to show message when all tasks are done
                    new Thread(() =>
                    {
                        bool finished = false;
                        while (!finished)
                        {
                            Thread.Sleep(100);
                            lock (itemsLock)
                            {
                                if (itemsTasks == 0)
                                {
                                    FileService.SaveFile(steamList);
                                    MessageBox.Show(itemsAdded + " games added to game list");
                                    updateGameListWorking = false;
                                    finished = true;
                                }
                            }
                        }
                    }).Start();
                }
            });

            return;
        }
예제 #3
0
 public void Start(int finalIndex)
 {
     this.mainImage.Source = ImageService.GetLogoPlaceholder();
     logoTask = SteamServiceExt.GetLogoAsync(gameList[finalIndex]);
 }