예제 #1
0
        private void BGFindPhotosets(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            FlickrNet.Flickr f = FlickrManager.GetFlickrAuthInstance();
            if (f == null)
            {
                BGErrorMessage = "You must authenticate before you can download data from Flickr.";
                return;
            }

            try
            {
                int page    = 1;
                int perPage = 500;
                FlickrNet.PhotosetCollection photoSets      = new FlickrNet.PhotosetCollection();
                FlickrNet.PhotoSearchExtras  PhotosetExtras = 0;
                do
                {
                    photoSets = f.PhotosetsGetList(SearchAccountUser.UserId, page, perPage, PhotosetExtras);
                    foreach (FlickrNet.Photoset ps in photoSets)
                    {
                        PhotosetList.Add(new Photoset(ps));
                        int index = PhotosetList.Count - 1;
                        PhotosetList[index].OriginalSortOrder = index;
                    }
                    page = photoSets.Page + 1;
                }while (page <= photoSets.Pages);
            }
            catch (FlickrNet.FlickrException ex)
            {
                BGErrorMessage = "Album search failed. Error: " + ex.Message;
                return;
            }
        }
예제 #2
0
 public FormAddLoginAccount(Settings settings, FlickrManager flickrManager)
 {
     Settings      = settings;
     FlickrManager = flickrManager;
     InitializeComponent();
 }
예제 #3
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            Settings = Settings.Load();
            if (Settings.FormMainLocation.X != 0 ||
                Settings.FormMainLocation.Y != 0)
            {
                this.Location = Settings.FormMainLocation;
            }
            if (Settings.FormMainSize.Height != 0 ||
                Settings.FormMainSize.Width != 0)
            {
                this.Size = Settings.FormMainSize;
            }

            FlickrManager = new FlickrManager(Settings);

            // Bind the login account list.
            cbLoginAccount.DataSource    = Settings.FlickrLoginAccountList;
            cbLoginAccount.DisplayMember = "CombinedName";
            if (Settings.FlickrLoginAccountName.Length > 0)
            {
                int index = cbLoginAccount.FindString(Settings.FlickrLoginAccountName);
                if (index >= 0)
                {
                    cbLoginAccount.SelectedIndex = index;
                }
            }

            cbSearchAccount.DataSource    = Settings.FlickrSearchAccountList;
            cbSearchAccount.DisplayMember = "CombinedName";
            if (Settings.FlickrSearchAccountName.Length > 0)
            {
                int index = cbSearchAccount.FindString(Settings.FlickrSearchAccountName);
                if (index >= 0)
                {
                    cbSearchAccount.SelectedIndex = index;
                }
            }

            // For the Album (photoset) DataGridView, add a "select all" checkbox to the header row
            // Set checkbox header to center of header cell. This is kluge code from the internet,
            // modified slightly so it looks right on my system.
            Rectangle rect = dgvPhotosets.GetCellDisplayRectangle(0, -1, true);

            rect.X = rect.X + rect.Width / 4;
            rect.Y = rect.Y + 2;

            cbHeader = new CheckBox
            {
                Name     = "cbHeader",
                Size     = new System.Drawing.Size(18, 18),
                Location = rect.Location
            };
            cbHeader.CheckedChanged += new EventHandler(cbHeader_CheckedChanged);
            dgvPhotosets.Controls.Add(cbHeader);

            // set up bindings
            chkDownloadAllPhotos.DataBindings.Add("Checked", Settings, "DownloadAllPhotos", true, DataSourceUpdateMode.OnPropertyChanged);
            btnGetAlbums.DataBindings.Add("Enabled", Settings, "GetAlbumsEnabled");
            chkFilterDate.DataBindings.Add("Checked", Settings, "FilterByDate", true, DataSourceUpdateMode.OnPropertyChanged);
            dateTimePickerStart.DataBindings.Add("Value", Settings, "StartDate", true, DataSourceUpdateMode.OnPropertyChanged);
            dateTimePickerStart.DataBindings.Add("Enabled", Settings, "FilterDateEnabled");
            dateTimePickerStop.DataBindings.Add("Value", Settings, "StopDate", true, DataSourceUpdateMode.OnPropertyChanged);
            dateTimePickerStop.DataBindings.Add("Enabled", Settings, "FilterDateEnabled");
            txtOutputFolder.DataBindings.Add("Text", Settings, "OutputFolder");

            Settings.UpdateEnabledProperties();

            FormIsLoaded = true;
        }
