Exemple #1
0
        private void getPlace(photo ph2)
        {
            
            if (!tokens.ContainsKey("oauth_token") || !tokens.ContainsKey("oauth_token_secret") )
            {
                return;
            }
            if (!places.Any(x => x.place_id.Equals(ph2.place_id)))
            {
                place place = new place() { place_id = ph2.place_id };
                string json = getJsonRest("flickr.places.getInfo", "place_id", ph2.place_id);
                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 dt = ds.Tables["locality"])
                    {
                        if (dt != null)
                        {
                            place.locality = dt.Rows[0][0].ToString();
                        }
                    }
                    using (DataTable dt = ds.Tables["region"])
                    {
                        if (dt != null)
                        {
                            place.region = dt.Rows[0][0].ToString();
                        }
                    }
                    using (DataTable dt = ds.Tables["county"])
                    {
                        if (dt != null)
                        {
                            place.county = dt.Rows[0][0].ToString();
                        }
                    }
                    using (DataTable dt = ds.Tables["country"])
                    {
                        if (dt != null)
                        {
                            place.country = dt.Rows[0][0].ToString();
                        }
                    }
                }                
                ph2.place = place;
                places.Add(place);
            }
            else
            {
                var place = places.FirstOrDefault(x => x.place_id.Equals(ph2.place_id));
                if(place!=null)
                {
                    ph2.place = place;
                }
            }
        }
Exemple #2
0
        private void getPhotoInfo(photo ph2)
        {

            if (!tokens.ContainsKey("oauth_token") || !tokens.ContainsKey("oauth_token_secret"))
            {
                return;
            }
            string json = "";
            int nTries = 0;
            while (string.IsNullOrEmpty(json) && nTries < 5)
            {
                json = getJsonRest("flickr.photos.getInfo", "photo_id", ph2.id);
                nTries++;
            }
                
            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 dt = ds.Tables["photo"])
                {
                    if (dt != null)
                    {
                        photo p = getPhoto(dt.Rows[0]);
                        ph2 = p;
                    }
                }
            }
        }
Exemple #3
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;
            });
        }
Exemple #4
0
        private void GetNotInSet(object state)
        {
            var phsid = phs.children.FirstOrDefault(x => x.title.Equals("none"));
            if (phsid == null)
                return;

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

            if (!string.IsNullOrEmpty(jsonn))
            {
                XmlDocument xd2 = new XmlDocument();

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

                DataSet dsp = new DataSet();
                dsp.ReadXml(new XmlNodeReader(xd2));
                int pages=0;
                int total = 0;
                using (DataTable dtphs = dsp.Tables["photos"])
                {
                    if (dtphs != null)
                    {
                        DataRow drp = dtphs.Rows[0];
                        pages = int.Parse(drp["pages"].ToString());
                        total = int.Parse(drp["total"].ToString());

                        this.Invoke((MethodInvoker)delegate
                        {
                            label2.Text = "Photoset:" + total;
                            pBMove.Maximum = total;
                            pBMove.Value = 0;
                        });
                    }
                }
                for (int p = 1; p <= pages; p++)
                {
                    string jsonnp = "";
                    int nTriesp = 0;
                    while (string.IsNullOrEmpty(jsonnp) && nTriesp < 5)
                    {
                        jsonnp = getJsonRest("flickr.photos.getNotInSet", "per_page|page", "500|" + p);
                        nTriesp++;
                    }
                    if (!string.IsNullOrEmpty(jsonnp))
                    {
                        XmlDocument xd = new XmlDocument();

                        xd = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonn.ToString(), "result");

                        DataSet ds = new DataSet();
                        ds.ReadXml(new XmlNodeReader(xd2));

                        using (DataTable dtph2 = ds.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
                                    {
                                        label3.Text = "Photos:" + phsid.photos.Count;
                                        if ((pBMove.Value + 1) > pBMove.Maximum)
                                            pBMove.Maximum = pBMove.Value + 1;
                                        pBMove.Value++;
                                        
                                    });
                                    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;
                        });
                    }
                }
            }        
        }
Exemple #5
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++;
            });
        }
Exemple #6
0
        private photo getPhoto(DataRow dr)
        {
            photo w = new photo();
            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;
        }
Exemple #7
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++;
            }
    
            
        }
Exemple #8
0
        private void tagPhoto(photo p)
        {
            if (!tokens.ContainsKey("oauth_token") || !tokens.ContainsKey("oauth_token_secret") || !tokens.ContainsKey("user_id"))
            {
                return;
            }

            string json = "";
            int ntries = 0;
            string tags = "";
            if (!string.IsNullOrEmpty(p.make))
            {
                tags = p.make.Split(' ')[0].Replace(",","");
                addToMake(p);
                if(!string.IsNullOrEmpty(p.model))
                    tags += " "  + (p.model + "").Replace(",", ".");
                if(p.datetimeoriginal>DateTime.MinValue)
                    tags += " "+ p.datetimeoriginal.Year + " " + p.datetimeoriginal.ToString("MMMM") + " " + p.datetimeoriginal.DayOfWeek;
            }
            if (!string.IsNullOrEmpty(p.place_id))
            {
                if (p.place != null)
                {
                    tags += " " + (p.place.country + "").Replace(",", " ");
                    tags += " " + (p.place.county + "").Replace(",", " ");
                    tags += " " + (p.place.locality + "").Replace(",", " ");
                    tags += " " + (p.place.region + "").Replace(",", " ");
                }
            }
            tags += " " + p.tags;
            if (!string.IsNullOrEmpty(tags) && tags.Length>3)
            {
                while (string.IsNullOrEmpty(json) && ntries < 5)
                {
                    json = getJsonRest("flickr.photos.setTags", "photo_id|tags", p.id + "|" + tags);
                    ntries++;
                }
            }
            
        }
Exemple #9
0
        private void getExif(photo ph,string photosetid )
        {
            if (!tokens.ContainsKey("oauth_token") || !tokens.ContainsKey("oauth_token_secret") || !tokens.ContainsKey("user_id"))
            {
                return;
            }
            var phsid = phs.children.FirstOrDefault(x => x.id==photosetid || x.id.Equals(photosetid));
            if (phsid == null)
                return;

            string json = getJsonRest("flickr.photos.getExif", "photo_id|secret", ph.id + "|" + ph.secret);
            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 dtex = ds.Tables["exif"])
                {
                    if (dtex != null)
                    {
                        DataTable dtr = ds.Tables["raw"];
                        for (int n = 0; n < dtex.Rows.Count; n++)
                        {
                            //photo ph = phsid.photos.FirstOrDefault(x => x.id.Equals(id));
                            DataRow drex = dtex.Rows[n];
                            DataRow drt = dtr.Rows[n];
                            //Make,Model,DateTimeOriginal

                            if (drex != null)
                            {
                                string label = drex["tag"].ToString();
                                string val = drt[0].ToString();
                                if (label.Equals("make", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    ph.make = val;
                                }
                                else if (label.Equals("model", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    ph.model = val;
                                }
                                else if (label.Equals("DateTimeOriginal", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    try
                                    {
                                        string[] vd = val.Split(' ')[0].Split(':');
                                        string[] vh = val.Split(' ')[1].Split(':');
                                        DateTime dtout = new DateTime(int.Parse(vd[0]), int.Parse(vd[1]), int.Parse(vd[2]), int.Parse(vh[0]), int.Parse(vh[1]), int.Parse(vh[2]));
                                        ph.datetimeoriginal = dtout;
                                    }
                                    catch { }
                                }
                            }

                        }
                    }
                }
            }
        }