Пример #1
0
        private async void LoadSavedPrimeData()
        {
            PrimeData primeData = await PrimeData.GetInstance().ConfigureAwait(false);

            foreach (var primeItem in primeData.Primes)
            {
                AllPrimePartsList.Add(new DisplayPrime()
                {
                    Data = primeData.GetDataForItem(primeItem), Prime = primeItem
                });
            }
        }
Пример #2
0
        private async void LoadData()
        {
            var primeData = await PrimeData.GetInstance();

            foreach (var primeItem in primeData.Primes)
            {
                PrimeItems.Add(new DisplayPrime()
                {
                    Data = primeData.GetDataForItem(primeItem), Prime = primeItem
                });
            }
        }
Пример #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 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);
        }
Пример #4
0
        public async void Close()
        {
            if (RenderOverlay && backgroundWorker.IsBusy)
            {
                backgroundWorker.CancelAsync();
            }

            var _wpfoverlay = (WPFOverlay)_overlay;

            if (_wpfoverlay != null)
            {
                _wpfoverlay.Dispose();
            }
            (await PrimeData.GetInstance()).SaveToFile();
        }
Пример #5
0
        public async void Close()
        {
            if (RenderOverlay && backgroundWorker.IsBusy)
            {
                backgroundWorker.CancelAsync();
            }

            WPFOverlay wpfoverlay = (WPFOverlay)overlay;

            if (wpfoverlay != null)
            {
                wpfoverlay.Dispose();
            }
            (await PrimeData.GetInstance().ConfigureAwait(false)).SaveToFile();
        }
Пример #6
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;
        }
Пример #7
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);
        }
Пример #8
0
        public static async Task <PrimeData> GetInstance()
        {
            if (_instance != null)
            {
                return(_instance);
            }

            try
            {
                await _cacheLock.WaitAsync();

                if (_instance == null)
                {
                    _instance = await Load();
                }

                return(_instance);
            }
            finally
            {
                _cacheLock.Release();
            }
        }
Пример #9
0
        public static async Task<PrimeData> GetInstance()
        {
            if (_instance != null)
            {
                return _instance;
            }

            try
            {
                await _cacheLock.WaitAsync();

                if (_instance == null)
                {
                    _instance = await Load();
                }

                return _instance;

            }
            finally
            {
                _cacheLock.Release();
            }
        }
Пример #10
0
 public async void Close()
 {
     (await PrimeData.GetInstance()).SaveToFile();
 }