Ejemplo n.º 1
0
        private void GetPhotos(object state)
        {
            this.Invoke((MethodInvoker)delegate
            {
                pBSet.Maximum = chkListFrom.CheckedItems.Count;
                pBSet.Value = 0;
            });
            foreach (string sphotoset in chkListFrom.CheckedItems)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    pBSet.Value++;
                });
                var phsid = phs.children.FirstOrDefault(x => x.title.Equals(sphotoset));
                if (phsid == null)
                    continue;
                if (phsid.photos.Count > 0)
                {
                    phsid.photos.Clear();
                }
                if (phsid.title.Equals("untagged"))
                {
                    GetUntaggedPhotos(null);
                }
                else if (phsid.title.Equals("none"))
                {
                    GetNotInSet(null);
                }
                else
                {
                    string json = "";
                    int nTries1 = 0;
                    while (string.IsNullOrEmpty(json) && nTries1 < 5)
                    {
                        json = getJsonRest("flickr.photosets.getInfo", "user_id|photoset_id", tokens["user_id"] + "|" + phsid.id);
                        nTries1++;
                    }

                    if (!string.IsNullOrEmpty(json))
                    {
                        XmlDocument xd = new XmlDocument();

                        xd = (XmlDocument)JsonConvert.DeserializeXmlNode(json.ToString().Replace(".", ","), "result");
                        DataSet ds = new DataSet();
                        ds.ReadXml(new XmlNodeReader(xd));
                        using (DataTable dtph = ds.Tables["photoset"])
                        {
                            if (dtph != null)
                            {
                                for (int n = 0; n < dtph.Rows.Count; n++)
                                {
                                    DataRow dr = dtph.Rows[n];
                                    photoset ph = new photoset();
                                    ph = getPhotoset(dr);
                                    this.Invoke((MethodInvoker)delegate
                                    {
                                        label2.Text = phsid.title + "(" + ph.count_photos + ")";
                                        pBMove.Maximum = ph.count_photos;
                                        pBMove.Value = 0;
                                    });
                                    if (ph.pages == 0)
                                    {
                                        ph.pages = int.Parse(Math.Floor((double)ph.count_photos / 500) + "") + 1;
                                    }
                                    for (int i = 1; i <= ph.pages; i++)
                                    {

                                        string json2 = "";
                                        int nTries2 = 0;
                                        while (string.IsNullOrEmpty(json2) && nTries2 < 5)
                                        {
                                            json2 = getJsonRest("flickr.photosets.getPhotos", "user_id|photoset_id|page|extras", tokens["user_id"] + "|" + phsid.id + "|" + i + "|geo,tags");
                                            nTries2++;
                                        }
                                        if (!string.IsNullOrEmpty(json2))
                                        {
                                            XmlDocument xd2 = new XmlDocument();

                                            xd2 = (XmlDocument)JsonConvert.DeserializeXmlNode(json2.ToString(), "result");

                                            DataSet ds2 = new DataSet();
                                            ds2.ReadXml(new XmlNodeReader(xd2));
                                            using (DataTable dtph2 = ds2.Tables["photo"])
                                            {
                                                if (dtph2 != null)
                                                {
                                                    for (int n2 = 0; n2 < dtph2.Rows.Count; n2++)
                                                    {
                                                        DataRow dr2 = dtph2.Rows[n2];
                                                        photo ph2 = new photo();
                                                        ph2 = getPhoto(dr2);
                                                        phsid.photos.Add(ph2);
                                                        this.Invoke((MethodInvoker)delegate
                                                        {
                                                            if ((pBMove.Value + 1) > pBMove.Maximum)
                                                                pBMove.Maximum = pBMove.Value + 1;
                                                            pBMove.Value++;
                                                            label3.Text = "Photos:" + phsid.photos.Count;
                                                        });
                                                        if (chkAutoTag.Checked)
                                                        {
                                                            getExif(ph2, phsid.id);
                                                            if (!string.IsNullOrEmpty(ph2.place_id))
                                                                getPlace(ph2);
                                                            tagPhoto(ph2);
                                                        }
                                                    }
                                                }
                                            }
                                            this.Invoke((MethodInvoker)delegate
                                            {
                                                label3.Text = "Photos:" + phsid.photos.Count;
                                            });
                                        }//if json2 is null
                                    }//Pages loog
                                }//Photosets loop
                            }//if(dtph != null)
                        }//Using datatable
                    }//if json is null
                }//if phsid.title equals null
            }//for checked photosets loop
            this.Invoke((MethodInvoker)delegate {
                chkListFrom.Enabled = true;
            });
        }
