/// <summary> /// Initializes a new instance of the <see cref="CacheItemAlbum" /> class. /// </summary> /// <param name="id">The ID for this gallery object.</param> /// <param name="galleryId">The ID for the gallery.</param> /// <param name="albumId">The ID of the album this gallery asset belongs to.</param> /// <param name="galleryObjectType">Type of the gallery asset.</param> /// <param name="sequence">The sequence of this gallery asset.</param> /// <param name="dateAdded">The date this gallery asset was added.</param> /// <param name="metaItems">The meta items belonging to this gallery asset.</param> /// <param name="createdByUserName">Name of the user who created this gallery asset.</param> /// <param name="lastModifiedByUserName">The name of the user who last modified this gallery asset.</param> /// <param name="dateLastModified">The date this gallery asset was last modified.</param> /// <param name="isPrivate">A value indicating whether this instance if private.</param> /// <param name="directoryName">The name of the directory where the album is stored. Example: summervacation.</param> /// <param name="thumbnailMediaObjectId">The media object ID whose thumbnail image is to be used as the thumbnail image to represent this album.</param> /// <param name="sortByMetaName">The metadata property to sort the album by.</param> /// <param name="sortAscending">A value indicating whether the contents of the album are sorted in ascending order. A <c>false</c> value indicates /// a descending sort.</param> /// <param name="ownedBy">The user name of this album's owner.</param> /// <param name="ownerRoleName">The name of the role associated with this album's owner.</param> /// <param name="childAlbumIds">The ID's of all child albums in this album. The IDs must be in the key; the value is ignored.</param> /// <param name="childMediaObjectIds">The ID's of all child media assets in this album. The IDs must be in the key; the value is ignored.</param> /// <exception cref="System.ArgumentNullException">Thrown when a required parameter is null.</exception> public CacheItemAlbum(int id, int galleryId, int albumId, GalleryObjectType galleryObjectType, int sequence, DateTime dateAdded, List <CacheItemMetaItem> metaItems, string createdByUserName, string lastModifiedByUserName, DateTime dateLastModified, bool isPrivate, string directoryName, int thumbnailMediaObjectId, MetadataItemName sortByMetaName, bool sortAscending, string ownedBy, string ownerRoleName, ConcurrentDictionary <int, byte> childAlbumIds, ConcurrentDictionary <int, byte> childMediaObjectIds) : base(id, galleryId, albumId, null, galleryObjectType, sequence, dateAdded, metaItems, createdByUserName, lastModifiedByUserName, dateLastModified, isPrivate) { if (metaItems == null) { throw new ArgumentNullException(nameof(metaItems)); } if (childAlbumIds == null) { throw new ArgumentNullException(nameof(childAlbumIds)); } if (childMediaObjectIds == null) { throw new ArgumentNullException(nameof(childMediaObjectIds)); } DirectoryName = directoryName; ThumbnailMediaObjectId = thumbnailMediaObjectId; SortByMetaName = sortByMetaName; SortAscending = sortAscending; OwnedBy = ownedBy; OwnerRoleName = ownerRoleName; ChildAlbumIds = childAlbumIds; ChildMediaObjectIds = childMediaObjectIds; }
/// <summary> /// Gets the metadata value for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public override IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.HtmlSource: return GetHtmlContent(); default: return base.GetMetaValue(metaName); } }
/// <summary> /// Gets the metadata value for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public override IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.Title: return GetAlbumTitle(); default: return base.GetMetaValue(metaName); } }
/// <summary> /// Initializes a new instance of the <see cref="CacheItemMetaItem"/> class. /// </summary> /// <param name="metadataId">The ID of the metadata property.</param> /// <param name="metaName">The name/type of the metadata property.</param> /// <param name="mediaObjectId">The ID of the media object this meta property belongs to. Specify null when it applies to an album.</param> /// <param name="albumId">The ID of the album this meta property belongs to. Specify null when it applies to a media object.</param> /// <param name="rawValue">The raw value of the metadata property.</param> /// <param name="value">The value of the metadata property.</param> public CacheItemMetaItem(int metadataId, MetadataItemName metaName, int?mediaObjectId, int?albumId, string rawValue, string value) { MetadataId = metadataId; MetaName = metaName; MediaObjectId = mediaObjectId; AlbumId = albumId; RawValue = rawValue; Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="MetadataDefinition" /> class. /// </summary> /// <param name="metadataItem">The metadata item.</param> /// <param name="displayName">The user-friendly name that describes this metadata item (e.g. "Date picture taken")</param> /// <param name="isVisibleForAlbum">If set to <c>true</c> metadata items belonging to albums are visible /// in the user interface.</param> /// <param name="isVisibleForGalleryObject">If set to <c>true</c> metadata items belonging to media /// objects are visible in the user interface.</param> /// <param name="isEditable">If set to <c>true</c> metadata items of this type are editable by the user.</param> /// <param name="sequence">Indicates the display order of the metadata item.</param> /// <param name="defaultValue">The template to use when adding a metadata item for a new album or media object.</param> public MetadataDefinition(MetadataItemName metadataItem, string displayName, bool isVisibleForAlbum, bool isVisibleForGalleryObject, bool isEditable, int sequence, string defaultValue) { MetadataItem = metadataItem; DisplayName = displayName; IsVisibleForAlbum= isVisibleForAlbum; IsVisibleForGalleryObject = isVisibleForGalleryObject; IsEditable = isEditable; Sequence = sequence; DefaultValue = defaultValue; }
/// <summary> /// Gets the metadata value for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public override IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.HtmlSource: return(GetHtmlContent()); default: return(base.GetMetaValue(metaName)); } }
/// <summary> /// Initializes a new instance of the <see cref="MetadataDefinition" /> class. /// </summary> /// <param name="metadataItem">The metadata item.</param> /// <param name="displayName">The user-friendly name that describes this metadata item (e.g. "Date picture taken")</param> /// <param name="isVisibleForAlbum">If set to <c>true</c> metadata items belonging to albums are visible /// in the user interface.</param> /// <param name="isVisibleForGalleryObject">If set to <c>true</c> metadata items belonging to media /// objects are visible in the user interface.</param> /// <param name="isEditable">If set to <c>true</c> metadata items of this type are editable by the user.</param> /// <param name="sequence">Indicates the display order of the metadata item.</param> /// <param name="defaultValue">The template to use when adding a metadata item for a new album or media object.</param> public MetadataDefinition(MetadataItemName metadataItem, string displayName, bool isVisibleForAlbum, bool isVisibleForGalleryObject, bool isEditable, int sequence, string defaultValue) { MetadataItem = metadataItem; DisplayName = displayName; IsVisibleForAlbum = isVisibleForAlbum; IsVisibleForGalleryObject = isVisibleForGalleryObject; IsEditable = isEditable; Sequence = sequence; DefaultValue = defaultValue; }
/// <summary> /// Sorts the gallery objects in this collection by <paramref name="sortByMetaName" /> in the order specified by /// <paramref name="sortAscending" />. The <paramref name="galleryId" /> is used to look up the applicable /// <see cref="IGallerySettings.MetadataDisplaySettings" />. /// </summary> /// <param name="sortByMetaName">The name of the metadata item to sort on.</param> /// <param name="sortAscending">If set to <c>true</c> sort in ascending order.</param> /// <param name="galleryId">The gallery ID.</param> /// <returns>An instance of IList{IGalleryObject}.</returns> public IList <IGalleryObject> ToSortedList(MetadataItemName sortByMetaName, bool sortAscending, int galleryId) { if (sortByMetaName == MetadataItemName.NotSpecified) { // This is a custom sort, so sort based on the Sequence property. return(ToSortedList()); } return(SortByMetaValue(sortByMetaName, sortAscending, Factory.LoadGallerySetting(galleryId).MetadataDisplaySettings.Find(sortByMetaName).DataType)); }
/// <summary> /// Gets the metadata value for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public override IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.Duration: return GetDuration(); case MetadataItemName.BitRate: return GetBitRate(); case MetadataItemName.AudioFormat: return GetAudioFormat(); default: return base.GetMetaValue(metaName); } }
/// <summary> /// Initializes a new instance of the <see cref="MetadataDefinition" /> class. /// </summary> /// <param name="metadataItem">The metadata item.</param> /// <param name="displayName">The user-friendly name that describes this metadata item (e.g. "Date picture taken")</param> /// <param name="isVisibleForAlbum">If set to <c>true</c> metadata items belonging to albums are visible /// in the user interface.</param> /// <param name="isVisibleForGalleryObject">If set to <c>true</c> metadata items belonging to media /// objects are visible in the user interface.</param> /// <param name="userEditMode">The user edit mode.</param> /// <param name="persistToFile">Indicates whether to persist this meta item to the media file during a save operation.</param> /// <param name="sequence">Indicates the display order of the metadata item.</param> /// <param name="defaultValue">The template to use when adding a metadata item for a new album or media object.</param> public MetadataDefinition(MetadataItemName metadataItem, string displayName, bool isVisibleForAlbum, bool isVisibleForGalleryObject, PropertyEditorMode userEditMode, bool?persistToFile, int sequence, string defaultValue) { MetadataItem = metadataItem; DisplayName = displayName; IsVisibleForAlbum = isVisibleForAlbum; IsVisibleForGalleryObject = isVisibleForGalleryObject; UserEditMode = userEditMode; PersistToFile = persistToFile; Sequence = sequence; DefaultValue = defaultValue; }
/// <summary> /// Extracts a metadata instance for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public virtual IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.DateAdded: return(new MetaValue(GalleryObject.DateAdded.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), GalleryObject.DateAdded.ToString("O", CultureInfo.InvariantCulture))); default: return(null); } }
/// <summary> /// Gets the <see cref="IGalleryObjectMetadataItem"/> object that matches the specified /// <see cref="MetadataItemName"/>. The <paramref name="metadataItem"/> /// parameter remains null if no matching object is in the collection. /// </summary> /// <param name="metadataName">The <see cref="MetadataItemName"/> of the /// <see cref="IGalleryObjectMetadataItem"/> to get.</param> /// <param name="metadataItem">When this method returns, contains the <see cref="IGalleryObjectMetadataItem"/> associated with the /// specified <see cref="MetadataItemName"/>, if the key is found; otherwise, the /// parameter remains null. This parameter is passed uninitialized.</param> /// <returns> /// Returns true if the <see cref="IGalleryObjectMetadataItemCollection"/> contains an element with the specified /// <see cref="MetadataItemName"/>; otherwise, false. /// </returns> public bool TryGetMetadataItem(MetadataItemName metadataName, out IGalleryObjectMetadataItem metadataItem) { // We know galleryObjectMetadataItems is actually a List<IGalleryObjectMetadataItem> because we passed it to the constructor. List <IGalleryObjectMetadataItem> galleryObjectMetadataItems = (List <IGalleryObjectMetadataItem>)Items; metadataItem = galleryObjectMetadataItems.Find(delegate(IGalleryObjectMetadataItem metaItem) { return(metaItem.MetadataItemName == metadataName); }); return(metadataItem != null); }
/// <summary> /// Initializes a new instance of the <see cref="GalleryObjectMetadataItem" /> class. /// </summary> /// <param name="mediaObjectMetadataId">The value that uniquely indentifies this metadata item.</param> /// <param name="galleryObject">The gallery object this metadata item applies to.</param> /// <param name="rawValue">The raw value of the metadata item. Typically this is the value extracted from /// the metadata of the media file.</param> /// <param name="value">The value of the metadata item (e.g. "F5.7", "1/500 sec.").</param> /// <param name="hasChanges">if set to <c>true</c> this object has changes that have not been persisted to the database.</param> /// <param name="metaDef">The meta definition.</param> public GalleryObjectMetadataItem(int mediaObjectMetadataId, IGalleryObject galleryObject, string rawValue, string value, bool hasChanges, IMetadataDefinition metaDef) { _mediaObjectMetadataId = mediaObjectMetadataId; GalleryObject = galleryObject; _metadataItemName = metaDef.MetadataItem; _description = metaDef.DisplayName; _rawValue = rawValue; _value = value; _hasChanges = hasChanges; MetaDefinition = metaDef; _isVisible = false; IsDeleted = false; }
/// <summary> /// Extracts a metadata instance for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public virtual IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.DateAdded: return(new MetaValue(GalleryObject.DateAdded.ToLocalTime().ToString(DateTimeFormatString, CultureInfo.InvariantCulture), GalleryObject.DateAdded.ToString("O", CultureInfo.InvariantCulture))); // Use the following if you want it formatted in UTC instead (above will store the formatted time in server's time zone) //return new MetaValue(GalleryObject.DateAdded.ToString(DateTimeFormatString + " UTC", CultureInfo.InvariantCulture), GalleryObject.DateAdded.ToString("O", CultureInfo.InvariantCulture)); default: return(null); } }
/// <summary> /// Gets the metadata value for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public override IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.Duration: return GetDuration(); case MetadataItemName.BitRate: return GetBitRate(); case MetadataItemName.AudioFormat: return GetAudioFormat(); case MetadataItemName.VideoFormat: return GetVideoFormat(); case MetadataItemName.Width: return GetWidth(); case MetadataItemName.Height: return GetHeight(); case MetadataItemName.Orientation: return GetRotation(); default: return base.GetMetaValue(metaName); } }
/// <summary> /// Sorts the gallery objects in the collection by the property specified in <paramref name="sortByMetaName" />. /// </summary> /// <param name="sortByMetaName">The name of the metadata item to sort on.</param> /// <param name="sortAscending">If set to <c>true</c> sort in ascending order.</param> /// <param name="metaDataType">The data type of the meta data. When <see cref="DateTime" />, the results are sorted on the /// <see cref="IGalleryObjectMetadataItem.RawValue" /> property, which are expected to be in a string-sortable format. For all other data types /// the results are sorted on the <see cref="IGalleryObjectMetadataItem.Value" /> property</param> /// <returns>Returns a collection of <see cref="IGalleryObject" /> instances.</returns> private IList <IGalleryObject> SortByMetaValue(MetadataItemName sortByMetaName, bool sortAscending, Type metaDataType) { Func <IGalleryObjectMetadataItem, string> sortProperty = mi => (metaDataType == typeof(DateTime) ? mi.RawValue : mi.Value); var childAlbums = Items.Values.Where(g => g.GalleryObjectType == GalleryObjectType.Album) .OrderBy(g => g.MetadataItems.Where(mi1 => mi1.MetadataItemName == sortByMetaName).Select(sortProperty).Distinct().FirstOrDefault()).Select(a => a); var mediaObjects = Items.Values.Where(g => g.GalleryObjectType != GalleryObjectType.Album) .OrderBy(g => g.MetadataItems.Where(mi1 => mi1.MetadataItemName == sortByMetaName).Select(sortProperty).Distinct().FirstOrDefault()).Select(mo => mo); if (!sortAscending) { childAlbums = childAlbums.Reverse(); mediaObjects = mediaObjects.Reverse(); } return(childAlbums.Concat(mediaObjects).ToList()); }
/// <summary> /// Gets the gallery objects in the album. Includes albums and media objects. /// </summary> /// <param name="albumId">The album ID.</param> /// <param name="sortByMetaName">The sort by meta name id.</param> /// <param name="sortAscending">if set to <c>true</c> [sort ascending].</param> /// <returns>Returns an <see cref="IQueryable" /> instance of <see cref="Entity.GalleryItem" />.</returns> /// <exception cref="InvalidAlbumException">Thrown when an album with the specified /// <paramref name="albumId" /> is not found in the data store.</exception> /// <exception cref="GalleryServerPro.Events.CustomExceptions.GallerySecurityException">Thrown when the user does not have at least one of the requested permissions to the /// specified album.</exception> public static IQueryable<GalleryItem> GetGalleryItemsInAlbum(int albumId, MetadataItemName sortByMetaName, bool sortAscending) { IAlbum album = Factory.LoadAlbumInstance(albumId, true); SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), album.Id, album.GalleryId, Utils.IsAuthenticated, album.IsPrivate, album.IsVirtualAlbum); IList<IGalleryObject> galleryObjects; if (MetadataItemNameEnumHelper.IsValidFormattedMetadataItemName(sortByMetaName)) { galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(sortByMetaName, sortAscending, album.GalleryId); } else { galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(); } return ToGalleryItems(galleryObjects).AsQueryable(); }
/// <summary> /// Gets the gallery objects in the album. Includes albums and media objects. /// </summary> /// <param name="albumId">The album ID.</param> /// <param name="sortByMetaName">The sort by meta name id.</param> /// <param name="sortAscending">if set to <c>true</c> [sort ascending].</param> /// <returns>Returns an <see cref="IQueryable" /> instance of <see cref="Entity.GalleryItem" />.</returns> /// <exception cref="InvalidAlbumException">Thrown when an album with the specified /// <paramref name="albumId" /> is not found in the data store.</exception> /// <exception cref="GalleryServerPro.Events.CustomExceptions.GallerySecurityException">Thrown when the user does not have at least one of the requested permissions to the /// specified album.</exception> public static IQueryable <GalleryItem> GetGalleryItemsInAlbum(int albumId, MetadataItemName sortByMetaName, bool sortAscending) { IAlbum album = Factory.LoadAlbumInstance(albumId, true); SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), album.Id, album.GalleryId, Utils.IsAuthenticated, album.IsPrivate, album.IsVirtualAlbum); IList <IGalleryObject> galleryObjects; if (MetadataItemNameEnumHelper.IsValidFormattedMetadataItemName(sortByMetaName)) { galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(sortByMetaName, sortAscending, album.GalleryId); } else { galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(); } return(ToGalleryItems(galleryObjects).AsQueryable()); }
/// <summary> /// Sorts the gallery objects in this collection by <paramref name="sortByMetaName" /> in the order specified by /// <paramref name="sortAscending" />. The <paramref name="galleryId" /> is used to look up the applicable /// <see cref="IGallerySettings.MetadataDisplaySettings" />. /// </summary> /// <param name="sortByMetaName">The name of the metadata item to sort on.</param> /// <param name="sortAscending">If set to <c>true</c> sort in ascending order.</param> /// <param name="galleryId">The gallery ID.</param> /// <returns>An instance of IList{IGalleryObject}.</returns> public IList <IGalleryObject> ToSortedList(MetadataItemName sortByMetaName, bool sortAscending, int galleryId) { if (sortByMetaName == MetadataItemName.NotSpecified) { // This is a custom sort, so sort based on the Sequence property. return(ToSortedList()); } var gallerySetting = Factory.LoadGallerySetting(galleryId); if (gallerySetting.MetadataDisplaySettings.Find(sortByMetaName).DataType == typeof(DateTime)) { return(SortByDateTime(sortByMetaName, sortAscending, gallerySetting.MetadataDateTimeFormatString)); } else { return(SortByString(sortByMetaName, sortAscending)); } }
/// <summary> /// Gets the metadata value for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public override IMetaValue GetMetaValue(MetadataItemName metaName) { var fi = GalleryObject.Original.FileInfo; switch (metaName) { case MetadataItemName.Title: return new MetaValue(GalleryObject.Original.FileName); case MetadataItemName.FileName: return new MetaValue((fi != null ? fi.Name : null)); case MetadataItemName.FileNameWithoutExtension: return new MetaValue((fi != null ? Path.GetFileNameWithoutExtension(fi.Name) : null)); case MetadataItemName.FileSizeKb: if (fi == null) return null; int fileSize = (int)(fi.Length / 1024); fileSize = (fileSize < 1 ? 1 : fileSize); // Very small files should be 1, not 0. return new MetaValue(String.Concat(fileSize.ToString("N0", CultureInfo.CurrentCulture), " ", Resources.Metadata_KB), fileSize.ToString(CultureInfo.InvariantCulture)); case MetadataItemName.DateFileCreated: return (fi != null ? new MetaValue(fi.CreationTime.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), fi.CreationTime.ToString("O", CultureInfo.InvariantCulture)) : null); case MetadataItemName.DateFileCreatedUtc: return (fi != null ? new MetaValue(fi.CreationTimeUtc.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), fi.CreationTimeUtc.ToString("O", CultureInfo.InvariantCulture)) : null); case MetadataItemName.DateFileLastModified: return (fi != null ? new MetaValue(fi.LastWriteTime.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), fi.LastWriteTime.ToString("O", CultureInfo.InvariantCulture)) : null); case MetadataItemName.DateFileLastModifiedUtc: return (fi != null ? new MetaValue(fi.LastWriteTimeUtc.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), fi.LastWriteTimeUtc.ToString("O", CultureInfo.InvariantCulture)) : null); default: return base.GetMetaValue(metaName); } }
/// <summary> /// Persists the current user's sort preference for the specified <paramref name="album" />. No action is taken if the /// album is virtual. Anonymous user data is stored in session only; logged on users' data are permanently stored. /// </summary> /// <param name="album">The album whose sort preference is to be preserved.</param> /// <param name="sortByMetaName">Name of the metadata item to sort by.</param> /// <param name="sortAscending">Indicates the sort direction.</param> private static void PersistUserSortPreference(IAlbum album, MetadataItemName sortByMetaName, bool sortAscending) { if (album.IsVirtualAlbum) { return; } var profile = ProfileController.GetProfile(); var aProfile = profile.AlbumProfiles.Find(album.Id); if (aProfile == null) { profile.AlbumProfiles.Add(new AlbumProfile(album.Id, sortByMetaName, sortAscending)); } else { aProfile.SortByMetaName = sortByMetaName; aProfile.SortAscending = sortAscending; } ProfileController.SaveProfile(profile); }
private IMetaValue GetGpsValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.GpsVersion: return (!String.IsNullOrWhiteSpace(GpsLocation.Version) ? new MetaValue(GpsLocation.Version, GpsLocation.Version) : null); case MetadataItemName.GpsLocation: if ((GpsLocation.Latitude != null) && (GpsLocation.Longitude != null)) { var loc = GpsLocation.ToLatitudeLongitudeDecimalString(); return new MetaValue(loc, loc); } else return null; case MetadataItemName.GpsLatitude: if ((GpsLocation.Latitude != null) && (GpsLocation.Longitude != null)) { var lat = GpsLocation.Latitude.ToDouble().ToString("F6", CultureInfo.InvariantCulture); return new MetaValue(lat, lat); } else return null; case MetadataItemName.GpsLongitude: if ((GpsLocation.Latitude != null) && (GpsLocation.Longitude != null)) { var longitude = GpsLocation.Longitude.ToDouble().ToString("F6", CultureInfo.InvariantCulture); return new MetaValue(longitude, longitude); } else return null; case MetadataItemName.GpsAltitude: if (GpsLocation.Altitude.HasValue) { var altitude = GpsLocation.Altitude.Value.ToString("N0", CultureInfo.CurrentCulture); return new MetaValue(String.Concat(altitude, " ", Resources.Metadata_meters), altitude); } else return null; case MetadataItemName.GpsDestLocation: if ((GpsLocation.DestLatitude != null) && (GpsLocation.DestLongitude != null)) { var loc = GpsLocation.ToDestLatitudeLongitudeDecimalString(); return new MetaValue(loc, loc); } else return null; case MetadataItemName.GpsDestLatitude: if ((GpsLocation.DestLatitude != null) && (GpsLocation.DestLongitude != null)) { var lat = GpsLocation.DestLatitude.ToDouble().ToString("F6", CultureInfo.InvariantCulture); return new MetaValue(lat, lat); } else return null; case MetadataItemName.GpsDestLongitude: if ((GpsLocation.DestLatitude != null) && (GpsLocation.DestLongitude != null)) { var longitude = GpsLocation.DestLongitude.ToDouble().ToString("F6", CultureInfo.InvariantCulture); return new MetaValue(longitude, longitude); } else return null; default: throw new ArgumentException(string.Format("The function GetGpsValue() expects a GPS-related parameter; instead the value {0} was passed.", metaName), "metaName"); } }
/// <summary> /// Gets the collection of tag values having the specified <paramref name="tagName" />. /// </summary> /// <param name="metas">The metadata items.</param> /// <param name="tagName">Name of the tag.</param> /// <returns>Returns a collection of strings.</returns> private static IEnumerable<string> GetTagList(IGalleryObjectMetadataItemCollection metas, MetadataItemName tagName) { IGalleryObjectMetadataItem mdTag; if (metas.TryGetMetadataItem(tagName, out mdTag)) { return mdTag.Value.ToListFromCommaDelimited(); } else return new string[] { }; }
/// <summary> /// Rebuilds the <paramref name="metaName" /> for all items in the gallery having ID <paramref name="galleryId" />. /// The action is executed asynchronously and returns immediately. /// </summary> /// <param name="metaName">Name of the meta item.</param> /// <param name="galleryId">The gallery ID.</param> public static void RebuildItemForGalleryAsync(MetadataItemName metaName, int galleryId) { var album = Factory.LoadRootAlbumInstance(galleryId); var metaDefs = Factory.LoadGallerySetting(galleryId).MetadataDisplaySettings; var userName = Utils.UserName; Task.Factory.StartNew(() => StartRebuildMetaItem(metaDefs.Find(metaName), album, userName), TaskCreationOptions.LongRunning); }
/// <summary> /// Extracts a metadata instance for the specified <paramref name="metaName" />. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public virtual IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.DateAdded: return new MetaValue(GalleryObject.DateAdded.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), GalleryObject.DateAdded.ToString("O", CultureInfo.InvariantCulture)); default: return null; } }
/// <summary> /// Attempts to get the requested <paramref name="metadataName" /> from the existing set of metadata /// items. This is used during metadata extraction when generating an item that is based on the /// calculated value of another metadata item. May return null. /// </summary> /// <param name="metadataName">Name of the metadata.</param> /// <returns></returns> /// <example>An admin may create a custom meta item with the default value "{Title} - {GpsLocationWithMapLink}". /// The title is extracted from the file (and thus does not use this function), but the GPS map link /// is based on a template and cannot be directly extracted from the image file. This function /// will return the map link in this case. Note that this function will only find an item when /// it has already been created, so if the item it looks for does not yet exist, a null is /// returned. To prevent this, an admin should ensure meta items based on other templated items occur /// after them (as ordered on the admin metadata page).</example> private IMetaValue TryGetFromExisting(MetadataItemName metadataName) { IGalleryObjectMetadataItem metaItem; if (MetadataItems.TryGetMetadataItem(metadataName, out metaItem)) return new MetaValue(metaItem.Value, metaItem.RawValue); else return null; }
/// <summary> /// Persists the meta value identified by <paramref name="metaName" /> to the media file. It is expected the meta item /// exists in <see cref="IGalleryObject.MetadataItems" />. /// </summary> /// <param name="metaName">Name of the meta item to persist.</param> /// <exception cref="System.NotSupportedException"></exception> public virtual void SaveMetaValue(MetadataItemName metaName) { throw new NotSupportedException(); }
public static IQueryable <GalleryItem> GetGalleryItemsHavingTags(string[] tags, string[] people, int galleryId, MetadataItemName sortByMetaName, bool sortAscending) { IAlbum album = GetGalleryObjectsHavingTags(tags, people, galleryId); IList <IGalleryObject> galleryObjects; if (MetadataItemNameEnumHelper.IsValidFormattedMetadataItemName(sortByMetaName)) { galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(sortByMetaName, sortAscending, album.GalleryId); } else { galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(); } return(ToGalleryItems(galleryObjects).AsQueryable()); }
private void TryAlternateMethodsOfPersistingMetadata(string sourceFileName, string outputFileName, MetadataItemName metaName, MetaPersistAction persistAction) { // Three alternate attempts to persist the metadata: // 1. Use outputFileName parameter and a cloned copy of the file's metadata // 2. Use outputFileName parameter and the original file's metadata // 3. Rename the file and try again using a cloned copy of the file's metadata // Adapted from: https://code.google.com/p/flickrmetasync/source/browse/trunk/FlickrMetadataSync/Picture.cs?spec=svn29&r=29 bool tryOneLastMethod = false; using (Stream originalFile = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { const BitmapCreateOptions createOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile; BitmapDecoder original = BitmapDecoder.Create(originalFile, createOptions, BitmapCacheOption.None); var output = new JpegBitmapEncoder(); if (original.Frames[0] != null && original.Frames[0].Metadata != null) { BitmapMetadata bitmapMetadata = original.Frames[0].Metadata.Clone() as BitmapMetadata; bitmapMetadata.SetQuery("/app1/ifd/PaddingSchema:Padding", MetadataPaddingInBytes); bitmapMetadata.SetQuery("/app1/ifd/exif/PaddingSchema:Padding", MetadataPaddingInBytes); bitmapMetadata.SetQuery("/xmp/PaddingSchema:Padding", MetadataPaddingInBytes); SetMetadata(bitmapMetadata, metaName, persistAction); output.Frames.Add(BitmapFrame.Create(original.Frames[0], original.Frames[0].Thumbnail, bitmapMetadata, original.Frames[0].ColorContexts)); } try { using (Stream outputFile = File.Open(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { output.Save(outputFile); } } catch (Exception e) //System.Exception, NotSupportedException, InvalidOperationException, ArgumentException { if (e is NotSupportedException || e is ArgumentException) { output = new JpegBitmapEncoder(); output.Frames.Add(BitmapFrame.Create(original.Frames[0], original.Frames[0].Thumbnail, original.Metadata, original.Frames[0].ColorContexts)); using (Stream outputFile = File.Open(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { output.Save(outputFile); } tryOneLastMethod = true; } else { throw new Exception("Error saving picture.", e); } } } if (tryOneLastMethod) { File.Move(outputFileName, outputFileName + "tmp"); using (Stream recentlyOutputFile = new FileStream(outputFileName + "tmp", FileMode.Open, FileAccess.Read, FileShare.Read)) { const BitmapCreateOptions createOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile; BitmapDecoder original = BitmapDecoder.Create(recentlyOutputFile, createOptions, BitmapCacheOption.None); JpegBitmapEncoder output = new JpegBitmapEncoder(); if (original.Frames[0] != null && original.Frames[0].Metadata != null) { BitmapMetadata bitmapMetadata = original.Frames[0].Metadata.Clone() as BitmapMetadata; bitmapMetadata.SetQuery("/app1/ifd/PaddingSchema:Padding", MetadataPaddingInBytes); bitmapMetadata.SetQuery("/app1/ifd/exif/PaddingSchema:Padding", MetadataPaddingInBytes); bitmapMetadata.SetQuery("/xmp/PaddingSchema:Padding", MetadataPaddingInBytes); SetMetadata(bitmapMetadata, metaName, persistAction); output.Frames.Add(BitmapFrame.Create(original.Frames[0], original.Frames[0].Thumbnail, bitmapMetadata, original.Frames[0].ColorContexts)); } using (Stream outputFile = File.Open(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { output.Save(outputFile); } } File.Delete(outputFileName + "tmp"); } }
/// <summary> /// Permanently removes the meta value from the media file. The item is also removed from /// <see cref="IGalleryObject.MetadataItems" />. /// </summary> /// <param name="metaName">Name of the meta item to delete.</param> /// <exception cref="System.NotSupportedException"></exception> public override void DeleteMetaValue(MetadataItemName metaName) { PersistMetaValue(metaName, MetaPersistAction.Delete); }
/// <summary> /// Gets the metadata value for the specified <paramref name="metaName" />. May return null. /// </summary> /// <param name="metaName">Name of the metadata item to retrieve.</param> /// <returns>An instance that implements <see cref="IMetaValue" />.</returns> public override IMetaValue GetMetaValue(MetadataItemName metaName) { switch (metaName) { case MetadataItemName.Title: return GetTitle(); case MetadataItemName.DatePictureTaken: return GetDatePictureTaken(); case MetadataItemName.Author: return GetAuthor(); case MetadataItemName.CameraModel: return GetCameraModel(); case MetadataItemName.EquipmentManufacturer: return GetCameraManufacturer(); case MetadataItemName.Tags: return GetKeywords(); case MetadataItemName.Rating: return GetRating(); case MetadataItemName.Comment: return GetComment(); case MetadataItemName.Copyright: return GetCopyright(); case MetadataItemName.Subject: return GetSubject(); case MetadataItemName.ColorRepresentation: return GetColorRepresentation(); case MetadataItemName.Description: return GetDescription(); case MetadataItemName.Dimensions: return GetDimensions(); case MetadataItemName.ExposureCompensation: return GetExposureCompensation(); case MetadataItemName.ExposureProgram: return GetExposureProgram(); case MetadataItemName.Orientation: return GetOrientation(); case MetadataItemName.ExposureTime: return GetExposureTime(); case MetadataItemName.FlashMode: return GetFlashMode(); case MetadataItemName.FNumber: return GetFNumber(); case MetadataItemName.FocalLength: return GetFocalLength(); case MetadataItemName.Height: return GetHeight(); case MetadataItemName.HorizontalResolution: return GetHorizontalResolution(); case MetadataItemName.IsoSpeed: return GetIsoSpeed(); case MetadataItemName.LensAperture: return GetLensAperture(); case MetadataItemName.LightSource: return GetLightSource(); case MetadataItemName.MeteringMode: return GetMeteringMode(); case MetadataItemName.SubjectDistance: return GetSubjectDistance(); case MetadataItemName.VerticalResolution: return GetVerticalResolution(); case MetadataItemName.Width: return GetWidth(); case MetadataItemName.GpsVersion: case MetadataItemName.GpsLocation: case MetadataItemName.GpsLatitude: case MetadataItemName.GpsLongitude: case MetadataItemName.GpsAltitude: case MetadataItemName.GpsDestLocation: case MetadataItemName.GpsDestLatitude: //case MetadataItemName.GpsLocationWithMapLink: // Built from template, nothing to extract //case MetadataItemName.GpsDestLocationWithMapLink: // Built from template, nothing to extract case MetadataItemName.GpsDestLongitude: return GetGpsValue(metaName); case MetadataItemName.IptcByline: case MetadataItemName.IptcBylineTitle: case MetadataItemName.IptcCaption: case MetadataItemName.IptcCity: case MetadataItemName.IptcCopyrightNotice: case MetadataItemName.IptcCountryPrimaryLocationName: case MetadataItemName.IptcCredit: case MetadataItemName.IptcDateCreated: case MetadataItemName.IptcHeadline: case MetadataItemName.IptcKeywords: case MetadataItemName.IptcObjectName: case MetadataItemName.IptcOriginalTransmissionReference: case MetadataItemName.IptcProvinceState: case MetadataItemName.IptcRecordVersion: case MetadataItemName.IptcSource: case MetadataItemName.IptcSpecialInstructions: case MetadataItemName.IptcSublocation: case MetadataItemName.IptcWriterEditor: return GetIptcValue(metaName); default: return base.GetMetaValue(metaName); } }
/// <summary> /// Persists the meta value identified by <paramref name="metaName" /> to the media file. It is expected the meta item /// exists in <see cref="IGalleryObject.MetadataItems" />. /// </summary> /// <param name="metaName">Name of the meta item to persist.</param> /// <exception cref="System.NotSupportedException"></exception> public override void SaveMetaValue(MetadataItemName metaName) { PersistMetaValue(metaName, MetaPersistAction.Save); }
private void VerifyObjectIsInflated(MetadataItemName propertyValue) { // If no meta name has been specified, and this is not a new object, and it has not been inflated // from the database, go to the database and retrieve the info for this object. lock (_lock) { if ((propertyValue == MetadataItemName.NotSpecified) && (!this.IsNew) && (!this.IsInflated)) { Inflate(); } } }
/// <summary> /// Initializes a new instance of the <see cref="AlbumProfile" /> class. /// </summary> /// <param name="albumId">The album ID.</param> /// <param name="sortByMetaName">The metadata name to sort the album by.</param> /// <param name="sortAscending">Indicates the direction the album is to be sorted.</param> public AlbumProfile(int albumId, MetadataItemName sortByMetaName, bool sortAscending) { AlbumId = albumId; SortByMetaName = sortByMetaName; SortAscending = sortAscending; }
/// <summary> /// Initializes a new instance of the <see cref="Album" /> class. /// </summary> /// <param name="id">The album ID.</param> /// <param name="galleryId">The gallery ID.</param> /// <param name="parentId">The ID of the parent album that contains this album.</param> /// <param name="directoryName">Name of the directory.</param> /// <param name="thumbnailMediaObjectId">The thumbnail media object id.</param> /// <param name="sortByMetaName">The metadata item to sort the album by.</param> /// <param name="sortAscending">Indicates whether the contents of the album are sorted in ascending order. Specify null if /// the sort order is not known.</param> /// <param name="sequence">The sequence.</param> /// <param name="dateStart">The starting date for this album.</param> /// <param name="dateEnd">The ending date for this album.</param> /// <param name="createdByUsername">The user name of the user who created this gallery object.</param> /// <param name="dateAdded">The date this gallery object was created.</param> /// <param name="lastModifiedByUsername">The user name of the user who last modified this gallery object.</param> /// <param name="dateLastModified">The date and time this gallery object was last modified.</param> /// <param name="ownerUsername">The user name of this gallery object's owner.</param> /// <param name="ownerRoleName">The name of the role associated with this gallery object's owner.</param> /// <param name="isPrivate"><c>true</c> this gallery object is hidden from anonymous users; otherwise <c>false</c>.</param> /// <param name="isInflated">A bool indicating whether this object is fully inflated.</param> /// <param name="metadata">A collection of <see cref="Data.MetadataDto" /> instances containing metadata for the /// object. Specify null if not available.</param> /// <exception cref="System.ArgumentOutOfRangeException">galleryId</exception> internal Album(int id, int galleryId, int parentId, string directoryName, int thumbnailMediaObjectId, MetadataItemName sortByMetaName, bool? sortAscending, int sequence, DateTime dateStart, DateTime dateEnd, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, string ownerUsername, string ownerRoleName, bool isPrivate, bool isInflated, IEnumerable<MetadataDto> metadata) { if (galleryId == int.MinValue) { throw new ArgumentOutOfRangeException("galleryId", String.Format(CultureInfo.CurrentCulture, "Gallery ID must be set to a valid value. Instead, the value was {0}.", galleryId)); } this._galleryObjects = new GalleryObjectCollection(); System.Diagnostics.Debug.Assert(this._areChildrenInflated == false, String.Format(CultureInfo.CurrentCulture, "The private boolean field _areChildrenInflated should have been initialized to false, but instead it was {0}.", this._areChildrenInflated)); this.Id = id; // Specify gallery ID: Use galleryID parm if specified, otherwise, use gallery ID of parent. If no parent, use int.MinValue //this.GalleryId = (galleryId > int.MinValue ? galleryId : (parentId >= 0 ? this.Parent.GalleryId : int.MinValue)); this.GalleryId = galleryId; if (parentId > 0) { this.Parent = Factory.CreateAlbumInstance(parentId, galleryId); } else if (parentId == 0) { this.Parent.Id = parentId; // Parent ID of root album is always 0. } //this.Title = title; this._directoryName = directoryName; //this._summary = summary; this.Sequence = sequence; this._dateStart = dateStart; this._dateEnd = dateEnd; this.CreatedByUserName = createdByUsername; this.DateAdded = dateAdded; this.LastModifiedByUserName = lastModifiedByUsername; this._ownerUsername = ownerUsername; this._ownerRoleName = ownerRoleName; this.DateLastModified = dateLastModified; this.IsPrivate = isPrivate; this.AllowMetadataLoading = true; this._fullPhysicalPathOnDisk = string.Empty; //this._thumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId); this.ThumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId); this._isThumbnailInflated = false; if (this._thumbnailMediaObjectId > 0) { this.Thumbnail = DisplayObject.CreateInstance(this, this._thumbnailMediaObjectId, DisplayObjectType.Thumbnail); } else { this.Thumbnail = GetDefaultAlbumThumbnail(); } this.VirtualAlbumType = (id > int.MinValue ? VirtualAlbumType.NotVirtual : VirtualAlbumType.NotSpecified); this.SaveBehavior = Factory.GetAlbumSaveBehavior(this); this.DeleteBehavior = Factory.GetAlbumDeleteBehavior(this); this.MetadataReadWriter = Factory.GetMetadataReadWriter(this); IGallerySettings gallerySetting = Factory.LoadGallerySetting(GalleryId); if (this.IsNew) { if (sortByMetaName == MetadataItemName.NotSpecified) { sortByMetaName = gallerySetting.DefaultAlbumSortMetaName; } if (!sortAscending.HasValue) { sortAscending = gallerySetting.DefaultAlbumSortAscending; } if (gallerySetting.ExtractMetadata) { ExtractMetadata(); } } if (sortByMetaName != MetadataItemName.NotSpecified) this.SortByMetaName = sortByMetaName; if (sortAscending.HasValue) this.SortAscending = sortAscending.Value; if (metadata != null) AddMeta(GalleryObjectMetadataItemCollection.FromMetaDtos(this, metadata)); this.IsInflated = isInflated; // Setting the previous properties has caused HasChanges = true, but we don't want this while // we're instantiating a new object. Reset to false. this.HasChanges = false; this.Saving += Album_Saving; this.Saved += Album_Saved; }
private void SetOrientationMetadata(BitmapMetadata bitmapMetadata, MetadataItemName metaName, MetaPersistAction persistAction) { switch (persistAction) { case MetaPersistAction.Delete: bitmapMetadata.RemoveQuery(UpdatableMetaItems[metaName]); break; case MetaPersistAction.Save: IGalleryObjectMetadataItem orientationMeta; if (GalleryObject.MetadataItems.TryGetMetadataItem(metaName, out orientationMeta)) { ushort orientationRaw; if (UInt16.TryParse(orientationMeta.RawValue, out orientationRaw) && MetadataEnumHelper.IsValidOrientation((Orientation)orientationRaw)) { bitmapMetadata.SetQuery(UpdatableMetaItems[metaName], orientationRaw); } } break; default: throw new InvalidEnumArgumentException(String.Format(CultureInfo.CurrentCulture, "This function is not designed to handle the enumeration value {0}. The function must be updated.", persistAction)); } }
private void RemoveMetadataItem(MetadataItemName metaName) { IGalleryObjectMetadataItem metaItem; if (MetadataItems.TryGetMetadataItem(metaName, out metaItem)) { metaItem.IsDeleted = true; } }
private void SetMetadata(BitmapMetadata bitmapMetadata, MetadataItemName metaName, MetaPersistAction persistAction) { if (!UpdatableMetaItems.ContainsKey(metaName)) { throw new ArgumentException(String.Format("This function does not support persisting the meta item {0}.", metaName)); } switch (metaName) { case MetadataItemName.Orientation: SetOrientationMetadata(bitmapMetadata, metaName, persistAction); break; default: throw new InvalidEnumArgumentException(String.Format(CultureInfo.CurrentCulture, "This function is not designed to handle the enumeration value {0}. The function must be updated.", metaName)); } //if (caption != null) //{ // bitmapMetadata.Comment = caption; //} //if (dateTaken.HasValue) //{ // bitmapMetadata.DateTaken = dateTaken.Value.ToString("M/d/yyyy HH:mm:ss"); // bitmapMetadata.SetQuery(DATE_TAKEN_QUERY, dateTaken.Value.ToString("yyyy:MM:dd HH:mm:ss")); // bitmapMetadata.SetQuery(DIGITIZED_DATE_QUERY, dateTaken.Value.ToString("yyyy:MM:dd HH:mm:ss")); // bitmapMetadata.SetQuery(ORIGINAL_DATE_QUERY, dateTaken.Value.ToString("yyyy:MM:dd HH:mm:ss")); //} ////-----------tags---------------------- //List<String> tagsList = new List<String>(); //foreach (string tag in tags) //{ // if (tag.Length > 0) // tagsList.Add(tag); //} //if (tagsList.Count == 0) // tagsList.Add(""); ////XMP //bitmapMetadata.Keywords = new System.Collections.ObjectModel.ReadOnlyCollection<string>(tagsList); ////IPTC //string[] iptcTagsList = tagsList.ToArray(); //bitmapMetadata.SetQuery(IPTC_KEYWORDS_QUERY, iptcTagsList); ////-----------tags---------------------- }
/// <summary> /// Reverse the gallery objects in the <paramref name="album" /> if they are custom sorted and the user /// clicked the reverse sort button (i.e. changed the <paramref name="previousSortAscending" /> value). /// This can't be handled by the normal sort routine because we aren't actually sorting on any particular /// metadata value. /// </summary> /// <param name="album">The album whose items are to be sorted.</param> /// <param name="previousSortByMetaName">The name of the metadata property the album was previously sorted on.</param> /// <param name="previousSortAscending">Indicates whether the album was previously sorted in ascending order.</param> private static void ReverseCustomSortIfNeeded(IAlbum album, MetadataItemName previousSortByMetaName, bool previousSortAscending) { var albumIsCustomSortedAndUserIsChangingSortDirection = ((album.SortByMetaName == MetadataItemName.NotSpecified) && (album.SortByMetaName == previousSortByMetaName) && (album.SortAscending != previousSortAscending)); if (albumIsCustomSortedAndUserIsChangingSortDirection) { // Album is being manually sorted and user clicked the reverse button. var seq = 1; foreach (var galleryObject in album.GetChildGalleryObjects().ToSortedList().Reverse()) { galleryObject.Sequence = seq; seq++; } } }
/// <summary> /// Persists the meta value. /// </summary> /// <param name="metaName">Name of the meta.</param> /// <param name="persistAction">The persist action.</param> private void PersistMetaValue(MetadataItemName metaName, MetaPersistAction persistAction) { if (!UpdatableMetaItems.ContainsKey(metaName)) { EventController.RecordEvent(String.Format("This version of Gallery Server Pro does not support modifying the meta value {0} in the original file. The request to save or delete the meta value was ignored.", metaName)); return; } lock (_sharedLock) { bool isSuccessful = false; var filePath = GalleryObject.Original.FileNamePhysicalPath; using (Stream savedFile = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite)) { var output = BitmapDecoder.Create(savedFile, BitmapCreateOptions.None, BitmapCacheOption.Default); var bitmapMetadata = output.Frames[0].CreateInPlaceBitmapMetadataWriter(); if (bitmapMetadata != null) { SetMetadata(bitmapMetadata, metaName, persistAction); if (bitmapMetadata.TrySave()) { isSuccessful = true; } } } // If the save wasn't successful, try to save another way. if (!isSuccessful) { string tmpFilePath = Path.Combine(AppSetting.Instance.TempUploadDirectory, String.Concat(Guid.NewGuid().ToString(), ".tmp")); TryAlternateMethodsOfPersistingMetadata(filePath, tmpFilePath, metaName, persistAction); ReplaceFileSafely(tmpFilePath, filePath); } } }
/// <summary> /// Permanently removes the meta value from the media file. The item is also removed from /// <see cref="IGalleryObject.MetadataItems" />. /// </summary> /// <param name="metaName">Name of the meta item to delete.</param> /// <exception cref="System.NotSupportedException"></exception> public virtual void DeleteMetaValue(MetadataItemName metaName) { throw new NotSupportedException(); }
/// <summary> /// Persists the meta value identified by <paramref name="metaName" /> to the media file. It is expected the meta item /// exists in <see cref="IGalleryObject.MetadataItems" />. /// </summary> /// <param name="metaName">Name of the meta item to persist.</param> /// <exception cref="System.NotSupportedException"></exception> public virtual void SaveMetaValue(MetadataItemName metaName) { // Do nothing. Functionality is contained in classes that inherit from this class (e.g. ImageMetadataReadWriter). }
/// <summary> /// Gets the requested <paramref name="metaName" /> instance for the specified <paramref name="galleryObjectId" /> /// having the specified <paramref name="goType" />. Returns null if no metadata item exists. /// Verifies user has permission to view item, throwing <see cref="GallerySecurityException" /> /// if authorization is denied. /// </summary> /// <param name="galleryObjectId">The ID for either an album or a media object.</param> /// <param name="goType">The type of gallery object.</param> /// <param name="metaName">Name of the metaitem to return.</param> /// <returns>Returns an instance of <see cref="IGalleryObjectMetadataItemCollection" />.</returns> /// <exception cref="GallerySecurityException">Thrown when user does not have permission to /// view the requested item.</exception> /// <exception cref="InvalidMediaObjectException">Thrown when the requested meta item or its /// associated media object does not exist in the data store.</exception> /// <exception cref="InvalidAlbumException">Thrown when the album associated with the /// meta item does not exist in the data store.</exception> public static IGalleryObjectMetadataItem Get(int galleryObjectId, GalleryObjectType goType, MetadataItemName metaName) { // Security check: Make sure user has permission to view item IGalleryObject go; if (goType == GalleryObjectType.Album) { go = Factory.LoadAlbumInstance(galleryObjectId, false); SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), go.Id, go.GalleryId, Utils.IsAuthenticated, go.IsPrivate, ((IAlbum)go).IsVirtualAlbum); } else { go = Factory.LoadMediaObjectInstance(galleryObjectId); SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), go.Parent.Id, go.GalleryId, Utils.IsAuthenticated, go.Parent.IsPrivate, ((IAlbum)go.Parent).IsVirtualAlbum); } IGalleryObjectMetadataItem md; GetGalleryObjectMetadataItemCollection(galleryObjectId, goType).TryGetMetadataItem(metaName, out md); return md; }
private static Entity.MetaItem GetMetaItemForTag(Entity.MetaItem[] meta, MetadataItemName tagName, Entity.GalleryItem galleryItem) { var tagMi = meta.FirstOrDefault(m => m.MTypeId == (int)tagName); if (tagMi != null) { return tagMi; } else { // Last item doesn't have a tag. Create one. This code path should be pretty rare. int galleryId; if (galleryItem.IsAlbum) galleryId = AlbumController.LoadAlbumInstance(galleryItem.Id, false).GalleryId; else galleryId = Factory.LoadMediaObjectInstance(galleryItem.Id).GalleryId; bool isEditable = Factory.LoadGallerySetting(galleryId).MetadataDisplaySettings.Find(tagName).IsEditable; tagMi = new Entity.MetaItem { Id = int.MinValue, MediaId = galleryItem.Id, GTypeId = galleryItem.ItemType, MTypeId = (int)tagName, Desc = tagName.ToString(), Value = String.Empty, IsEditable = isEditable }; Array.Resize(ref meta, meta.Count() + 1); meta[meta.Length - 1] = tagMi; return tagMi; } }
/// <summary> /// Determines whether the <paramref name="metadataItemName"/> is a member of the collection. /// </summary> /// <param name="metadataItemName">The <see cref="MetadataItemName"/> to search for.</param> /// <returns>Returns <c>true</c> if <paramref name="metadataItemName"/> is in the current collection; /// otherwise returns <c>false</c>. /// </returns> public bool Contains(MetadataItemName metadataItemName) { IGalleryObjectMetadataItem metadataItem; return(TryGetMetadataItem(metadataItemName, out metadataItem)); }
/// <summary> /// Generate a collection of all tag values that exist associated with the specified /// <paramref name="galleryItems" /> having the specified <paramref name="tagName" />. /// Individual tag values will be repeated when they belong to multiple gallery items. /// </summary> /// <param name="galleryItems">The gallery items.</param> /// <param name="tagName">Name of the tag.</param> /// <returns>Returns a collection of strings.</returns> /// <exception cref="InvalidAlbumException">Thrown when the requested album does not exist.</exception> /// <exception cref="InvalidMediaObjectException">Thrown when the requested media object does not exist.</exception> private static IEnumerable<string> GetTagListForGalleryItems(IEnumerable<Entity.GalleryItem> galleryItems, MetadataItemName tagName) { var tagList = new List<string>(); foreach (var metas in galleryItems.Select(GetGalleryObjectMetadataItemCollection)) { tagList.AddRange(GetTagList(metas, tagName)); } return tagList; }
private IMetaValue GetIptcValue(MetadataItemName metaName) { string iptcValue; try { iptcValue = WpfMetadata.GetQuery(String.Format(CultureInfo.InvariantCulture, IptcQueryFormatString, IptcQueryParameters[metaName])) as string; } catch (ArgumentNullException) { // Some images throw this exception. When this happens, just exit. return null; } catch (InvalidOperationException) { // Some images throw this exception. When this happens, just exit. return null; } if (String.IsNullOrWhiteSpace(iptcValue)) return null; var formattedIptcValue = iptcValue; // For dates, format to a specific pattern. if (metaName == MetadataItemName.IptcDateCreated) { var dateTaken = TryParseDate(iptcValue); if (dateTaken.Year > DateTime.MinValue.Year) formattedIptcValue = dateTaken.ToString(DateTimeFormatString, CultureInfo.InvariantCulture); } return new MetaValue(formattedIptcValue, iptcValue); }