public OffersResponse GetActiveTradeOffers(bool getSentOffers, bool getReceivedOffers, bool getDescriptions, string language = "en_us")
        {
            if (!getSentOffers && !getReceivedOffers)
            {
                throw new ArgumentException("getSentOffers and getReceivedOffers can't be both false");
            }

            string options = string.Format("?key={0}&get_sent_offers={1}&get_received_offers={2}&get_descriptions={3}&language={4}&active_only={5}",
                                           apiKey, BoolConverter(getSentOffers), BoolConverter(getReceivedOffers), BoolConverter(getDescriptions), language, BoolConverter(true));
            string url = string.Format(BaseUrl, "GetTradeOffers", "v1", options);

            bool           failed   = true;
            OffersResponse response = null;

            while (failed)
            {
                string responseStr = steamWeb.Fetch(url, "GET", null, false);
                try
                {
                    var result = JsonConvert.DeserializeObject <ApiResponse <OffersResponse> >(responseStr);
                    response = result.Response;
                }
                catch (Exception ex)
                {
                    //todo log
                    Debugger.Log(3, "[TradeOfferWebAPI] ", ex.ToString());
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[TradeOfferWebAPI] Exception caught in deserialization: " + ex.ToString());
                }

                if (response != null && response.TradeOffersReceived != null)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.WriteLine("[TradeOfferWebAPI] Trade offers fetched.");
                    failed = false;
                }

                Console.ForegroundColor = ConsoleColor.White;

                if (failed)
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("[TradeOfferWebAPI] Unable to fetch trade offers. Trying again in 45 secs.");
                    for (int i = 0; i < 45; i++)
                    {
                        Thread.Sleep(1000);

                        if (Thread.CurrentThread.ThreadState != System.Threading.ThreadState.Running)
                        {
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine("[TradeOfferWebAPI] Exit requested during trade offer wait.");
                            return(null);
                        }
                    }
                }
            }

            return(response);
        }
Exemple #2
0
        private void AddTradeOffersToQueue(OffersResponse offers)
        {
            if (offers == null || offers.AllOffers == null)
            {
                return;
            }

            lock (unhandledTradeOfferUpdates)
            {
                foreach (var offer in offers.AllOffers)
                {
                    unhandledTradeOfferUpdates.Enqueue(offer);
                }
            }
        }