public void ValidBattleNetTag(string playername, string tag)
        {
            var profile = BattleNetProfile.ParseTag(string.Format("{0}#{1}", playername, tag));

            Assert.Equal(playername, profile.Name);
            Assert.Equal(tag, profile.Tag);
        }
Esempio n. 2
0
        public async Task <bool> ProfileIsUpdatable(BattleNetProfile profile)
        {
            //Temp

            //Check if the file exists, if it does not - profile is updatable.
            //If it does exist, check timestamp

            return(await Task.Run(() => true));
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="profile">BattleNet Profile.</param>
        /// <param name="datetime">Date of the cache file.</param>
        /// <returns></returns>
        private string GetProfileCacheFile(BattleNetProfile profile, DateTime datetime)
        {
            var importPath = CacheDirectory;

            importPath += datetime.Date.Ticks + @"\";
            System.IO.Directory.CreateDirectory(importPath);

            importPath += profile + ".html";

            return(importPath.Replace('#', '-'));
        }
Esempio n. 4
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. 5
0
        public static void Main(string[] args)
        {
            ApplicationLogging.LoggerFactory.AddConsole();
            var logger = ApplicationLogging.CreateLogger <Program>();

            var importer = new Importer(SettingsManager.ApplicationSettings.ServerPath);

            var f = Parallel.ForEach(
                SettingsManager.ApplicationSettings.Profiles,
                new ParallelOptions {
                MaxDegreeOfParallelism = SettingsManager.ApplicationSettings.MaxScrapperThreads
            },
                (s, state, arg3) =>
            {
                Console.WriteLine("Fetching profile " + s);
                try
                {
                    var task = importer.ImportAndSaveProfileToCacheAsync(BattleNetProfile.ParseTag(s));
                    task.Wait();
                }
                catch (Exception ex)
                {
                    logger.LogError(new EventId(ApplicationLogging.ImportEvent), string.Format("Failed to import profile {0}. Error: {1}", s, ex.Message));
                }
            });

            // Debug / code can be remove for production...

            var dateDirs = Directory.GetDirectories(SettingsManager.ApplicationSettings.SaveLocation);

            foreach (var dir in dateDirs)
            {
                var date = new DateTime(Convert.ToInt64(Path.GetFileName(dir)));

                foreach (var p in SettingsManager.ApplicationSettings.Profiles)
                {
                    var filename = dir + Path.DirectorySeparatorChar + p.Replace('#', '-') + ".html";
                    if (File.Exists(filename))
                    {
                        var snapshot = new PlayerSnapshot(File.ReadAllText(filename));
                        snapshot.ParseHtml();
                        logger.LogInformation(new EventId(ApplicationLogging.ImportEvent), "{0} has won {1} games as of {2}", p, snapshot.GamesWon, date.ToString("D"));
                        logger.LogInformation(snapshot.PlayerIcon.ToString());
                    }
                }
            }

            Console.WriteLine("Completed fetching profiles.");
        }
Esempio n. 6
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);
        }
 public void InvalidBattleTagSep()
 {
     Assert.Throws <ArgumentException>(() => BattleNetProfile.ParseTag("RavenKnight_1137"));
 }
 public void InvalidBattleTagPartialName()
 {
     Assert.Throws <ArgumentException>(() => BattleNetProfile.ParseTag("RavenKnight"));
 }
 public void InvalidBattleTagName()
 {
     Assert.Throws <ArgumentException>(() => BattleNetProfile.ParseTag("#1137"));
 }