public fb_response get_object(string url, int timeout) { WebRequest req = WebRequest.Create(url); req.Timeout = timeout; Stream s = req.GetResponse().GetResponseStream(); JToken obj = readjson(s); s.Close(); fb_response resp = new fb_response(); switch (obj.Type) { case JTokenType.Array: resp.is_array = true; resp.data = obj; break; case JTokenType.Object: JObject obj1 = (JObject)obj; JToken tmp; if (obj1.TryGetValue("data", out tmp)) { resp.is_array = true; resp.data = tmp; } else { resp.is_array = false; resp.data = obj; } if (obj1.TryGetValue("paging", out tmp)) { JObject x = (JObject)tmp; JToken tmp1; if (x.TryGetValue("previous", out tmp1)) { resp.prev_url = tmp1.Value <string> (); } if (x.TryGetValue("next", out tmp1)) { resp.next_url = tmp1.Value <string> (); } } break; default: resp.is_array = false; resp.data = obj; break; } return(resp); }
public fb_response get_object (string url, int timeout) { WebRequest req = WebRequest.Create (url); req.Timeout = timeout; Stream s = req.GetResponse ().GetResponseStream (); JToken obj = readjson (s); s.Close (); fb_response resp = new fb_response (); switch (obj.Type) { case JTokenType.Array: resp.is_array = true; resp.data = obj; break; case JTokenType.Object: JObject obj1 = (JObject)obj; JToken tmp; if (obj1.TryGetValue ("data", out tmp)) { resp.is_array = true; resp.data = tmp; } else { resp.is_array = false; resp.data = obj; } if (obj1.TryGetValue ("paging", out tmp)) { JObject x = (JObject)tmp; JToken tmp1; if (x.TryGetValue ("previous", out tmp1)) resp.prev_url = tmp1.Value<string> (); if (x.TryGetValue ("next", out tmp1)) resp.next_url = tmp1.Value<string> (); } break; default: resp.is_array = false; resp.data = obj; break; } return resp; }
public void dump_fb_object(string url, fbdump_params p, bool raw_url = false) { Gdk.Threads.Enter(); try { /*Gtk.Label l = new Gtk.Label ("dumping "+url); * vbox1.Add (l); * l.Show ();*/ Console.WriteLine("dumping " + url); } finally { Gdk.Threads.Leave(); } if (!raw_url) { string tmp = "access_token=" + p.atoken; if (url.IndexOf('?') < 0) { url += "?" + tmp; } else { url += "&" + tmp; } } try { fb_response r = get_object(url, p.timeout); p.pages++; if (r.is_array) { string graph_path = get_graph_path(url); if (p.list_cb != null) { p.list_cb(r.data, graph_path, p); } JArray a = (JArray)r.data; int i; for (i = 0; i < a.Count; i++) { process_fb_obj(a [i], graph_path, p); } } else { process_fb_obj(r.data, null, p); } Gdk.Threads.Enter(); try { update_labels(); } finally { Gdk.Threads.Leave(); } if (p.f == followmode.prev && r.prev_url != null && r.prev_url.Length > 0) { dump_fb_object(r.prev_url, p, true); } else if (p.f == followmode.next && r.next_url != null && r.next_url.Length > 0) { dump_fb_object(r.next_url, p, true); } } catch (Exception ex) { Gdk.Threads.Enter(); try { if (ex.GetType() != typeof(System.Threading.ThreadAbortException)) { p.errors++; perror(ex); update_labels(); } } finally { Gdk.Threads.Leave(); } } }