Exemplo n.º 1
0
        public static async Task <PostResult> UploadArenaMatchAsync(GameStats game, Deck deck, bool saveFilesAfter = false,
                                                                    bool background = false)
        {
            Logger.WriteLine("trying to upload arena match: " + game, "HearthStatsManager");
            if (!HearthStatsAPI.IsLoggedIn)
            {
                Logger.WriteLine("error: not logged in", "HearthStatsManager");
                return(PostResult.Failed);
            }
            if (background)
            {
                AddBackgroundActivity();
            }
            if (!deck.HasHearthStatsArenaId)
            {
                Logger.WriteLine("...deck has no HearthStatsArenaId, creating arena run", "HearthStatsManager");
                var createRun = await CreateArenaRunAsync(deck, false, background);

                if (!createRun.Success)
                {
                    Logger.WriteLine("error: could not create arena run.", "HearthStatsManager");
                    if (background)
                    {
                        RemoveBackgroundActivity();
                    }
                    return(PostResult.Failed);
                }
            }
            var result = await HearthStatsAPI.PostArenaMatch(game, deck);

            if (!result.Success && result.Retry)
            {
                await Task.Delay(RetryDelay);

                Logger.WriteLine("try #2 to upload arena match: " + game, "HearthStatsManager");
                result = await HearthStatsAPI.PostArenaMatch(game, deck);
            }
            if (result.Success && saveFilesAfter)
            {
                DeckStatsList.Save();
            }
            if (background)
            {
                RemoveBackgroundActivity();
            }
            if (result.Success)
            {
                Logger.WriteLine("success uploading arena match " + game, "HearthStatsManager");
            }
            return(result);
        }