Example #1
0
 public void AddOrUpdate(PhotosetCollection setL)
 {
     foreach (var item in setL)
     {
         AddOrUpdate(item);
     }
 }
        public List <Album> GetAlbums()
        {
            PhotosetCollection albums    = Flickr.PhotosetsGetList();
            List <Album>       albumlist = albums.Select(x => Album.CreateAlbum(x)).ToList();

            return(albumlist);
        }
Example #3
0
        /// <summary>
        /// Load user data for the selected user.
        /// </summary>
        private void LoadUserData(object userid)
        {
            UpdateStatusLabel("Retrieving user data from Flickr...");
            SetProgressMax(3);

            Identity id = (Identity)userid;

            ConfigInfo.FlickrApiToken = IdentityManager.GetUserToken(id.TokenFile);
            Flickr flickr = new Flickr(ConfigInfo.FlickrApiKey, ConfigInfo.FlickrApiSecret, ConfigInfo.FlickrApiToken);

            IncrementProgress(1);

            UpdateStatusLabel("Downloading Sets...");
            PhotosetCollection sets = flickr.PhotosetsGetList();

            IncrementProgress(1);

            SetProgressMax((sets.Count) * 3);
            SetProgressValue((sets.Count) * 2);

            UpdateStatusLabel("Loading Set Info...");
            foreach (Photoset p in sets)
            {
                AddItemToSetsList(p.Title);
                photoSetCollection.Add(p.Title, new FlickrSet(p));
                IncrementProgress(1);
            }

            SetProgressValue(0);
            UpdateStatusLabel("Identity Loaded.");
        }
        public IEnumerable <string> GetRoots()
        {
            yield return("/"); // for photos not in a set

            int page     = 1;
            int maxPages = 1;

            while (page <= maxPages)
            {
                // existing sources gives us a list of photoset ids
                PhotosetCollection photosets;
                try
                {
                    photosets = _flickr.PhotosetsGetList();
                    maxPages  = photosets.Pages;
                    page++;
                }
                catch
                {
                    photosets = new PhotosetCollection();
                }
                foreach (var root in photosets.Select(s => s.PhotosetId + "/"))
                {
                    yield return(root);
                }
            }
        }
 public void AddOrUpdate(PhotosetCollection setL)
 {
     foreach (var item in setL)
     {
         AddOrUpdate(item);
     }
 }
Example #6
0
        public void RemoveNonExisting(PhotosetCollection setL)
        {
            var d = db.Sets.ToList().Where(r => (setL.Select(r1 => r1.PhotosetId).Contains(r.SetsID) == false) &&
                                           r.UserID == Flickr.User.UserId);

            db.Sets.RemoveRange(d);
            db.SaveChanges();
        }
        public Albums Convert(PhotosetCollection photosets)
        {
            var items = photosets
                .Select(Convert)
                .ToArray();

            return new Albums(items);
        }
Example #8
0
        public Albums Convert(PhotosetCollection photosets)
        {
            var items = photosets
                        .Select(Convert)
                        .ToArray();

            return(new Albums(items));
        }
Example #9
0
        public string UploadPhotographToFlickr(string flickrAuth, string title, string description, string path, string tag)
        {
            try
            {
                flickr.AuthToken = flickrAuth;

                bool uploadAsPublic = true;

                string photoId = flickr.UploadPicture(ConfigurationManager.AppSettings["TempFileLocalPath"].ToString(), title, description, tag, uploadAsPublic, false, false);
                if (photoId != null && photoId != "")
                {
                    bool setFlag = false;

                    // Get list of users sets
                    PhotosetCollection sets = flickr.PhotosetsGetList();

                    //add photo to appropriate skichair photoset
                    foreach (Photoset set in sets)
                    {
                        if (set.Title.Equals(tag))
                        {
                            setFlag = true;
                            //add the photo to that set
                            AddPhotoToPhotoset(set.PhotosetId, photoId);
                            break;
                        }
                    }

                    //if photoset didn't exist create it
                    if (!setFlag)
                    {
                        //create photoset and add photo to it
                        CreateFlickrPhotoSet(tag, photoId);
                        flickr.GroupsPoolsAdd(photoId, Utility.FlickrGroupID);
                    }

                    return(photoId);
                }
                else
                {
                    return("");
                }
            }
            catch (Exception ex)
            {
                System.IO.StreamWriter sw = System.IO.File.AppendText(ConfigurationManager.AppSettings["ErrorLogPath"].ToString() + "SkiChairErrorLogFile.txt");
                try
                {
                    string logLine = System.String.Format("{0:G}: {1}.", System.DateTime.Now, "Error: " + ex.Message);
                    sw.WriteLine(logLine);
                }
                finally
                {
                    sw.Close();
                }
                return("");
            }
        }
