Inheritance: ObservableModel
示例#1
0
        private async Task AddGame(BadgeModel next, bool trial = false)
        {
            if (false == IsActive || _badgeBuffer.Any(w => w.Badge == next) || _badgeBuffer.Count == _badgeBuffer.Capacity)
            {
                return;
            }

            _badgeBuffer.Add(new BadgeIdlingWrapper {
                Badge = next, IsTrial = trial, Hours = next.HoursPlayed
            });
            next.IdleStopped += BadgeIdleProcessStopped;

            next.CardIdleProcess.Start();
            if (trial)
            {
                next.PropertyChanged += BadgeHoursChanged;
            }
            next.PropertyChanged += BadgeQueueStateChanged;

            // Make a short but random amount of time pass before starting next game
            var wait = _rand.Next(40, 80);

            wait = wait * 100;
            await Task.Delay(wait);
        }
示例#2
0
 private void RemoveGame(BadgeModel badge)
 {
     _badgeBuffer.RemoveAll(b => b.Badge == badge);
     badge.IdleStopped     -= BadgeIdleProcessStopped;
     badge.PropertyChanged -= BadgeHoursChanged;
     badge.PropertyChanged -= BadgeQueueStateChanged;
 }
示例#3
0
 public void RemoveBadge(BadgeModel badge)
 {
     badge.RemainingCard = 0;
     AllBadges.Remove(badge);
     IdleQueueBadges.Remove(badge);
     badge.PropertyChanged -= BadgeIdleStatusChanged;
 }
示例#4
0
        /// <summary>
        /// Processes all badges on page
        /// </summary>
        /// <param name="badges"></param>
        /// <param name="document">HTML document (1 page) from x</param>
        private void ProcessBadgesOnPage(IList <BadgeModel> badges, HtmlDocument document)
        {
            var nodes = document.DocumentNode.SelectNodes("//div[@class=\"badge_row is_link\"]");

            if (nodes == null)
            {
                return;
            }
            foreach (var badge in nodes)
            {
                var appIdNode = badge.SelectSingleNode(".//a[@class=\"badge_row_overlay\"]").Attributes["href"].Value;
                var appid     = Regex.Match(appIdNode, @"gamecards/(\d+)/").Groups[1].Value;

                if (string.IsNullOrWhiteSpace(appid) || appid == "368020" || appid == "335590" || appIdNode.Contains("border=1"))
                {
                    continue;
                }

                var hoursNode = badge.SelectSingleNode(".//div[@class=\"badge_title_stats_playtime\"]");
                var hours     = hoursNode == null ? string.Empty : Regex.Match(hoursNode.InnerText, @"[0-9\.,]+").Value;

                var nameNode = badge.SelectSingleNode(".//div[@class=\"badge_title\"]");
                var name     = WebUtility.HtmlDecode(nameNode.FirstChild.InnerText).Trim();

                var cardNode = badge.SelectSingleNode(".//span[@class=\"progress_info_bold\"]");
                var cards    = cardNode == null ? string.Empty : Regex.Match(cardNode.InnerText, @"[0-9]+").Value;

                var      progressNode = badge.SelectSingleNode(".//div[@class=\"badge_progress_info\"]");
                HtmlNode craftNode    = null;

                int current = 0, total = 0;
                if (progressNode != null)
                {
                    Match  m        = Regex.Match(progressNode.InnerText, @"([0-9]+)\s.+\s([0-9]+)");
                    string gCurrent = m.Groups[1].Value;
                    string gTotal   = m.Groups[2].Value;
                    int.TryParse(gCurrent, out current);
                    int.TryParse(gTotal, out total);

                    craftNode = progressNode.SelectSingleNode("a[@class='badge_craft_button']");
                }

                var    unlockedNode = badge.SelectSingleNode(".//div[@class=\"badge_info_title\"]");
                string unlockedName = null;
                if (unlockedNode != null)
                {
                    unlockedName = unlockedNode.InnerText.Trim();
                }

                var badgeModel = new BadgeModel(appid, name, cards, hours, current, total)
                {
                    UnlockedBadge = unlockedName,
                    CanCraft      = craftNode != null
                };

                badges.Add(badgeModel);
            }
        }
 private static void UpdateCompletion(BadgeShowcase showcase, BadgeModel badge)
 {
     showcase.UnlockedBadge = badge.UnlockedBadge;
     showcase.IsCompleted   = badge.UnlockedBadge != null;
     showcase.CanCraft      = badge.CanCraft;
     foreach (var level in showcase.CommonBadges)
     {
         level.IsCompleted = level.Name == badge.UnlockedBadge;
     }
 }
