예제 #1
0
 private void CheckPrice(out PriceDate pd, out string prefix, out string suffix)
 {
     pd = null; prefix = suffix = "";
     try
     {
         string response = HelpFunctions.LoadPage(ITEM_JSON_LINK);
         if (response == "" || response == "[]")
         {
             SetToolTipUpdate($"{DateTime.Now} empty json");
         }
         else
         {
             MarketResponse resp = JsonConvert.DeserializeObject <MarketResponse>(response);
             if (resp != null && resp.success)
             {
                 if (resp.sog != null && resp.sog.Count > 0)
                 {
                     prefix = resp.price_prefix;
                     suffix = resp.price_suffix;
                     pd     = new PriceDate(double.Parse(resp.sog[0][0], CultureInfo.InvariantCulture), DateTime.Now);
                     SetToolTipUpdate($"{DateTime.Now} success updated");
                 }
             }
             else
             {
                 SetToolTipUpdate($"{DateTime.Now} error json");
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Write($"CheckPrice error: {ex.Message} / {ITEM_ID} / {ITEM_NAME}");
     }
 }
예제 #2
0
        private async Task <PriceDate> CheckPriceAsync()
        {
            try
            {
                using (var httpClient = new HttpClient())
                    using (var stream = await httpClient.GetStreamAsync(ITEM_JSON_LINK))
                        using (var reader = new StreamReader(stream))
                        {
                            string response = await reader.ReadToEndAsync();

                            if (response == "" || response == "[]")
                            {
                                SetToolTipUpdate($"{DateTime.Now} empty json");
                            }
                            else
                            {
                                MarketResponse resp = JsonConvert.DeserializeObject <MarketResponse>(response);
                                if (resp != null && resp.success)
                                {
                                    if (resp.sog != null && resp.sog.Count > 0)
                                    {
                                        SetToolTipUpdate($"{DateTime.Now} success updated");
                                        textblockValues.pricePreffix = resp.price_prefix;
                                        textblockValues.priceSuffix  = resp.price_suffix;
                                        return(new PriceDate(double.Parse(resp.sog[0][0], CultureInfo.InvariantCulture), DateTime.Now));
                                    }
                                }
                                else
                                {
                                    SetToolTipUpdate($"{DateTime.Now} error json");
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                Logger.Write($"CheckPriceAsync error: {ex.Message} / {ITEM_ID} / {ITEM_NAME}");
            }
            return(null);
        }