コード例 #1
0
        public async Task UpdateProgress(IProgress <string> progress, CancellationToken cancellation)
        {
            if (SteamIdHelper.Instance.Value == null)
            {
                throw new InformativeException("Can’t get challenges progress", "Steam ID is missing.");
            }

            progress.Report("Finishing preparing…");
            await EnsureLoadedAsync();

            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            progress.Report("Loading stats…");
            string[] achievments;
            try {
                achievments = await Task.Run(() => SteamWebProvider.GetAchievments(CommonAcConsts.AppId, SteamIdHelper.Instance.Value), cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return;
                }
            } catch (WebException e)
                when(e.Status == WebExceptionStatus.ProtocolError && (e.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.InternalServerError)
                {
                    throw new InformativeException("Can’t get challenges progress because of internal server error (500)", "Make sure Steam account isn’t private.");
                }

            foreach (var eventObject in LoadedOnly)
            {
                eventObject.TakenPlace = 5;
            }

            foreach (var achievment in achievments.Where(x => x.StartsWith(@"SPECIAL_EVENT_")))
            {
                var id    = achievment.Substring(0, achievment.Length - 2);
                var place = FlexibleParser.TryParseInt(achievment.Substring(achievment.Length - 1));

                var eventObject = GetById(id);
                if (eventObject == null || !place.HasValue)
                {
                    continue;
                }

                eventObject.TakenPlace = Math.Min(eventObject.TakenPlace, (eventObject.ConditionType == null ? 4 : 3) - place.Value);
            }
        }