Esempio n. 1
0
        public async Task <PlayerSnapshot> FetchPlayerSnapshotAsync(BattleNetProfile player)
        {
            Logger.LogDebug("Getting profile {0} from server {1}", player, HttpClient.BaseAddress);
            var response = await HttpClient.GetAsync(player.ToString());

            if (!response.IsSuccessStatusCode)
            {
                Logger.LogError(new EventId(ApplicationLogging.ImportEvent),
                                "Failed to capture profile. Error: " + response.StatusCode + ": " + response.ReasonPhrase);
                return(null);
            }

            return(new PlayerSnapshot(await response.Content.ReadAsStringAsync()));
        }
Esempio n. 2
0
        /// <summary>
        /// Debug Method.
        /// </summary>
        /// <param name="profileName"></param>
        /// <returns></returns>
        public async Task <bool> ImportAndSaveProfileToCacheAsync(BattleNetProfile profileName)
        {
            //Get the save location.
            var importPath = GetProfileCacheFile(profileName, DateTime.Now);

            Logger.LogInformation(new EventId(ApplicationLogging.ImportEvent), string.Format("Caching profile to {0}", importPath));

            //!System.IO.File.Exists(importPath)
            if (await ProfileIsUpdatable(profileName))
            {
                var data = await HttpClient.GetStringAsync(profileName.ToString().Replace('#', '-'));

                System.IO.File.WriteAllText(importPath, data);
            }
            else
            {
                Logger.LogInformation(new EventId(ApplicationLogging.ImportEvent), "Skipping profile import - already cached.");
            }

            return(true);
        }