Пример #1
0
        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);
        }
Пример #2
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.");
        }
Пример #3
0
 public void InvalidBattleTagSep()
 {
     Assert.Throws <ArgumentException>(() => BattleNetProfile.ParseTag("RavenKnight_1137"));
 }
Пример #4
0
 public void InvalidBattleTagPartialName()
 {
     Assert.Throws <ArgumentException>(() => BattleNetProfile.ParseTag("RavenKnight"));
 }
Пример #5
0
 public void InvalidBattleTagName()
 {
     Assert.Throws <ArgumentException>(() => BattleNetProfile.ParseTag("#1137"));
 }