示例#1
0
        public static async Task <PrimeData> Load()
        {
            PrimeData primeData = new PrimeData();

            if (File.Exists(FILE))
            {
                var formatter = new BinaryFormatter();
                using (FileStream stream = File.OpenRead(FILE))
                {
                    primeData = formatter.Deserialize(stream) as PrimeData;
                }
            }

            if (primeData.PrimesLastRetrieved + _expirationTimespan < DateTime.Now)
            {
                //Update the cached Primes
                string lootFileText = await DownloadLootFile();

                var doc = new HtmlDocument();
                doc.LoadHtml(lootFileText);

                var relicTable = doc.DocumentNode.Descendants().First(n => n.InnerText == "Relics:").NextSibling;

                var primeRewardNodes = relicTable.SelectNodes("tr[td[2]]");

                primeData.Primes = primeRewardNodes.Select(node =>
                                                           new PrimeItem()
                {
                    Name   = node.ChildNodes[0].InnerText,
                    Rarity = node.ChildNodes[1].InnerText.Contains("Rare") ? Rarity.Rare : node.ChildNodes[1].InnerText.Contains("Uncommon") ? Rarity.Uncommon : Rarity.Common
                })
                                   .GroupBy(i => i.Name)
                                   .Select(g => g.First())
                                   .ToList();

                foreach (var prime in primeData.Primes)
                {
                    prime.Name = prime.Name.Replace("Systems Blueprint", "Systems");
                    prime.Name = prime.Name.Replace("Chassis Blueprint", "Chassis");
                    prime.Name = prime.Name.Replace("Neuroptics Blueprint", "Neuroptics");
                }

                primeData.PrimesLastRetrieved = DateTime.Now;
            }

            primeData.SaveToFile();

            return(primeData);
        }
示例#2
0
        public static async Task <PrimeData> Load()
        {
            PrimeData primeData = new PrimeData();

            if (File.Exists(FILE))
            {
                var formatter = new BinaryFormatter();
                using (FileStream stream = File.OpenRead(FILE))
                {
                    primeData = formatter.Deserialize(stream) as PrimeData;
                }
            }

            if (primeData.PrimesLastRetrieved + _expirationTimespan < DateTime.Now)
            {
                //Update the cached Primes
                string lootFileText = await DownloadLootFile();

                var lootFileLines = lootFileText.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                var primeLootLines = lootFileLines.Where(line => line.Contains("PRIME"));

                var primeItems = primeLootLines.Select(l => TryParseLine(l)).Where(i => i != null);

                var uniquePrimes = primeItems.GroupBy(i => i.Name).Select(group => group.First());

                var newPrimes = uniquePrimes.OrderBy(p => p.Name).ToList();

                if (newPrimes.Count > 0)
                {
                    primeData.Primes = newPrimes;

                    primeData.PrimesLastRetrieved = DateTime.Now;
                }
            }

            primeData.SaveToFile();

            return(primeData);
        }
示例#3
0
        public static async Task<PrimeData> Load()
        {
            PrimeData primeData = new PrimeData();

            if (File.Exists(FILE))
            {
                var formatter = new BinaryFormatter();
                using (FileStream stream = File.OpenRead(FILE))
                {
                    primeData = formatter.Deserialize(stream) as PrimeData;
                }
            }

            if (primeData.PrimesLastRetrieved + _expirationTimespan < DateTime.Now)
            {
                //Update the cached Primes
                string lootFileText = await DownloadLootFile();

                var lootFileLines = lootFileText.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                var primeLootLines = lootFileLines.Where(line => line.Contains("PRIME"));

                var primeItems = primeLootLines.Select(l => TryParseLine(l)).Where(i => i != null);

                var uniquePrimes = primeItems.GroupBy(i => i.Name).Select(group => group.First());
                
                var newPrimes = uniquePrimes.OrderBy(p => p.Name).ToList();

                if (newPrimes.Count > 0)
                {
                    primeData.Primes = newPrimes;

                    primeData.PrimesLastRetrieved = DateTime.Now;
                }
            }

            primeData.SaveToFile();

            return primeData;
        }