private async Task ReadLocalStorage() { if (_cache != null) { return; } _cache = new Dictionary <string, BadgeShowcase>(); string db = Storage.ReadContent(); if (String.IsNullOrWhiteSpace(db)) { return; } var apps = await SteamParser.GetSteamApps(); try { var xml = XDocument.Parse(db).Root; if (xml != null) { foreach (var xeBadge in xml.Elements("badge")) { var appId = (string)xeBadge.Attribute("app_id"); string title = appId; GameIdentity app; bool marketable = apps.TryGetValue(appId, out app); if (marketable) { title = app.name; } var showcase = new BadgeShowcase(appId, title); showcase.IsMarketable = marketable; BadgeStockModel stock; if (_pricesUpdater.Prices.TryGetValue(appId, out stock)) { showcase.CardPrice = stock.CardValue; showcase.BadgePrice = stock.Normal; if (!marketable) { showcase.Title = stock.Name; } } foreach (var xeLevel in xeBadge.Elements("level")) { showcase.CommonBadges.Add(BadgeFromXml(xeLevel)); } var xeFoil = xeBadge.Element("foil"); if (xeFoil != null) { var foilBadge = BadgeFromXml(xeFoil); if (false == String.IsNullOrEmpty(foilBadge.PictureUrl)) { showcase.FoilBadge = foilBadge; } } _cache.Add(appId, showcase); } } Logger.Info("Showcase storage initialized"); } catch (Exception ex) { Logger.Exception(ex, "Showcase storage"); } }
/// <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++; } }