예제 #4
0
        // Background worker task to search selected photosets.
        private void BGDownloadPhotosets(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;

            worker.ReportProgress(0, "Connecting");

            PhotoList = new SortableBindingList <Photo>();

            // Count the number of enabled photosets, so we can do an estimate of percent complete;
            int enabledPhotosets = 0;

            foreach (Photoset photoset in PhotosetList)
            {
                if (photoset.EnableSearch)
                {
                    enabledPhotosets++;
                }
            }

            if (enabledPhotosets == 0)
            {
                // No photosets are enabled. We are done.
                return;
            }

            try
            {
                int indexPhotoset = 0;

                FlickrNet.Flickr f = FlickrManager.GetFlickrAuthInstance();
                if (f == null)
                {
                    BGErrorMessage = "You must authenticate before you can download data from Flickr.";
                    return;
                }

                // Iterate over the photosets and get the photos from each set.
                FlickrNet.PhotosetPhotoCollection photoCollection = new FlickrNet.PhotosetPhotoCollection();

                foreach (Photoset photoset in PhotosetList)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    if (photoset.EnableSearch)
                    {
                        int    percent     = indexPhotoset * 100 / enabledPhotosets;
                        string description = "Searching Album " + photoset.Title;
                        worker.ReportProgress(percent, description);

                        int page    = 1;
                        int perpage = 500;
                        do
                        {
                            if (worker.CancellationPending) // See if cancel button was pressed.
                            {
                                e.Cancel = true;
                                return;
                            }

                            photoCollection = f.PhotosetsGetPhotos(photoset.PhotosetId, SearchExtras, page, perpage);
#if false
                            // It is not clear from the documentation whether the limit of 4000 photos per search applies
                            // to album searches. If an album has more than 4000 photos, is the result of GetPhotos
                            // accurate? I'm going to assume for now that it is. If not, you can enable this code.
                            if (photoCollection.Total > 3999)
                            {
                                BGErrorMessage = $"Too many photos: {photoCollection.Total}";
                                return;
                            }
#endif
                            foreach (FlickrNet.Photo flickrPhoto in photoCollection)
                            {
                                AddPhotoToList(f, flickrPhoto, photoset);
                            }
                            // Calculate percent complete based on both how many photo sets we have completed,
                            // plus how many pages we have read
                            percent = (indexPhotoset * 100 + page * 100 / photoCollection.Pages) / enabledPhotosets;
                            worker.ReportProgress(percent, description);
                            page = photoCollection.Page + 1;
                        }while (page <= photoCollection.Pages);

                        indexPhotoset++;
                    }
                }
            }
            catch (FlickrNet.FlickrException ex)
            {
                BGErrorMessage = "Search failed. Error: " + ex.Message;
                return;
            }

            DownloadFiles(sender, e);
        }
예제 #5
0
        private void BGDownloadAllPhotos(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;

            PhotoList = new SortableBindingList <Photo>();

            worker.ReportProgress(0, "Searching all photos");

            FlickrNet.Flickr f = FlickrManager.GetFlickrAuthInstance();
            if (f == null)
            {
                BGErrorMessage = "You must authenticate before you can download data from Flickr.";
                return;
            }

            try
            {
                FlickrNet.PhotoSearchOptions options = new FlickrNet.PhotoSearchOptions();
                options.Extras    = SearchExtras;
                options.SortOrder = FlickrNet.PhotoSearchSortOrder.DateTakenAscending;
                if (Settings.FilterByDate)
                {
                    options.MinTakenDate = Settings.StartDate.Date;
                    options.MaxTakenDate = Settings.StopDate.Date + new TimeSpan(23, 59, 59);
                }
                options.UserId  = SearchAccountUser.UserId;
                options.Page    = 1;
                options.PerPage = 500;

                FlickrNet.PhotoCollection photoCollection;
                do
                {
                    if (worker.CancellationPending) // See if cancel button was pressed.
                    {
                        return;
                    }

                    photoCollection = f.PhotosSearch(options);
                    if (photoCollection.Total > 3999)
                    {
                        BGErrorMessage = $"Too many photos: {photoCollection.Total}";
                        return;
                    }
                    foreach (FlickrNet.Photo flickrPhoto in photoCollection)
                    {
                        AddPhotoToList(f, flickrPhoto, null);
                    }
                    // Calculate percent complete based on how many pages we have completed.
                    int percent = (options.Page * 100 / photoCollection.Pages);
                    worker.ReportProgress(percent, "Searching all photos");

                    options.Page = photoCollection.Page + 1;
                }while (options.Page <= photoCollection.Pages);
            }
            catch (FlickrNet.FlickrException ex)
            {
                BGErrorMessage = "Download failed. Error: " + ex.Message;
                return;
            }

            DownloadFiles(worker, e);
        }