private FlickrNet.Sizes SafelyGetSizes(string photoid) { FlickrNet.Sizes sizes = null; for (int i = 0; i < MAXTRIES; i++) { try { sizes = flickrObj.PhotosGetSizes(photoid); return(sizes); } catch (FlickrNet.FlickrApiException e) { // Maximum attempts over. if (i == MAXTRIES - 1) { PrintException(e); if (e.Code == CODE_TIMEOUT) { _isConnected = false; } return(null); } continue; } } throw new Exception("FlickrCommunicator: GetSizes(photoid) unreachable code"); }
private void CheckPhotosToDownload() { ArrayList entries = PersistentInformation.GetInstance().GetEntriesToDownload(); Gtk.Application.Invoke(delegate { DeskFlickrUI.GetInstance().SetStatusLabel("Downloading photos..."); DeskFlickrUI.GetInstance().SetLimitsProgressBar(entries.Count); }); foreach (PersistentInformation.Entry entry in entries) { string photoid = entry.entry1; string foldername = entry.entry2; FlickrNet.Sizes photosizes = SafelyGetSizes(photoid); if (photosizes == null) { continue; } Photo p = PersistentInformation.GetInstance().GetPhoto(photoid); Gtk.Application.Invoke(delegate { string label = String.Format( "Downloading {0}... Saving to {1}", p.Title, foldername); DeskFlickrUI.GetInstance().SetStatusLabel(label); }); Hashtable table = new Hashtable(); foreach (FlickrNet.Size size in photosizes.SizeCollection) { table.Add(size.Label.ToLower(), size.Source); } string sourceurl; if (table.ContainsKey("original")) { sourceurl = (string)table["original"]; } else if (table.ContainsKey("large")) { sourceurl = (string)table["large"]; } else if (table.ContainsKey("medium")) { sourceurl = (string)table["medium"]; } else { PersistentInformation.GetInstance().DeleteEntryFromDownload(photoid); continue; } string safetitle = p.Title.Replace("/", ""); string extension = sourceurl.Substring(sourceurl.LastIndexOf('.')); string filename = String.Format( "{0}/{1}_{2}{3}", foldername, safetitle, p.Id, extension); Utils.IfExistsDeleteFile(filename); try { webclient.DownloadFile(sourceurl, filename); } catch (Exception e) { Console.WriteLine(e.Message); continue; } DelegateIncrementProgressBar(); PersistentInformation.GetInstance().DeleteEntryFromDownload(photoid); CheckProceedRoutinePermission(); } }