private void UpdateAlbumAccess(PicasaService session, Album albumToUpdate, AlbumAccessEnum albumAccess) { //update existing album WriteOutput(string.Concat("Updating Album: ", albumToUpdate.AtomEntry.Title.Text), true); albumToUpdate.Updated = DateTime.Now; albumToUpdate.Access = albumAccess.ToString().ToLower(); albumToUpdate.AtomEntry = (PicasaEntry)albumToUpdate.AtomEntry.Update(); m_albumUpdateCount++; }
private AlbumAccessEnum DetermineAlbumAccess(DirectoryInfo sourceFolder, AlbumAccessEnum parentFolderAccess) { AlbumAccessEnum albumAccess = parentFolderAccess; if (this.AlbumPrivateFolderNames != null && this.AlbumPrivateFolderNames.Contains(sourceFolder.Name)) { WriteOutput(string.Format("Album Marked Private (folder named '{0}')", sourceFolder.Name), true); albumAccess = AlbumAccessEnum.Private; } else if (!string.IsNullOrEmpty(this.AlbumPrivateFileName) && File.Exists(Path.Combine(sourceFolder.FullName, this.AlbumPrivateFileName))) { WriteOutput(string.Format("Album Marked Private ('{0}' file was found in folder)", this.AlbumPrivateFileName), true); albumAccess = AlbumAccessEnum.Private; } else if (!string.IsNullOrEmpty(this.AlbumPublicFileName) && File.Exists(Path.Combine(sourceFolder.FullName, this.AlbumPublicFileName))) { WriteOutput(string.Format("Album Marked Public ('{0}' file was found in folder)", this.AlbumPublicFileName), true); albumAccess = AlbumAccessEnum.Public; } return(albumAccess); }
/// <summary> /// Syncs a local folder to an online Picasa Web Album location /// </summary> /// <param name="sourceFolder">The source folder to sync.</param> /// <param name="albumNamePrefix">A prefix to prepend to the album name.</param> /// <param name="includeSubFolders">Indicated whether to sync all subfolders recursively.</param> /// <param name="session">The current authenticated Picasa session.</param> /// <param name="albumFeed">A feed listing all existing Picass Web Albums in the Picasa account.</param> private void SyncFolder(DirectoryInfo sourceFolder, string albumNamePrefix, AlbumAccessEnum targetAlbumAccess, bool includeSubFolders, PicasaService session, PicasaFeed albumFeed) { if (!sourceFolder.Exists) { throw new DirectoryNotFoundException(string.Format("Folder '{0}' cannot be located.", sourceFolder.FullName)); } string targetAlbumName = GetTargetAlbumName(sourceFolder, albumNamePrefix); Dictionary<string, FileInfo> sourceFiles = GetSourceFiles(sourceFolder); bool excludeFolder = ShouldExcludeFolder(sourceFolder, sourceFiles); PicasaEntry existingAlbumEntry = albumFeed.Entries.FirstOrDefault(a => a.Title.Text == targetAlbumName) as PicasaEntry; if (excludeFolder) { if (existingAlbumEntry != null && !this.AddOnly) { //album needs to be removed WriteOutput(string.Format("Removing Album: {0} (excluded but already exists)", targetAlbumName)); existingAlbumEntry.Delete(); existingAlbumEntry.Summary.Text = ENTRY_DELETED_SUMMARY; m_albumDeleteCount++; } else { m_folderSkipCount++; } } else { WriteOutput(string.Format("Syncing Folder: {0} to Album: {1}", sourceFolder.FullName, targetAlbumName), true); try { targetAlbumAccess = DetermineAlbumAccess(sourceFolder, targetAlbumAccess); if (sourceFiles.Count > 0) { Album targetAlbum = new Album(); if (existingAlbumEntry != null) { targetAlbum.AtomEntry = existingAlbumEntry; if (targetAlbum.Access != targetAlbumAccess.ToString().ToLower()) { UpdateAlbumAccess(session, targetAlbum, targetAlbumAccess); } } else { targetAlbum = CreateAlbum(session, albumFeed, targetAlbumName, targetAlbumAccess); } PhotoQuery existingAlbumPhotosQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername, targetAlbum.Id)); PicasaFeed existingAlbumPhotosFeed = session.Query(existingAlbumPhotosQuery); //sync folder files DeleteFilesFromAlbum(sourceFiles, existingAlbumPhotosFeed); foreach (KeyValuePair<string, FileInfo> file in sourceFiles.OrderBy(f => f.Value.LastWriteTime)) { AddFileToAlbum(file.Value, targetAlbum, existingAlbumPhotosFeed, session); } } } catch (Exception ex) { WriteOutput(string.Format("Skipping Folder: {0} (Error - {1})", sourceFolder.Name, ex.Message), true); } if (includeSubFolders) { DirectoryInfo[] subfolders = sourceFolder.GetDirectories().OrderBy(d => d.CreationTime).ToArray(); if (subfolders.Length > 0) { foreach (DirectoryInfo folder in subfolders) { SyncFolder(folder, targetAlbumName, targetAlbumAccess, includeSubFolders, session, albumFeed); } } } } }
private AlbumAccessEnum DetermineAlbumAccess(DirectoryInfo sourceFolder, AlbumAccessEnum parentFolderAccess) { AlbumAccessEnum albumAccess = parentFolderAccess; if (this.AlbumPrivateFolderNames != null && this.AlbumPrivateFolderNames.Contains(sourceFolder.Name)) { WriteOutput(string.Format("Album Marked Private (folder named '{0}')", sourceFolder.Name), true); albumAccess = AlbumAccessEnum.Private; } else if (!string.IsNullOrEmpty(this.AlbumPrivateFileName) && File.Exists(Path.Combine(sourceFolder.FullName, this.AlbumPrivateFileName))) { WriteOutput(string.Format("Album Marked Private ('{0}' file was found in folder)", this.AlbumPrivateFileName), true); albumAccess = AlbumAccessEnum.Private; } else if (!string.IsNullOrEmpty(this.AlbumPublicFileName) && File.Exists(Path.Combine(sourceFolder.FullName, this.AlbumPublicFileName))) { WriteOutput(string.Format("Album Marked Public ('{0}' file was found in folder)", this.AlbumPublicFileName), true); albumAccess = AlbumAccessEnum.Public; } return albumAccess; }
private Album CreateAlbum(PicasaService session, PicasaFeed albumFeed, string targetAlbumName, AlbumAccessEnum albumAccess) { //create album (doesn't exist) WriteOutput(string.Concat("Creating Album: ", targetAlbumName), true); AlbumEntry newAlbumEntry = new AlbumEntry(); newAlbumEntry.Title.Text = targetAlbumName; newAlbumEntry.Summary.Text = targetAlbumName; newAlbumEntry.Published = DateTime.Now; Album newAlbum = new Album(); newAlbum.AtomEntry = newAlbumEntry; newAlbum.Access = albumAccess.ToString().ToLower(); Uri insertAlbumFeedUri = new Uri(PicasaQuery.CreatePicasaUri(this.PicasaUsername)); newAlbum.AtomEntry = (PicasaEntry)session.Insert(insertAlbumFeedUri, newAlbumEntry); m_albumCreateCount++; return newAlbum; }
private Album CreateAlbum(PicasaService session, PicasaFeed albumFeed, string targetAlbumName, AlbumAccessEnum albumAccess) { //create album (doesn't exist) WriteOutput(string.Concat("Creating Album: ", targetAlbumName), true); AlbumEntry newAlbumEntry = new AlbumEntry(); newAlbumEntry.Title.Text = targetAlbumName; newAlbumEntry.Summary.Text = targetAlbumName; newAlbumEntry.Published = DateTime.Now; Album newAlbum = new Album(); newAlbum.AtomEntry = newAlbumEntry; newAlbum.Access = albumAccess.ToString().ToLower(); Uri insertAlbumFeedUri = new Uri(PicasaQuery.CreatePicasaUri(this.PicasaUsername)); newAlbum.AtomEntry = (PicasaEntry)session.Insert(insertAlbumFeedUri, newAlbumEntry); m_albumCreateCount++; return(newAlbum); }
/// <summary> /// Syncs a local folder to an online Picasa Web Album location /// </summary> /// <param name="sourceFolder">The source folder to sync.</param> /// <param name="albumNamePrefix">A prefix to prepend to the album name.</param> /// <param name="includeSubFolders">Indicated whether to sync all subfolders recursively.</param> /// <param name="session">The current authenticated Picasa session.</param> /// <param name="albumFeed">A feed listing all existing Picass Web Albums in the Picasa account.</param> private void SyncFolder(DirectoryInfo sourceFolder, string albumNamePrefix, AlbumAccessEnum targetAlbumAccess, bool includeSubFolders, PicasaService session, PicasaFeed albumFeed) { if (!sourceFolder.Exists) { throw new DirectoryNotFoundException(string.Format("Folder '{0}' cannot be located.", sourceFolder.FullName)); } string targetAlbumName = GetTargetAlbumName(sourceFolder, albumNamePrefix); Dictionary <string, FileInfo> sourceFiles = GetSourceFiles(sourceFolder); bool excludeFolder = ShouldExcludeFolder(sourceFolder, sourceFiles); PicasaEntry existingAlbumEntry = albumFeed.Entries.FirstOrDefault(a => a.Title.Text == targetAlbumName) as PicasaEntry; if (excludeFolder) { if (existingAlbumEntry != null && !this.AddOnly) { //album needs to be removed WriteOutput(string.Format("Removing Album: {0} (excluded but already exists)", targetAlbumName)); existingAlbumEntry.Delete(); existingAlbumEntry.Summary.Text = ENTRY_DELETED_SUMMARY; m_albumDeleteCount++; } else { m_folderSkipCount++; } } else { WriteOutput(string.Format("Syncing Folder: {0} to Album: {1}", sourceFolder.FullName, targetAlbumName), true); try { targetAlbumAccess = DetermineAlbumAccess(sourceFolder, targetAlbumAccess); if (sourceFiles.Count > 0) { Album targetAlbum = new Album(); if (existingAlbumEntry != null) { targetAlbum.AtomEntry = existingAlbumEntry; if (targetAlbum.Access != targetAlbumAccess.ToString().ToLower()) { UpdateAlbumAccess(session, targetAlbum, targetAlbumAccess); } } else { targetAlbum = CreateAlbum(session, albumFeed, targetAlbumName, targetAlbumAccess); } PhotoQuery existingAlbumPhotosQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername, targetAlbum.Id)); PicasaFeed existingAlbumPhotosFeed = session.Query(existingAlbumPhotosQuery); //sync folder files DeleteFilesFromAlbum(sourceFiles, existingAlbumPhotosFeed); foreach (KeyValuePair <string, FileInfo> file in sourceFiles.OrderBy(f => f.Value.LastWriteTime)) { AddFileToAlbum(file.Value, targetAlbum, existingAlbumPhotosFeed, session); } } } catch (Exception ex) { WriteOutput(string.Format("Skipping Folder: {0} (Error - {1})", sourceFolder.Name, ex.Message), true); } if (includeSubFolders) { DirectoryInfo[] subfolders = sourceFolder.GetDirectories().OrderBy(d => d.CreationTime).ToArray(); if (subfolders.Length > 0) { foreach (DirectoryInfo folder in subfolders) { SyncFolder(folder, targetAlbumName, targetAlbumAccess, includeSubFolders, session, albumFeed); } } } } }