public static async void GetAucInfo(AucResponseHandler handler, string realm) { // GetDataFromFile(handler); if (handler == null) { return; } var fileitem = Path.Combine(@"AucInfo\", realm + ".json"); var filelast = Path.Combine(@"AucInfo\", realm + ".last"); try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.GetAsync("/api/wow/auction/data/" + realm); if (!response.IsSuccessStatusCode) { handler(null); return; } var jsonString = await response.Content.ReadAsStringAsync(); var js = JObject.Parse(jsonString); string oldlast = null; if (File.Exists(filelast)) { oldlast = File.ReadAllText(filelast).ToString(CultureInfo.InvariantCulture); } var url = js["files"][0]["url"]; var last = js["files"][0]["lastModified"]; File.WriteAllText(filelast, last.ToString()); if (last.ToString() != oldlast) { var res = await client.GetAsync(url.ToString()); var jsonString1 = await res.Content.ReadAsStringAsync(); Save(fileitem, jsonString1); } GetDataFromFile(handler, realm); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public static void GetTest(AucResponseHandler hand) { var str = @"{""auc"":1117916020,""item"":82800,""owner"":""»рника"",""ownerRealm"":""ясеневыйлес"",""bid"":61740500,""buyout"":64990000,""quantity"":1,""timeLeft"":""MEDIUM"",""rand"":0,""seed"":1984317312,""context"":0,""modifiers"":[{""type"":3,""value"":1332},{""type"":4,""value"":50331663},{""type"":5,""value"":25}],""petSpeciesId"":1332,""petBreedId"":15,""petLevel"":25,""petQualityId"":3}"; var auc = new WoWAucInfo(str); // hand(auc); }
public static void GetDataFromFile(AucResponseHandler handler, string realm) { if (handler == null) { return; } var fileitem = Path.Combine(@"AucInfo\", realm + ".json"); if (!File.Exists(fileitem)) { var ex = new Exception(); var f = new FileNotFoundException(); return; } //var jsarr = ReadFileInString(fileitem); //JsonTextReader reader = new JsonTextReader(new StringReader(jsarr)) {SupportMultipleContent = true}; //var st = ""; // while (reader.Read()) // { // if (reader.Value != null) st += reader.Value+" "; // // Console.WriteLine("Token: {0}, Value: {1} Path {2}", reader.TokenType, reader.Value,reader.Path); // else // //Console.WriteLine("Token: {0}", reader.TokenType); // if (reader.TokenType.ToString() == "StartObject" ) // { // handler(st); // st = ""; // } // // var a = reader.Value; // // handler(new WoWAucInfo(a)); // } var lists = new List <WoWAucInfo>(); using (var stream = new FileStream(fileitem, FileMode.Open)) { var str = new StreamReader(stream); string f; while ((f = str.ReadLine()) != null) { var s = f; var t = s.Trim(); if (t.LastOrDefault() == ',') { t = t.Remove(t.LastIndexOf(',')); } var r = new Regex(@"\["); var open = r.Matches(t).Count; r = new Regex(@"\]"); var close = r.Matches(t).Count; if (open != close) { t = t.Replace("]", ""); t = t.Remove(t.Length - 1); } if (t.FirstOrDefault() == '{' && t.LastOrDefault() == '}') { lists.Add(new WoWAucInfo(t)); } } } handler(lists); }