public ImageID.Image[] getUrlFromID(String id) { ImageID.Image[] list = null; try { String url = getURL(textBox2.Text, id + "?fields=images"); HttpRequest http = getRequest("", ""); String outJson = http.Get(url).ToString(); ImageID.Rootobject listIMG = JsonConvert.DeserializeObject <ImageID.Rootobject>(outJson); list = listIMG.images; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(list); }
public void DownloadImage(String path, String id) { String url = getURL(textBox2.Text, id + "?fields=images"); try { HttpRequest http = getRequest("", ""); String outJson = http.Get(url).ToString(); ImageID.Rootobject list = JsonConvert.DeserializeObject <ImageID.Rootobject>(outJson); String pathout = path + "\\" + id; if (isAll) { Directory.CreateDirectory(pathout); foreach (ImageID.Image item in list.images) { try { http.Get(item.source).ToFile(pathout + "\\h" + item.height + "_w" + item.width + ".jpg"); } catch (Exception ex) { richTextBox1.Invoke(new MethodInvoker(() => { richTextBox1.AppendText("\nLỗi: " + ex.Message); })); } } richTextBox1.Invoke(new MethodInvoker(() => { richTextBox1.AppendText("\nĐã tải xong ảnh ID: " + id); })); File.AppendAllText("log.lg", String.Format("Status: Download successful image: {0}\tTime: {1} {2}\n", id, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString())); } else { try { http.Get(list.images[0].source).ToFile(path + "\\" + id + ".jpg"); richTextBox1.Invoke(new MethodInvoker(() => { richTextBox1.AppendText("\nĐã tải xong ảnh ID: " + id); })); File.AppendAllText("log.lg", String.Format("Status: Download successful image: {0}\tTime: {1} {2}\n", id, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString())); } catch (Exception ex) { richTextBox1.Invoke(new MethodInvoker(() => { richTextBox1.AppendText("\nLỗi:" + ex.Message); })); File.AppendAllText("log.lg", String.Format("Status: Download ERROR image: {0}\tTime: {1} {2}\n", id, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString())); } } } catch (Exception ex) { richTextBox1.Invoke(new MethodInvoker(() => { richTextBox1.AppendText("\nLỗi:" + ex.Message); })); File.AppendAllText("log.lg", String.Format("Status: Download ERROR image: {0}\tTime: {1} {2}\n", id, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString())); } }