private void bgetPhotosets_Click(object sender, EventArgs e) { if (!tokens.ContainsKey("oauth_token") || !tokens.ContainsKey("oauth_token_secret")||!tokens.ContainsKey("user_id")) { bgetPhotosets.Enabled = false; return; } string json = ""; int nTries1 = 0; while (string.IsNullOrEmpty(json) && nTries1 < 5) { json = getJsonRest("flickr.photosets.getList", "user_id", tokens["user_id"]); nTries1++; } if (!string.IsNullOrEmpty(json)) { XmlDocument xd = new XmlDocument(); xd = (XmlDocument)JsonConvert.DeserializeXmlNode(json.ToString().Replace(".", ","), "result"); phs = new photosets(); DataSet ds = new DataSet(); ds.ReadXml(new XmlNodeReader(xd)); using (DataTable dt1 = ds.Tables["photosets"]) { phs = getPhotosets(dt1.Rows[0]); } using (DataTable dtph = ds.Tables["photoset"]) { DataTable dtt = ds.Tables["title"]; DataTable dtd = ds.Tables["description"]; for (int n = 0; n < dtph.Rows.Count; n++) { DataRow dr = dtph.Rows[n]; DataRow drt = dtt.Rows[n]; DataRow drd = dtd.Rows[n]; photoset ph = new photoset(); ph = getPhotoset(dr); if (drt != null) ph.title = drt[0].ToString(); if (drd != null) ph.description = drd[0].ToString(); phs.children.Add(ph); } } photoset phnone = new photoset(); phnone.title = "none"; phnone.description = "none"; phs.children.Add(phnone); photoset phuntagged = new photoset(); phuntagged.title = "untagged"; phuntagged.description = "untagged"; phs.children.Add(phuntagged); chkListFrom.Items.Clear(); comboTo.Items.Clear(); foreach (photoset ps in phs.children) { chkListFrom.Items.Add(ps.title); comboTo.Items.Add(ps.title); } label2.Text = "Photosets:" + phs.children.Count; bgetPhotos.Enabled = (phs.children.Count > 0); } }
private photosets getPhotosets(DataRow dr) { photosets w = new photosets(); Type source = dr.GetType(); Type dest = w.GetType(); foreach (PropertyInfo pi in dest.GetProperties()) { if (dr.Table.Columns.Contains(pi.Name)) { string str = dr[pi.Name].ToString(); if (pi.PropertyType == typeof(bool)) { bool bout = false; bool.TryParse(str, out bout); pi.SetValue(w, bout); } else if (pi.PropertyType == typeof(double)) { double bout = 0; double.TryParse(str, out bout); pi.SetValue(w, bout); } else if (pi.PropertyType == typeof(DateTime)) { DateTime bout = DateTime.MinValue; DateTime.TryParse(str, out bout); pi.SetValue(w, bout); } else if (pi.PropertyType == typeof(Int32)) { Int32 bout = Int32.MinValue; Int32.TryParse(str, out bout); pi.SetValue(w, bout); } else pi.SetValue(w, str); } } return w; }
private void addToMake(photo p) { string make = p.make.Split(' ')[0]; string json = ""; int nTries1 = 0; while (string.IsNullOrEmpty(json) && nTries1 < 5) { json = getJsonRest("flickr.photosets.getList", "user_id", tokens["user_id"]); nTries1++; } if (!string.IsNullOrEmpty(json)) { XmlDocument xd = new XmlDocument(); xd = (XmlDocument)JsonConvert.DeserializeXmlNode(json.ToString().Replace(".", ","), "result"); photosets photosets = new photosets(); DataSet ds = new DataSet(); ds.ReadXml(new XmlNodeReader(xd)); using (DataTable dt1 = ds.Tables["photosets"]) { photosets = getPhotosets(dt1.Rows[0]); } using (DataTable dtph = ds.Tables["photoset"]) { DataTable dtt = ds.Tables["title"]; DataTable dtd = ds.Tables["description"]; for (int n = 0; n < dtph.Rows.Count; n++) { DataRow dr = dtph.Rows[n]; DataRow drt = dtt.Rows[n]; DataRow drd = dtd.Rows[n]; photoset ph = new photoset(); ph = getPhotoset(dr); if (drt != null) ph.title = drt[0].ToString(); if (drd != null) ph.description = drd[0].ToString(); photosets.children.Add(ph); } } } var phsid = phs.children.FirstOrDefault(x => x.title.Equals(make,StringComparison.InvariantCultureIgnoreCase)); string photoset_id = ""; if (phsid == null) { string json2 = ""; int nTries2 = 0; while (string.IsNullOrEmpty(json2) && nTries2 < 5) { json2 = getJsonRest("flickr.photosets.create", "primary_photo_id|title", p.id + "|" + make); nTries2++; } if (!string.IsNullOrEmpty(json2)) { XmlDocument xd = new XmlDocument(); xd = (XmlDocument)JsonConvert.DeserializeXmlNode(json2.ToString().Replace(".", ","), "result"); DataSet ds = new DataSet(); ds.ReadXml(new XmlNodeReader(xd)); using (DataTable dt1 = ds.Tables["photoset"]) { if (dt1 != null) { photoset ps = getPhotoset(dt1.Rows[0]); photoset_id = ps.id; ps.title = make; phs.children.Add(ps); } } } } else { photoset_id = phsid.id; } string json1 = ""; int nTries3 = 0; while (string.IsNullOrEmpty(json1) && nTries3 < 5) { json1 = getJsonRest("flickr.photosets.addPhoto", "photo_id|photoset_id", p.id + "|" + photoset_id); nTries3++; } }