Esempio n. 1
0
        public static IList <EtherPrice> ReadListFromFile()
        {
            var list = new List <EtherPrice>();

            if (File.Exists(ConfigHelper.CalculateUSDCostFromFile))
            {
                return(File.ReadAllLines(ConfigHelper.CalculateUSDCostFromFile)
                       .Skip(867)
                       .Select(line => EtherPrice.LoadFromCsv(line))
                       .ToList());
            }

            return(list);
        }
Esempio n. 2
0
        public static async Task <IList <EtherPrice> > ReadListFromUrl()
        {
            var list = new List <EtherPrice>();

            try
            {
                using (var client = new HttpClient())
                {
                    client.Timeout = TimeSpan.FromSeconds(ConfigHelper.CalculateUSDCostFromTimeout);
                    using (var response = await client.GetAsync(ConfigHelper.CalculateUSDCostFromUrl))
                        using (var stream = await response.Content.ReadAsStreamAsync())
                            using (var reader = new StreamReader(stream))
                            {
                                string line;
                                var    count = 0;
                                while ((line = await reader.ReadLineAsync()) != null)
                                {
                                    count++;
                                    if (count > 867)
                                    {
                                        var etherPrice = EtherPrice.LoadFromCsv(line);
                                        list.Add(etherPrice);
                                    }
                                }
                            }
                }
            }
            catch
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Could not read {0}.", ConfigHelper.CalculateUSDCostFromUrl);
                Console.ResetColor();
            }

            return(list);
        }