示例#6
0
        public async Task LoadShowcases(IEnumerable <BadgeModel> badges)
        {
            var        args          = new Dictionary <string, string>();
            BadgeModel badge         = null;
            int        unknownBadges = 0;

            await ReadLocalStorage();

            try
            {
                foreach (var b in badges)
                {
                    badge = b;

                    BadgeShowcase showcase;
                    _cache.TryGetValue(b.AppId, out showcase);

                    if (showcase != null)
                    {
                        UpdateCompletion(showcase, badge);
                        continue;
                    }

                    bool unknownBadge = false;
                    if (false == _cache.TryGetValue(badge.AppId, out showcase))
                    {
                        unknownBadge = true;
                        showcase     = await new SteamParser().GetBadgeShowcase(badge.AppId, args);
                        _cache.Add(badge.AppId, showcase);
                    }

                    UpdateCompletion(showcase, badge);

                    _showcases.Add(showcase);

                    if (unknownBadge)
                    {
                        unknownBadges++;
                        await Task.Delay(1500);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, String.Format("Showcase loading failed for {0}", badge.AppId));
            }
            finally
            {
                if (unknownBadges > 0)
                {
                    SaveLocalStorage();
                }
            }
        }
        public async Task<BadgeModel> GetGameInfo(string id)
        {
            var game = new BadgeModel(id, "Title", "0", "0");            

            // getting game title from store page
            var response = await DownloadString(game.StorePageUrl);
            var document = new HtmlDocument();
            document.LoadHtml(response);
            var titleNode = document.DocumentNode.SelectSingleNode("//div[@class=\"apphub_AppName\"]");
            if (titleNode != null)
                game.Title = titleNode.InnerText;

            return game;
        }
示例#8
0
        public async Task <BadgeModel> GetGameInfo(string id)
        {
            var game = new BadgeModel(id, "Title", "0", "0");

            // getting game title from store page
            var response = await DownloadString(game.StorePageUrl);

            var document = new HtmlDocument();

            document.LoadHtml(response);
            var titleNode = document.DocumentNode.SelectSingleNode("//div[@class=\"apphub_AppName\"]");

            if (titleNode != null)
            {
                game.Title = titleNode.InnerText;
            }

            return(game);
        }
示例#9
0
        private void AddGame(object o)
        {
            var selectedGame = o as GameIdentity;

            if (selectedGame == null)
            {
                return;
            }

            if (Games.Any(g => g.AppId == selectedGame.appid))
            {
                return;
            }
            Storage.Games.Add(selectedGame.appid);
            Storage.Save();
            var game = new BadgeModel(selectedGame.appid, selectedGame.name);

            game.PropertyChanged += BadgeIdleStatusChanged;
            Games.Add(game);
            GameSearch = string.Empty;
        }
示例#10
0
 public BadgeShowcase(BadgeModel badge)
     : this(badge.AppId, badge.Title)
 {
 }
 private async Task AddTrialGames(BadgeModel[] trial)
 {
     foreach (var badge in trial)
     {
         if (_badgeBuffer.Count == _badgeBuffer.Capacity)
             break;
         if (false == IsActive)
             break;
         await AddGame(badge, true);
     }
 }
 public void RemoveBadge(BadgeModel badge)
 {
     badge.RemainingCard = 0;
     AllBadges.Remove(badge);
     IdleQueueBadges.Remove(badge);
     badge.PropertyChanged -= BadgeIdleStatusChanged;
 }
 public void AddBadge(BadgeModel badge)
 {
     AllBadges.Add(badge);
     badge.PropertyChanged += BadgeIdleStatusChanged;            
 }
 private void RemoveGame(BadgeModel badge)
 {
     _badgeBuffer.RemoveAll(b=>b.Badge == badge);
     badge.IdleStopped -= BadgeIdleProcessStopped;            
     badge.PropertyChanged -= BadgeHoursChanged;
     badge.PropertyChanged -= BadgeQueueStateChanged;               
 }
示例#15
0
 public bool IsTrial(BadgeModel badge)
 {
     return(badge.HoursPlayed < TrialPeriod);
 }
示例#16
0
        /// <summary>
        /// Load account when application starts
        /// </summary>
        public async void LoadAccount()
        {
            if (String.IsNullOrWhiteSpace(Storage.SteamProfileUrl) == false)
            {
                // restore account data from Settings
                UserName = Storage.SteamUserName;
                Level    = Storage.SteamLevel;

                AvatarUrl = Storage.SteamAvatarUrl;

                BackgroundUrl = Storage.SteamBackgroundUrl;

                FavoriteBadge = new BadgeLevelData
                {
                    PictureUrl = Storage.SteamBadgeUrl,
                    Name       = Storage.SteamBadgeTitle,
                };
            }

            CustomBackgroundUrl = Storage.CustomBackgroundUrl;
            BadgePropertiesFilters.Deserialize <BadgeProperty>(Storage.BadgeFilter);

            Mode = (IdleMode)Storage.IdleMode;

            MaxIdleInstanceCount = Storage.MaxIdleProcessCount;

            PeriodicSwitchRepeatCount = Storage.PeriodicSwitchRepeatCount;

            TrialPeriod = Storage.TrialPeriod;

            SwitchMinutes = Storage.SwitchMinutes;
            SwitchSeconds = Storage.SwitchSeconds;

            IgnoreClient = Storage.IgnoreClient;

            AllowShowcaseSync = Storage.AllowShowcaseSync;
            ShowInTaskbar     = Storage.ShowInTaskbar;
            ShowBackground    = Storage.ShowBackground;

            IdleQueueBadges.CollectionChanged += IdleQueueItemsChanged;

            AllShowcases = await _showcaseManager.GetShowcases();

            ShowcasePropertiesFilters.Deserialize <ShowcaseProperty>(Storage.ShowcaseFilter);

            try
            {
                IsAuthorized = await CheckAuth();
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, "Could not authorize");
            }

            if (IsAuthorized)
            {
                await InitProfile();
            }

            _steamApps = await SteamParser.GetSteamApps();

            // reload games list
            var games = Storage.Games.Cast <string>().ToList();
            int idx   = 0;

            foreach (var id in games)
            {
                GameIdentity app;
                _steamApps.TryGetValue(id, out app);

                var game = new BadgeModel(id, app != null ? app.name : "");
                game.PropertyChanged += BadgeIdleStatusChanged;
                Games.Insert(idx, game);
                idx++;
            }
        }
        private async Task AddGame(BadgeModel next, bool trial = false)
        {
            if (_badgeBuffer.Any(w=>w.Badge == next) || _badgeBuffer.Count == _badgeBuffer.Capacity)
                return;
            _badgeBuffer.Add(new BadgeWrapper{Badge = next, IsTrial = trial, Hours = next.HoursPlayed});            
            next.IdleStopped += BadgeIdleProcessStopped;

            next.CardIdleProcess.Start();            
            if (trial)
                next.PropertyChanged += BadgeHoursChanged;
            next.PropertyChanged += BadgeQueueStateChanged;            

            // Make a short but random amount of time pass before starting next game
            var wait = _rand.Next(40, 80);
            wait = wait * 100;
            await Task.Delay(wait);
        }
示例#18
0
 public void AddBadge(BadgeModel badge)
 {
     AllBadges.Add(badge);
     badge.PropertyChanged += BadgeIdleStatusChanged;
 }