Example #10
0
        public void UpdateStatusBar()
        {
            int photos = 0;
            PhotosetCollection allsets = ri.GetAllSets();

            for (int i = 0; i < allsets.Count; i++)
            {
                photos += allsets[i].NumberOfPhotos;
            }

            labelStatus.Text = string.Format("Sets on Flickr: {0}       Photos on Flickr: {1}", allsets.Count, photos);
        }
Example #11
0
        public void PhotosetsGetListWebUrlTest()
        {
            PhotosetCollection photosets = Instance.PhotosetsGetList(TestData.TestUserId);

            Assert.IsTrue(photosets.Count > 0, "Should be at least one photoset");

            foreach (Photoset set in photosets)
            {
                Assert.IsNotNull(set.Url);
                string expectedUrl = "https://www.flickr.com/photos/" + TestData.TestUserId + "/sets/" + set.PhotosetId + "/";
                Assert.AreEqual(expectedUrl, set.Url);
            }
        }
Example #12
0
        public void PhotosetsOrderSetsArrayTest()
        {
            PhotosetCollection mySets = f.PhotosetsGetList();

            List <string> setIds = new List <string>();

            foreach (Photoset myset in mySets)
            {
                setIds.Add(myset.PhotosetId);
            }

            f.PhotosetsOrderSets(setIds.ToArray());
        }
Example #13
0
        /// <summary>
        /// this method will get a list of all the photograph gallerys associated with ski chair
        /// </summary>
        /// <returns>generic list of strings</returns>
        public List <string> GetPhotoGalleryMenu()
        {
            List <string> photoGalleryMenu = new List <string>();

            //will only select photographs for the signed in user
            PhotosetCollection photoSets = flickr.PhotosetsGetList(Utility.FlickrUserID);

            foreach (Photoset photoSet in photoSets)
            {
                photoGalleryMenu.Add(photoSet.Title + ":" + photoSet.PhotosetId);
            }

            return(photoGalleryMenu);
        }
Example #14
0
        private void LoadUserData()
        {
            Identity id = (Identity)cboIdentities.SelectedItem;

            ConfigInfo.FlickrApiToken = IdentityManager.GetUserToken(id.TokenFile);

            Flickr             flickr = new Flickr(ConfigInfo.FlickrApiKey, ConfigInfo.FlickrApiSecret, ConfigInfo.FlickrApiToken);
            PhotosetCollection sets   = flickr.PhotosetsGetList();

            foreach (Photoset p in sets)
            {
                lstSets.Items.Add(p.Title);
            }
        }
Example #15
0
        private String GetPhotoSetID(String Sets)
        {
            Flickr             f         = FlickrManager.GetAuthInstance();
            PhotosetCollection photosets = f.PhotosetsGetList();

            foreach (Photoset pset in photosets)
            {
                if (Sets == pset.Title)
                {
                    return(pset.PhotosetId);
                }
                Console.WriteLine(pset.Title);
            }
            return("");
        }
Example #16
0
        public void PhotosetsGetListBasicTest()
        {
            PhotosetCollection photosets = Instance.PhotosetsGetList(TestData.TestUserId);

            Assert.IsTrue(photosets.Count > 0, "Should be at least one photoset");
            Assert.IsTrue(photosets.Count > 100, "Should be greater than 100 photosets. (" + photosets.Count + " returned)");

            foreach (Photoset set in photosets)
            {
                Assert.IsNotNull(set.OwnerId, "OwnerId should not be null");
                Assert.IsTrue(set.NumberOfPhotos > 0, "NumberOfPhotos should be greater than zero");
                Assert.IsNotNull(set.Title, "Title should not be null");
                Assert.IsNotNull(set.Description, "Description should not be null");
                Assert.AreEqual(TestData.TestUserId, set.OwnerId);
            }
        }
