Ejemplo n.º 1
0
        public static double GetPrice(string name)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest
                                     .Create(RequestBuilder.PriceRequest(name));

            if (ProxySingleton.GetInstance().CanUse)
            {
                request.Proxy = ProxySingleton.GetInstanceNext().Proxy;
            }

            HttpWebResponse response = GetResponse(request);

            if (response == null)
            {
                return(-2);
            }

            Stream       stream       = response.GetResponseStream();
            StreamReader streamReader = new StreamReader(stream);

            string content = streamReader.ReadToEnd();

            response.Close();

            JSONObject json = JSONParser.Parse(content);

            if (json.GetValue("success").ToString() == "false")
            {
                return(-2);
            }

            return(Converters.ConvertToDouble(json.GetValue("lowest_price")?.ToString()));
        }
Ejemplo n.º 2
0
        public override void LoadItems()
        {
            RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, () =>
            {
                return(Task.Run(() =>
                {
                    State = LootBoxState.LoadStarted;

                    return true;
                }));
            }, false);

            foreach (var description in Description)
            {
                if (description.Text.Contains("Exceedingly"))
                {
                    continue;
                }

                RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, async() =>
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest
                                             .Create(RequestBuilder.SearchRequest(description.Text));

                    if (ProxySingleton.GetInstanceNext().CanUse)
                    {
                        request.Proxy = ProxySingleton.GetInstance().Proxy;
                    }

                    HttpWebResponse response = await RequestsUtil.GetResponseAsync(request);

                    await Task.Delay(RequestHandler.Delay);

                    if (response == null)
                    {
                        return(false);
                    }

                    Stream stream             = response.GetResponseStream();
                    StreamReader streamReader = new StreamReader(stream);

                    string content = streamReader.ReadToEnd();

                    response.Close();

                    JSONObject json = JSONParser.Parse(content);

                    var results = json.GetArray("results");

                    if (results == null)
                    {
                        return(false);
                    }

                    string hashName, imageCode;
                    IMarketItem item;

                    for (int i = 0; i < results.Count; i++)
                    {
                        hashName = results[i]["asset_description"].GetValue("market_hash_name").ToString();

                        if (!hashName.ToLower().Contains(description.Text.ToLower()) ||
                            Items.Where(x => x.Name == hashName).Count() > 0)
                        {
                            continue;
                        }

                        item = new MarketItem(hashName);

                        AddItem(item);

                        imageCode = results[i]["asset_description"].GetValue("icon_url").ToString();

                        item.GetIcon(imageCode, hashName, Name);

                        RaisePropertyChanged("OnItemLoaded");
                    }

                    return(true);
                });
            }

            RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, () =>
            {
                return(Task.Run(() =>
                {
                    State = LootBoxState.ItemsLoaded;

                    LoadPrices();

                    return true;
                }));
            }, false);
        }