Ejemplo n.º 1
0
        public static void StoreData(string path, R6StatsData minervaPlayer)
        {
            //Checks all the files in the given directory
            DirectoryInfo d = new DirectoryInfo(path);

            FileInfo[] Files = d.GetFiles("*.json");

            foreach (FileInfo file in Files)
            {
                if (file.Name.Contains(minervaPlayer._Nick))
                {
                    UpdateData(path + file.Name, minervaPlayer);
                    return;
                }
            }

            // serialize JSON to a string and then write string to a file
            Guid id = Guid.NewGuid();

            File.WriteAllText(path + minervaPlayer._Nick + " " + id + ".json", JsonConvert.SerializeObject(minervaPlayer));

            // serialize JSON directly to a file
            using (StreamWriter file = File.CreateText(path + minervaPlayer._Nick + " " + id + ".json"))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, minervaPlayer);
            }
        }
Ejemplo n.º 2
0
        public static void UpdateData(string path, R6StatsData minervaPlayer)
        {
            // read file into a string and deserialize JSON to a type
            R6StatsData storedPlayer = JsonConvert.DeserializeObject <R6StatsData>(File.ReadAllText(path));

            PlayerData player = new PlayerData
            {
                RankedWins       = Utils.Parse(minervaPlayer.RankedWins, storedPlayer.RankedWins),
                RankedKills      = Utils.Parse(minervaPlayer.RankedKills, storedPlayer.RankedKills),
                RankedDeaths     = Utils.Parse(minervaPlayer.RankedDeaths, storedPlayer.RankedDeaths),
                RankedLosses     = Utils.Parse(minervaPlayer.RankedLosses, storedPlayer.RankedLosses),
                RankedTimePlayed = Utils.Parse(Utils.DateToMinute(minervaPlayer.RankedTimePlayed).ToString(), Utils.DateToMinute(storedPlayer.RankedTimePlayed).ToString()).ToString() + " minutos",

                CasualWins       = Utils.Parse(minervaPlayer.CasualWins, storedPlayer.CasualWins),
                CasualKills      = Utils.Parse(minervaPlayer.CasualKills, storedPlayer.CasualKills),
                CasualDeaths     = Utils.Parse(minervaPlayer.CasualDeaths, storedPlayer.CasualDeaths),
                CasualLosses     = Utils.Parse(minervaPlayer.CasualLosses, storedPlayer.CasualLosses),
                CasualTimePlayed = Utils.Parse(Utils.DateToMinute(minervaPlayer.CasualTimePlayed).ToString(), Utils.DateToMinute(storedPlayer.CasualTimePlayed).ToString()).ToString() + " minutos",

                TerroristHuntTimePlayed = Utils.Parse(minervaPlayer.TerroristHuntTimePlayed, storedPlayer.TerroristHuntTimePlayed).ToString() + " minutos"
            };

            using (StreamWriter file = File.CreateText(path))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, minervaPlayer);
            }

            // serialize JSON directly to a file
            using (StreamWriter file = File.CreateText(resultPath + minervaPlayer._Nick + ".json"))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, player);
            }
        }
Ejemplo n.º 3
0
        static void Main()
        {
            string[] players = ConfigurationSettings.AppSettings["user"].Split('|');
            string   path    = ConfigurationSettings.AppSettings["TemporaryPath"] + @"\";

            foreach (string player in players)
            {
                R6StatsData minervaPlayer = new R6StatsData();

                string token = GetUbiToken(player);

                string html = GetUserHTML(token);

                GetRankedInfo(ref minervaPlayer, html);
                GetCasualInfo(ref minervaPlayer, html);
                GetGeneralInfo(ref minervaPlayer, html);

                minervaPlayer._Nick = player;

                minervaPlayer.TerroristHuntTimePlayed = Utils.DateToMinute(minervaPlayer.GeneralTimePlayed, minervaPlayer.CasualTimePlayed, minervaPlayer.RankedTimePlayed).ToString();

                StoreData(path, minervaPlayer);
            }
        }
Ejemplo n.º 4
0
        public static void GetRankedInfo(ref R6StatsData minervaPlayer, string html)
        {
            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(html);

            HtmlNodeCollection rankedStats = htmlDoc.DocumentNode.SelectNodes("//*[@class='card stat-card block__ranked horizontal']/div/div");

            if (rankedStats == null)
            {
                Console.WriteLine("rankedStats for the user: "******" is empty.");
                return;
            }

            foreach (HtmlNode rankedData in rankedStats)
            {
                if (rankedData.FirstChild == null)
                {
                    continue;
                }

                string value = rankedData.FirstChild.InnerText;

                switch (rankedData.LastChild.InnerText)
                {
                case "Time Played":
                    minervaPlayer.RankedTimePlayed = value;
                    break;

                case "Matches Played":
                    minervaPlayer.RankedMatchesPlayed = value;
                    break;

                case "Kills / Match":
                    minervaPlayer.RankedKPM = value;
                    break;

                case "Kills":
                    minervaPlayer.RankedKills = value;
                    break;

                case "Deaths":
                    minervaPlayer.RankedDeaths = value;
                    break;

                case "K/D Ratio":
                    minervaPlayer.RankedKD = value;
                    break;

                case "Wins":
                    minervaPlayer.RankedWins = value;
                    break;

                case "Losses":
                    minervaPlayer.RankedLosses = value;
                    break;

                case "W/L Ratio":
                    minervaPlayer.RankedWL = value;
                    break;
                }
            }
        }