Example #17
0
        private void btnValidation_Click(object sender, RoutedEventArgs e)
        {
            // Récupère l'autentification
            try
            {
                autFlickr = conFlickr.AuthGetToken(tempFrob);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Une erreur vient de ce produire :" + Environment.NewLine + ex.Message,
                                "Erreur d'authentification à Flickr", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            // Active le bouton "Suivant"
            btnSuivant.IsEnabled = true;

            // Affiche le quota restant
            if (conFlickr.PeopleGetUploadStatus().IsPro == false)
            {
                lblQuota.Content = String.Format("Quota restant sur votre compte Flickr : {0} Kio",
                                                 conFlickr.PeopleGetUploadStatus().BandwidthRemainingKB);
            }
            else
            {
                lblQuota.Content = "Quota restant sur votre compte Flickr : ∞ Kio";
            }

            // Affiche un message de bienvenue
            MessageBox.Show("Bienvenue " + conFlickr.PeopleGetUploadStatus().UserName + " !", "Bienvenue",
                            MessageBoxButton.OK, MessageBoxImage.Information);

            // Récupère la liste des albums
            cmbAlbum.Items.Clear();
            listeAlbums.Clear();
            cmbAlbum.Items.Add("Sélectionnez un album");
            listeAlbums.Add("-1");
            cmbAlbum.Items.Add("Ajoutez un nouvel album…");
            listeAlbums.Add("0");
            PhotosetCollection lstAlbums = conFlickr.PhotosetsGetList();

            foreach (Photoset album in lstAlbums)
            {
                cmbAlbum.Items.Add(album.Title);
                listeAlbums.Add(album.PhotosetId);
            }
            cmbAlbum.SelectedIndex = 0;
        }
Example #18
0
        public void FillListSet(ProgressBar progress)
        {
            int photos = 0;
            PhotosetCollection allsets = ri.GetAllSets();

            if (progress != null)
            {
                progress.Minimum = 0;
                progress.Maximum = allsets.Count;
                progress.Value   = 0;
            }

            // Setup the image list first to speed things up.
            Image[] tempimgs     = new Image[allsets.Count];
            Image[] tempimgsmall = new Image[allsets.Count];

            for (int i = 0; i < allsets.Count; i++)
            {
                // use a fixed temporary image
                tempimgs[i]     = global::FlickrSync.Properties.Resources.icon_default;
                tempimgsmall[i] = global::FlickrSync.Properties.Resources.icon_default;
            }
            imageListLarge.Images.AddRange(tempimgs);
            imageListSmall.Images.AddRange(tempimgsmall);

            for (int i = 0; i < allsets.Count; i++)
            {
                Photoset psi = allsets[i];
                Image    img = ri.PhotosetThumbnail(psi);
                imageListLarge.Images[i] = img;
                imageListLarge.Images.SetKeyName(i, psi.PhotosetId);
                imageListSmall.Images[i] = img.GetThumbnailImage(16, 16, null, IntPtr.Zero);
                imageListSmall.Images.SetKeyName(i, psi.PhotosetId);

                ListViewItem lvi = listSets.Items.Add(psi.PhotosetId, psi.Title, psi.PhotosetId);
                lvi.SubItems.Add(psi.NumberOfPhotos.ToString());
                lvi.SubItems.Add(psi.Description);

                if (progress != null)
                {
                    progress.Value = i;
                }
                photos += psi.NumberOfPhotos;
            }

            labelStatus.Text = string.Format("Sets on Flickr: {0}       Photos on Flickr: {1}", allsets.Count, photos);
        }
Example #19
0
        private void CreateFlickrObject()
        {
            f = new Flickr(Properties.Settings.Default.FlickrApiKey, Properties.Settings.Default.FlickrShared);
            OAuthAccessToken oauth = Properties.Settings.Default.OAuthToken;

            f.OAuthAccessToken       = oauth.Token;
            f.OAuthAccessTokenSecret = oauth.TokenSecret;

            f.Proxy             = FlickrSync.GetProxy(true);
            f.HttpTimeout       = 240000;
            f.OnUploadProgress += new EventHandler <FlickrNet.UploadProgressEventArgs>(Flickr_OnUploadProgress);
            sets = f.PhotosetsGetList();
            if (sets == null)
            {
                sets = new PhotosetCollection();
            }

            string user = User();  //force access to check connection
        }
Example #20
0
        /// <summary>
        /// dohledani seznamu PhotoSetu
        /// </summary>
        public PhotosetCollection VtPhotosetsGetList()
        {
            var photosetCollection = new PhotosetCollection();

            var startTime = DateTime.Now;
            PhotosetCollection searchedForPage = null;
            var page = 1;

            do
            {
                RaiseSearchProgressEvent("PhotosetsGetList", photosetCollection.Count, startTime);

                searchedForPage = PhotosetsGetList(page, SearchOptions_PerPage_MAX);
                foreach (var photoset in searchedForPage)
                {
                    photosetCollection.Add(photoset);
                }
                page++;
            } while (searchedForPage.Count >= SearchOptions_PerPage_MAX);

            return(photosetCollection);
        }
 public void RemoveNonExisting(PhotosetCollection setL)
 {
     var d = db.Sets.ToList().Where(r => (setL.Select(r1 => r1.PhotosetId).Contains(r.SetsID) == false)
         && r.UserID == Flickr.User.UserId);
     db.Sets.RemoveRange(d);
     db.SaveChanges();
 }
Example #22
0
 public void Reload()
 {
     Flickr.CacheDisabled = true;
     sets = f.PhotosetsGetList();
     Flickr.CacheDisabled = false;
 }
 public PhotosetsSearchAllProgressEventData(DateTime startTime, PhotosetCollection photosetCollection, bool searchFinished = false)
     : base(startTime, searchFinished)
 {
     PhotosetCollection = photosetCollection;
 }
Example #24
0
        public void PhotosetsOrderSetsArrayTest()
        {
            PhotosetCollection mySets = AuthInstance.PhotosetsGetList();

            AuthInstance.PhotosetsOrderSets(mySets.Select(myset => myset.PhotosetId));
        }
Example #25
0
        public Albums GetAlbumsOf(string userId)
        {
            PhotosetCollection photosets = _flickrPhotoProvider.GetAlbumsOf(userId);

            return(_flickrConverter.Convert(photosets));
        }
        /// <summary>
        /// Gets all sets
        /// </summary>
        /// <exception cref="System.Exception">flickr error</exception>
        private void Refresh()
        {
            _collection = _flickr.PhotosetsGetList();

            //            _collection = _flickr.PhotosetsGetList(1,500);
        }
Example #27
0
 public PhotosetSearchPageResult(int page, PhotosetCollection photosetCollection) : base()
 {
     Page = page;
     PhotosetCollection = photosetCollection;
 }
Example #28
0
        /// <summary>
        /// The main thread
        /// </summary>
        void UploadPhotoList()
        {
            // If a folder is just a date (yyyy-mm-dd), we don't upload it - we only do so if
            // some text has been added to provide a meaningful name. This regex extracts the
            // meaningful part of the name in group 1
            Regex alt = new Regex(@"^[\d- ]*(.*?)$", RegexOptions.Compiled);
            PowerModeChangedEventHandler eh = null;

            if (Settings.Default.WaitLogging)
            {
                Log("Adding power handler");
                eh = new PowerModeChangedEventHandler(delegate(object sender, PowerModeChangedEventArgs e) {
                    Log("Power " + e.Mode);
                });
                SystemEvents.PowerModeChanged += eh;
            }
            try {
                do
                {
                    try {
                        Form.Log("Starting");
                        Form.Sets    = Sets = new Dictionary <string, Set>();
                        Form.AltSets = AltSets = new Dictionary <string, Set>();
                        Form.ClearFolders();
                        Form.LogError("");
                        foreach (string folder in Directory.EnumerateDirectories(Settings.Default.Folder))
                        {
                            if (TaskCancelled())
                            {
                                return;
                            }
                            Form.Status("Loading folder {0}", folder);
                            Set s = new Set(folder);
                            if (s.Photos.Count > 0)
                            {
                                Match m = alt.Match(s.Folder.Name);
                                if (m.Success)
                                {
                                    // The folder name starts with a date
                                    string key = m.Groups[1].Value;
                                    if (key == "")
                                    {
                                        Form.Error("Ignored folder {0} with no description", folder);
                                        continue;
                                    }
                                    // Index set by name part only, in case date has been removed from Flickr set name
                                    AltSets[key] = s;
                                }
                                Sets[s.Folder.Name] = s;
                                Form.AddFolder(s);
                            }
                        }
                        // Have finished building local folder list
                        Form.Status("");
                        // Now compute hashes
                        foreach (Set s in Sets.Values)
                        {
                            if (TaskCancelled())
                            {
                                return;
                            }
                            Form.Status("Checking folder {0}", s.Folder.Name);
                            int i = 0;
                            foreach (PhotoInfo p in s.Photos)
                            {
                                if (TaskCancelled())
                                {
                                    return;
                                }
                                p.LoadHash();
                                Form.UpdatePhoto(s, i++);
                            }
                        }
                        Form.Status("");
                        if (Settings.Default.AccessToken == null)
                        {
                            Form.Log("Not logged in");
                            return;
                        }
                        // Wait until start time (if a start time is specified)
                        if (Wait(false))
                        {
                            return;
                        }
                        // Prevent computer going to sleep during upload
                        uint executionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
                        if (executionState == 0)
                        {
                            Form.LogError("SetThreadExecutionState failed.");
                        }
                        try {
                            Form.Status("Downloading Flickr sets");
                            // Get Flickr sets
                            PhotosetCollection sets = Flickr.PhotosetsGetList(1, 1000);
                            if (TaskCancelled())
                            {
                                return;
                            }
                            foreach (Photoset set in sets)
                            {
                                Set ours;
                                // Match Flickr sets to ours
                                if (Sets.TryGetValue(set.Title, out ours) || AltSets.TryGetValue(set.Title, out ours))
                                {
                                    ours.Id = set.PhotosetId;
                                }
                            }
                            foreach (Set s in Sets.Values)
                            {
                                if (TaskCancelled())
                                {
                                    return;
                                }
                                // Photos matched in the Flickr set
                                HashSet <PhotoInfo> matched = new HashSet <PhotoInfo>();
                                bool changed = false;
                                if (s.Id != null)
                                {
                                    // There is a Flickr set - get Flickr's list of photos in the set
                                    Form.Status("Downloading photo details for set {0}", s.Folder.Name);
                                    foreach (Photo p in Flickr.PhotosetsGetPhotos(s.Id, PhotoSearchExtras.DateUploaded, 1, 1000))
                                    {
                                        if (TaskCancelled())
                                        {
                                            return;
                                        }
                                        // Match by Id, name, file name or description
                                        PhotoInfo info = s.Photos.FirstOrDefault(pf => pf.Flickr.Id == p.PhotoId ||
                                                                                 pf.Name == p.Title ||
                                                                                 pf.FileName == p.Title ||
                                                                                 pf.Description == p.Description);
                                        if (info != null)
                                        {
                                            matched.Add(info);
                                            if (info.Flickr.Uploaded != p.DateUploaded)
                                            {
                                                changed = true;
                                            }
                                            info.Flickr.Id       = p.PhotoId;
                                            info.Flickr.Uploaded = p.DateUploaded;
                                        }
                                    }
                                }
                                // Now look for local photos not in the Flickr set
                                foreach (PhotoInfo p in s.Photos)
                                {
                                    if (!matched.Contains(p))
                                    {
                                        if (p.Flickr.Id != null)
                                        {
                                            // Photo is already on Flickr, but is not in this set
                                            if (TaskCancelled())
                                            {
                                                return;
                                            }
                                            if (DateTime.Now >= stop)
                                            {
                                                Form.Log("Reached stop time");
                                                return;
                                            }
                                            try {
                                                Flickr.PhotosetsAddPhoto(s.Id, p.Flickr.Id);
                                            } catch {
                                                // Cannot add photo - perhaps it was deleted from Flickr - mark it as missing
                                                p.Flickr.Id       = null;
                                                p.Flickr.Uploaded = null;
                                                changed           = true;
                                            }
                                        }
                                    }
                                }
                                if (changed)
                                {
                                    Form.UpdateSet(s);
                                }
                                // Upload remaining photos
                                foreach (PhotoInfo p in s.Photos)
                                {
                                    if (TaskCancelled())
                                    {
                                        return;
                                    }
                                    if (p.Flickr.Id != null)
                                    {
                                        continue;                                               // Photo is already on Flickr
                                    }
                                    if (DateTime.Now >= stop)
                                    {
                                        Form.Log("Reached stop time");
                                        return;
                                    }
                                    Form.Log("Uploading {0}", p.FullName);
                                    try {
                                        if (TaskCancelled())
                                        {
                                            return;
                                        }
                                        p.Flickr.Id       = Flickr.UploadPicture(p.FullName, p.Name, p.Description, "", false, true, false);
                                        p.Flickr.Uploaded = DateTime.Now;
                                        if (changed)
                                        {
                                            Form.UpdatePhoto(s, s.Photos.IndexOf(p));
                                        }
                                        if (s.Id == null)
                                        {
                                            Form.Log("Creating set {0}", s.Folder.Name);
                                            s.Id = Flickr.PhotosetsCreate(s.Folder.Name, p.Flickr.Id).PhotosetId;
                                        }
                                        else
                                        {
                                            Flickr.PhotosetsAddPhoto(s.Id, p.Flickr.Id);
                                        }
                                    } catch (Exception ex) {
                                        Form.LogError("Exception: {0}", ex);
                                    }
                                }
                            }
                            Form.Status("");
                            Form.LogError("Completed");
                        } finally {
                            if (executionState != 0)
                            {
                                NativeMethods.SetThreadExecutionState(executionState);
                            }
                        }
                    } catch (Exception ex) {
                        try {
                            Form.LogError("Exception: {0}", ex);
                        } catch {
                        }
                    }
                } while (!Wait(true));
            } finally {
                if (eh != null)
                {
                    Log("Removing power handler");
                    SystemEvents.PowerModeChanged -= eh;
                }
            }
        }