Ejemplo n.º 2
0
        private void GetUntaggedPhotos(object state)
        {
            this.Invoke((MethodInvoker)delegate
            {
                pBSet.Maximum = 1;
                pBSet.Value = 0;
            });

            var phsid = phs.children.FirstOrDefault(x => x.title.Equals("untagged"));
            if (phsid == null)
                return;

            string json = "";
            int nTries1 = 0;
            while (string.IsNullOrEmpty(json) && nTries1 < 5)
            {
                json = getJsonRest("flickr.photos.getUntagged", "per_page", "500");
                nTries1++;
            }

            if (!string.IsNullOrEmpty(json))
            {
                XmlDocument xd = new XmlDocument();

                xd = (XmlDocument)JsonConvert.DeserializeXmlNode(json.ToString().Replace(".", ","), "result");
                DataSet ds = new DataSet();
                ds.ReadXml(new XmlNodeReader(xd));
                using (DataTable dtph = ds.Tables["photos"])
                {
                    if (dtph != null)
                    {
                            DataRow dr = dtph.Rows[0];
                            photoset ph = new photoset() { pages = int.Parse(dr["pages"].ToString()), count_photos = int.Parse(dr["total"].ToString()) };

                            this.Invoke((MethodInvoker)delegate
                            {
                                label2.Text = "(" + ph.count_photos + ")";
                                pBMove.Maximum = ph.count_photos;
                                pBMove.Value = 0;
                            });
                            if (ph.pages == 0)
                            {
                                ph.pages = int.Parse(Math.Floor((double)ph.count_photos / 500) + "") + 1;
                            }
                            List<double> dsecavg = new List<double>();

                            DateTime dtStartFirst = DateTime.Now;
                            for (int i = 1; i <= ph.pages; i++)
                            {
                                DateTime dtStart = DateTime.Now;
                                string json2 = "";
                                int nTries2 = 0;
                                while (string.IsNullOrEmpty(json2) && nTries2 < 5)
                                {
                                    json2 = getJsonRest("flickr.photos.getUntagged", "per_page|page|extras","500|" + i + "|geo");
                                    nTries2++;
                                }
                                if (!string.IsNullOrEmpty(json2))
                                {
                                    XmlDocument xd2 = new XmlDocument();

                                    xd2 = (XmlDocument)JsonConvert.DeserializeXmlNode(json2.ToString(), "result");

                                    DataSet ds2 = new DataSet();
                                    ds2.ReadXml(new XmlNodeReader(xd2));
                                    using (DataTable dtph2 = ds2.Tables["photo"])
                                    {
                                        if (dtph2 != null)
                                        {
                                            for (int n2 = 0; n2 < dtph2.Rows.Count; n2++)
                                            {

                                                DateTime dtStart2 = DateTime.Now;

                                                DataRow dr2 = dtph2.Rows[n2];
                                                photo ph2 = new photo();
                                                ph2 = getPhoto(dr2);
                                                //getPhotoInfo(ph2);
                                                phsid.photos.Add(ph2);
                                                this.Invoke((MethodInvoker)delegate
                                                {
                                                    if ((pBMove.Value + 1) > pBMove.Maximum)
                                                        pBMove.Maximum = pBMove.Value + 1;
                                                    pBMove.Value++;
                                                    label3.Text = "Photos:" + phsid.photos.Count;
                                                });
                                                if (chkAutoTag.Checked)
                                                {
                                                    getExif(ph2, phsid.id);
                                                    if (!string.IsNullOrEmpty(ph2.place_id))
                                                        getPlace(ph2);
                                                    tagPhoto(ph2);
                                                }

                                                DateTime dtEnd = DateTime.Now;

                                                TimeSpan ts = new TimeSpan(dtEnd.Ticks - dtStart2.Ticks);
                                                double sec = ts.TotalSeconds * ph.count_photos;
                                                dsecavg.Add(sec);
                                                double davg = dsecavg.Average();
                                                DateTime ddiff = dtStartFirst.AddSeconds(davg);
                                                this.Invoke((MethodInvoker)delegate
                                                {
                                                    label6.Text = "Time left:" + dtStartFirst.ToString("HH:mm:ss") + "+" + getFTime(davg) +"="+ ddiff.ToString("HH:mm:ss");
                                                });
                                            }
                                        }
                                    }
                                    this.Invoke((MethodInvoker)delegate
                                    {
                                        label3.Text = "Photos:" + phsid.photos.Count;
                                    });
                                }//if json2 is null


                            }//Pages loog
                    }//if(dtph != null)
                }//Using datatable
            }//if json is null

            this.Invoke((MethodInvoker)delegate
            {
                pBSet.Value++;
            });
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        private photoset getPhotoset(DataRow dr)
        {
            photoset w = new photoset();
            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;
        }
Ejemplo n.º 5
0
        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++;
            }
    
            
        }