Esempio n. 1
0
        public ItemDataRequest GetItemData(int itemId, string version)
        {
            string         apiKey         = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiKey"];
            string         requestUri     = String.Format("https://global.api.pvp.net/api/lol/static-data/na/v1.2/item/{0}?version={1}&itemData=all&api_key={2}", itemId, version, apiKey);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri);

            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Method      = WebRequestMethods.Http.Get;
            httpWebRequest.Accept      = "application/json";
            httpWebRequest.Proxy       = null;
            WebResponse response = httpWebRequest.GetResponse();

            string json;

            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                json = sr.ReadToEnd();
            }

            ItemDataRequest data = JsonConvert.DeserializeObject <ItemDataRequest>(json);

            return(data);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            try
            {
                Console.Write("Checking for existing key:        ");
                string key = SessionManager.GetInstance().GameSession.Key;
                ok();
            }
            catch (GameSessionRequiredException)
            {
                error();

                Console.Write("Locating Guild Wars 2 process:    ");
                Process gw2 = findProcess(m_PROCESS_NAME);
                if (gw2 == null)
                {
                    error(); return;
                }
                else
                {
                    ok();
                }

                Console.Write("Locating game session key:        ");
                string key = findSessionKey(gw2);
                if (key == null)
                {
                    error(); return;
                }
                else
                {
                    ok();
                }
                SessionManager.GetInstance().GameSession = new Session(key, true);
            }

            Console.Write("Retreiving filtered buy listings: ");
            IList <Listing> buyOrders = new MeRequest(MeRequest.TimeType.NOW, MeRequest.ListingType.BUY)
                                        .ExecuteAll()
                                        .SelectMany(r => r.Listings)
                                        .ToList();

            ok();

            Console.Write("Filter outbid listings:           ");
            IDictionary <int, ItemData> items            = new Dictionary <int, ItemData>();
            IList <Listing>             filteredListings = buyOrders
                                                           .Where((listing) =>
            {
                if (!items.ContainsKey(listing.DataId))
                {
                    ItemDataResponse response = new ItemDataRequest(listing.DataId).Execute();
                    if (response == null)
                    {
                        return(false);
                    }

                    items[listing.DataId] = response.Result;
                }

                return(items[listing.DataId].MaxOfferUnitPrice <= listing.UnitPrice);
            })
                                                           .ToList();

            ok();

            if (filteredListings.Count > 0)
            {
                Console.WriteLine("{0} of your buy orders have not been outbid.", filteredListings.Count);
                Console.WriteLine("Orders are displayed in descending order from the date the order was placed.");
                Console.WriteLine("Press any key to view the next order in the list, or Esc to exit.");
                Console.WriteLine("{0,-10} {1}", "Price", "Name");

                foreach (Listing listing in filteredListings)
                {
                    Console.WriteLine(string.Format("{0,10} {1}",
                                                    listing.BuyPrice.ToString("#### ## #0").Trim(),
                                                    listing.Name));

                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                    {
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine("All of your buy orders have been outbid. Press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            try
            {
                Console.Write("Checking for existing key:        ");
                string key = SessionManager.GetInstance().GameSession.Key;
                ok();
            }
            catch (GameSessionRequiredException)
            {
                error();

                Console.Write("Locating Guild Wars 2 process:    ");
                Process gw2 = findProcess(m_PROCESS_NAME);
                if (gw2 == null) { error(); return; }
                else { ok(); }

                Console.Write("Locating game session key:        ");
                string key = findSessionKey(gw2);
                if (key == null) { error(); return; }
                else { ok(); }
                SessionManager.GetInstance().GameSession = new Session(key, true);
            }

            Console.Write("Retreiving filtered buy listings: ");
            IList<Listing> buyOrders = new MeRequest(MeRequest.TimeType.NOW, MeRequest.ListingType.BUY)
                    .ExecuteAll()
                    .SelectMany(r => r.Listings)
                    .ToList();
            ok();

            Console.Write("Filter outbid listings:           ");
            IDictionary<int, ItemData> items = new Dictionary<int, ItemData>();
            IList<Listing> filteredListings = buyOrders
                    .Where((listing) =>
                        {
                            if (!items.ContainsKey(listing.DataId))
                            {
                                ItemDataResponse response = new ItemDataRequest(listing.DataId).Execute();
                                if (response == null)
                                    return false;

                                items[listing.DataId] = response.Result;
                            }

                            return items[listing.DataId].MaxOfferUnitPrice <= listing.UnitPrice;
                        })
                    .ToList();
            ok();

            if (filteredListings.Count > 0)
            {
                Console.WriteLine("{0} of your buy orders have not been outbid.", filteredListings.Count);
                Console.WriteLine("Orders are displayed in descending order from the date the order was placed.");
                Console.WriteLine("Press any key to view the next order in the list, or Esc to exit.");
                Console.WriteLine("{0,-10} {1}", "Price", "Name");

                foreach (Listing listing in filteredListings)
                {
                    Console.WriteLine(string.Format("{0,10} {1}",
                            listing.BuyPrice.ToString("#### ## #0").Trim(),
                            listing.Name));

                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                        break;
                }
            }
            else
            {
                Console.WriteLine("All of your buy orders have been outbid. Press any key to exit.");
                Console.ReadKey(true);
            }
        }