Пример #1
0
        public static XDocument downloadPrices(EveCentralUtility parameters)
        {
            UriBuilder url = new UriBuilder();
            url.Scheme = "http";
            url.Host = "api.eve-central.com";
            url.Path = "api/quicklook";
            url.Query = "typeid=" + parameters.Id +
                "&usesystem=" + parameters.System +
                "&sethour=" + parameters.Hours;

            using (WebClient client = new WebClient())
                return XDocument.Parse(client.DownloadString(url.ToString()));
        }
Пример #2
0
 public Security grabItem(int id, int station, int age)
 {
     try
     {
         EveCentralUtility parameters =
             new EveCentralUtility(id, age, station);
         Security security = fetchPrices(parameters,
             this.downloadPrices,
             this.downloadVolume);
         return security;
     }
     catch (WebException exception)
     {
         // TODO: Recover from this
         MessageBox.Show(exception.Message);
         return null;
     }
 }
Пример #3
0
        public static Security fetchPrices(EveCentralUtility parameters,
            PriceDownloader downloadPrices,
            VolumeDownloader downloadVolume)
        {
            XDocument xml = downloadPrices(parameters);

            string name = xml.Descendants("itemname").First().Value;

            Func<string, IEnumerable<double>> process =
                (string type) => xml.Descendants(type)
                .Descendants("order")
                .Elements("price")
                .Select(p => double.Parse(p.Value))
                .DefaultIfEmpty(0);

            double buy = process("buy_orders").Max();
            double sell = process("sell_orders").Min();

            int id = parameters.Id;

            long volume = downloadVolume(id);

            return new Security(id, name, buy, sell, volume);
        }