private IGalleryObjectMetadataItem GetApertureMetadataItem() { // The aperture is the same as the F-Number if present; otherwise it is calculated from ExifAperture. IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; string aperture = String.Empty; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifFNumber, out rawMdi)) { if (rawMdi.ExtractedValueType == ExtractedValueType.Fraction) { float exifFNumber = ((Fraction)rawMdi.Value).ToSingle(); aperture = exifFNumber.ToString("f/##0.#", CultureInfo.InvariantCulture); } } if ((String.IsNullOrEmpty(aperture)) && (RawMetadata.TryGetValue(RawMetadataItemName.ExifAperture, out rawMdi))) { if (rawMdi.ExtractedValueType == ExtractedValueType.Fraction) { float exifAperture = ((Fraction)rawMdi.Value).ToSingle(); float exifFNumber = (float)Math.Round(Math.Pow(Math.Sqrt(2), exifAperture), 1); aperture = exifFNumber.ToString("f/##0.#", CultureInfo.InvariantCulture); } } if (!String.IsNullOrEmpty(aperture)) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.LensAperture, Resources.Metadata_LensAperture, aperture, true); } return(mdi); }
public void Save(IGalleryObjectMetadataItem metaDataItem) { MetadataDto mDto; SaveInternal(metaDataItem, out mDto); Save(); }
public static MetaItem[] ToMetaItems(IGalleryObjectMetadataItemCollection metadataItems, IGalleryObject galleryObject) { var metaItems = new MetaItem[metadataItems.Count]; var metaDefs = Factory.LoadGallerySetting(galleryObject.GalleryId).MetadataDisplaySettings; var moProfiles = ProfileController.GetProfile().MediaObjectProfiles; for (int i = 0; i < metaItems.Length; i++) { IGalleryObjectMetadataItem md = metadataItems[i]; metaItems[i] = new MetaItem { Id = md.MediaObjectMetadataId, MediaId = galleryObject.Id, MTypeId = (int)md.MetadataItemName, GTypeId = (int)galleryObject.GalleryObjectType, Desc = md.Description, Value = md.Value, IsEditable = metaDefs.Find(md.MetadataItemName).IsEditable }; if (md.MetadataItemName == MetadataItemName.Rating) { ReplaceAvgRatingWithUserRating(metaItems[i], moProfiles); } } return(metaItems); }
/// <summary> /// Returns a value indicating whether the <paramref name="mdItem" /> contains ALL the tags contained in SearchOptions.Tags. /// The comparison is case insensitive. /// </summary> /// <param name="mdItem">The metadata item.</param> /// <returns><c>true</c> if the metadata item contains all the tags, <c>false</c> otherwise</returns> private bool MetadataItemContainsAllTags(IGalleryObjectMetadataItem mdItem) { // First split the meta value into the separate tag items, trimming and converting to lower case. var albumTags = mdItem.Value.ToLowerInvariant().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()); // Now make sure that albumTags contains ALL the items in SearchOptions.Tags. return(SearchOptions.Tags.Aggregate(true, (current, tag) => current & albumTags.Contains(tag.ToLowerInvariant()))); }
private SaveAction SaveInternal(IGalleryObjectMetadataItem metaDataItem, out MetadataDto mDto) { SaveAction result; if (metaDataItem.IsDeleted) { // The item has been marked for deletion, so let's smoke it. mDto = Find(metaDataItem.MediaObjectMetadataId); if (mDto != null) { Delete(mDto); } // Remove it from the collection. metaDataItem.GalleryObject.MetadataItems.Remove(metaDataItem); result = SaveAction.Deleted; } else if (metaDataItem.MediaObjectMetadataId == int.MinValue) { // Insert the item. bool isAlbum = metaDataItem.GalleryObject.GalleryObjectType == GalleryObjectType.Album; mDto = new MetadataDto { MetaName = metaDataItem.MetadataItemName, FKAlbumId = isAlbum ? metaDataItem.GalleryObject.Id : (int?)null, FKMediaObjectId = isAlbum ? (int?)null : metaDataItem.GalleryObject.Id, RawValue = metaDataItem.RawValue, Value = metaDataItem.Value }; Add(mDto); result = SaveAction.Inserted; } else { // Update the item. mDto = Find(metaDataItem.MediaObjectMetadataId); if (mDto != null) { mDto.MetaName = metaDataItem.MetadataItemName; mDto.Value = metaDataItem.Value; mDto.RawValue = metaDataItem.RawValue; } result = SaveAction.Updated; } if (result != SaveAction.Deleted) { SaveTags(mDto, metaDataItem.GalleryObject.GalleryId); } return(result); }
/// <summary> /// Delete the specified metadata item from the data store. No error occurs if the record does not exist in the data store. /// </summary> /// <param name="metaDataItem">The metadata item to delete from the data store.</param> private static void DeleteMetadataItem(IGalleryObjectMetadataItem metaDataItem) { SqlCommand cmd = GetCommandMediaObjectMetadataDelete(); cmd.Parameters["@MediaObjectMetadataId"].Value = metaDataItem.MediaObjectMetadataId; cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); }
/// <summary> /// Delete the specified metadata item from the data store. No error occurs if the record does not exist in the data store. /// </summary> /// <param name="metaDataItem">The metadata item to delete from the data store.</param> private static void DeleteMetadataItem(IGalleryObjectMetadataItem metaDataItem) { using (SqlConnection cn = SqlDataProvider.GetDbConnection()) { using (SqlCommand cmd = GetCommandMediaObjectMetadataDelete(metaDataItem.MediaObjectMetadataId, cn)) { cn.Open(); cmd.ExecuteNonQuery(); } } }
private IGalleryObjectMetadataItem GetStringMetadataItem(RawMetadataItemName sourceRawMetadataName, FormattedMetadataItemName destinationFormattedMetadataName, string metadataDescription, string formatString) { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(sourceRawMetadataName, out rawMdi)) { mdi = new GalleryObjectMetadataItem(int.MinValue, destinationFormattedMetadataName, metadataDescription, String.Format(CultureInfo.CurrentCulture, formatString, rawMdi.Value.ToString().TrimEnd(new char[] { '\0' })), true); } return(mdi); }
/// <summary> /// Compares the current object with another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref name="other"/> parameter.Zero This object is equal to <paramref name="other"/>. Greater than zero This object is greater than <paramref name="other"/>. /// </returns> public int CompareTo(IGalleryObjectMetadataItem other) { if (other == null) { return(1); } else { return(String.Compare(this.Description, other.Description, StringComparison.CurrentCulture)); } }
private IGalleryObjectMetadataItem GetWidthMetadataItem() { IGalleryObjectMetadataItem mdi = null; int width = GetWidth(); if (width > 0) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.Width, Resources.Metadata_Width, String.Concat(width, " ", Resources.Metadata_Width_Units), true); } return(mdi); }
private IGalleryObjectMetadataItem GetHeightMetadataItem() { IGalleryObjectMetadataItem mdi = null; int height = GetHeight(); if (height > 0) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.Height, Resources.Metadata_Height, String.Concat(height, " ", Resources.Metadata_Height_Units), true); } return(mdi); }
/// <summary> /// Saves the specified meta data item. /// </summary> /// <param name="metaDataItem">The meta data item.</param> public void Save(IGalleryObjectMetadataItem metaDataItem) { MetadataDto mDto; var saveAction = SaveInternal(metaDataItem, out mDto); Save(); if (saveAction == SaveAction.Inserted) { metaDataItem.MediaObjectMetadataId = mDto.MetadataId; } }
private IGalleryObjectMetadataItem GetDimensionsMetadataItem() { IGalleryObjectMetadataItem mdi = null; int width = GetWidth(); int height = GetHeight(); if ((width > 0) && (height > 0)) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.Dimensions, Resources.Metadata_Dimensions, String.Concat(width, " x ", height), true); } return(mdi); }
private IGalleryObjectMetadataItem GetColorRepresentationMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifColorSpace, out rawMdi)) { string value = rawMdi.Value.ToString().Trim(); string formattedValue = (value == "1" ? Resources.Metadata_ColorRepresentation_sRGB : Resources.Metadata_ColorRepresentation_Uncalibrated); mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.ColorRepresentation, Resources.Metadata_ColorRepresentation, formattedValue, true); } return(mdi); }
/// <summary> /// Gets a metadata item containing the date the picture was taken. The date format conforms to the IETF RFC 1123 specification, /// which means it uses this format string: "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'" (e.g. "Mon, 17 Apr 2006 21:38:09 GMT"). See /// the DateTimeFormatInfo.RFC1123Pattern property for more information about the format. Returns null if no date is found /// in the metadata. /// </summary> /// <returns>Returns a metadata item containing the date the picture was taken. Returns null if no date is found /// in the metadata.</returns> private IGalleryObjectMetadataItem GetDatePictureTakenMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifDTOrig, out rawMdi)) { DateTime convertedDateTimeValue = ConvertExifDateTimeToDateTime(rawMdi.Value.ToString()); if (convertedDateTimeValue > DateTime.MinValue) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.DatePictureTaken, Resources.Metadata_DatePictureTaken, convertedDateTimeValue.ToString("R", CultureInfo.InvariantCulture), true); } } return(mdi); }
private IGalleryObjectMetadataItem GetFocalLengthMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifFocalLength, out rawMdi)) { if (rawMdi.ExtractedValueType == ExtractedValueType.Fraction) { float value = ((Fraction)rawMdi.Value).ToSingle(); string formattedValue = String.Concat(Math.Round(value), " ", Resources.Metadata_FocalLength_Units); mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.FocalLength, Resources.Metadata_FocalLength, formattedValue, true); } } return(mdi); }
private IGalleryObjectMetadataItem GetExposureCompensationMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifExposureBias, out rawMdi)) { if (rawMdi.ExtractedValueType == ExtractedValueType.Fraction) { float value = ((Fraction)rawMdi.Value).ToSingle(); string formattedValue = String.Concat(value.ToString("##0.# ", CultureInfo.InvariantCulture), Resources.Metadata_ExposureCompensation_Suffix); mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.ExposureCompensation, Resources.Metadata_ExposureCompensation, formattedValue, true); } } return(mdi); }
private IGalleryObjectMetadataItem GetFNumberMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifFNumber, out rawMdi)) { if (rawMdi.ExtractedValueType == ExtractedValueType.Fraction) { float value = ((Fraction)rawMdi.Value).ToSingle(); string formattedValue = value.ToString("f/##0.#", CultureInfo.InvariantCulture); mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.FNumber, Resources.Metadata_FNumber, formattedValue, true); } } return(mdi); }
private IGalleryObjectMetadataItem GetExposureProgramMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifExposureProg, out rawMdi)) { if (rawMdi.ExtractedValueType == ExtractedValueType.Int64) { ExposureProgram expProgram = (ExposureProgram)(Int64)rawMdi.Value; if (MetadataEnumHelper.IsValidExposureProgram(expProgram)) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.ExposureProgram, Resources.Metadata_ExposureProgram, expProgram.ToString(), true); } } } return(mdi); }
private IGalleryObjectMetadataItem GetFlashModeMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifFlash, out rawMdi)) { if (rawMdi.ExtractedValueType == ExtractedValueType.Int64) { FlashMode flashMode = (FlashMode)(Int64)rawMdi.Value; if (MetadataEnumHelper.IsValidFlashMode(flashMode)) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.FlashMode, Resources.Metadata_FlashMode, flashMode.ToString(), true); } } } return(mdi); }
private IGalleryObjectMetadataItem GetYResolutionMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; string resolutionUnit = String.Empty; if (RawMetadata.TryGetValue(RawMetadataItemName.ResolutionYUnit, out rawMdi)) { resolutionUnit = rawMdi.Value.ToString(); } if ((String.IsNullOrEmpty(resolutionUnit)) && (RawMetadata.TryGetValue(RawMetadataItemName.ResolutionUnit, out rawMdi))) { if (rawMdi.ExtractedValueType == ExtractedValueType.Int64) { ResolutionUnit resUnit = (ResolutionUnit)(Int64)rawMdi.Value; if (MetadataEnumHelper.IsValidResolutionUnit(resUnit)) { resolutionUnit = resUnit.ToString(); } } } if (RawMetadata.TryGetValue(RawMetadataItemName.YResolution, out rawMdi)) { string yResolution; if (rawMdi.ExtractedValueType == ExtractedValueType.Fraction) { yResolution = Math.Round(((Fraction)rawMdi.Value).ToSingle(), 2).ToString(CultureInfo.InvariantCulture); } else { yResolution = rawMdi.Value.ToString(); } string yResolutionString = String.Concat(yResolution, " ", resolutionUnit); mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.VerticalResolution, Resources.Metadata_VerticalResolution, yResolutionString, true); } return(mdi); }
private IGalleryObjectMetadataItem GetLightSourceMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; if (RawMetadata.TryGetValue(RawMetadataItemName.ExifLightSource, out rawMdi)) { if (rawMdi.ExtractedValueType == ExtractedValueType.Int64) { LightSource lightSource = (LightSource)(Int64)rawMdi.Value; if (MetadataEnumHelper.IsValidLightSource(lightSource)) { // Don't bother with it if it is "Unknown" if (lightSource != LightSource.Unknown) { mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.LightSource, Resources.Metadata_LightSource, lightSource.ToString(), true); } } } } return(mdi); }
private IGalleryObjectMetadataItem GetExposureTimeMetadataItem() { IGalleryObjectMetadataItem mdi = null; MetadataItem rawMdi = null; const Single NUM_SECONDS = 1; // If the exposure time is less than this # of seconds, format as fraction (1/350 sec.); otherwise convert to Single (2.35 sec.) if (RawMetadata.TryGetValue(RawMetadataItemName.ExifExposureTime, out rawMdi)) { string exposureTime = String.Empty; if ((rawMdi.ExtractedValueType == ExtractedValueType.Fraction) && ((Fraction)rawMdi.Value).ToSingle() > NUM_SECONDS) { exposureTime = Math.Round(((Fraction)rawMdi.Value).ToSingle(), 2).ToString(CultureInfo.InvariantCulture); } else { exposureTime = rawMdi.Value.ToString(); } string exposureTimeString = String.Concat(exposureTime, " ", Resources.Metadata_ExposureTime_Units); mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.ExposureTime, Resources.Metadata_ExposureTime, exposureTimeString, true); } return(mdi); }
/// <summary> /// Delete the specified metadata item from the data store. No error occurs if the record does not exist in the data store. /// </summary> /// <param name="metaDataItem">The metadata item to delete from the data store.</param> /// <param name="cn">An open database connection.</param> private static void DeleteMetadataItem(IGalleryObjectMetadataItem metaDataItem, SQLiteConnection cn) { using (SQLiteCommand cmd = cn.CreateCommand()) { const string sql = @" DELETE [gs_MediaObjectMetadata] WHERE MediaObjectMetadataId = @MediaObjectMetadataId;"; cmd.CommandText = sql; cmd.Parameters.AddWithValue("@MediaObjectMetadataId", metaDataItem.MediaObjectMetadataId); cmd.ExecuteNonQuery(); } }
private void UpdateInternalMetaItem(IGalleryObjectMetadataItem metaItem) { IGalleryObjectMetadataItem existingMetaItem; if (MetadataItems.TryGetMetadataItem(metaItem.MetadataItemName, out existingMetaItem)) { existingMetaItem.Description = metaItem.Description; if (OkToUpdateMetaItemValue(metaItem)) { // Update value only when we have some data. This helps prevent overwriting user-entered data. existingMetaItem.Value = metaItem.Value; existingMetaItem.RawValue = metaItem.RawValue; } } else { var metaItems = Factory.CreateMetadataCollection(); metaItems.Add(metaItem); AddMeta(metaItems); } }
/// <summary> /// Incorporate the new <paramref name="userRatingStr" /> into the current <paramref name="ratingItem" /> /// belonging to the <paramref name="galleryObject" />. Automatically increments and saves the rating count /// meta item. Detects when a user has previously rated the item and reverses the effects of the previous /// rating before applying the new one. Returns a <see cref="System.Single" /> converted to a string to 4 /// decimal places (e.g. "2.4653"). /// </summary> /// <param name="galleryObject">The gallery object being rated.</param> /// <param name="ratingItem">The rating metadata item.</param> /// <param name="userRatingStr">The user rating to be applied to the gallery object rating.</param> /// <returns>Returns a <see cref="System.String" /> representing the new rating.</returns> private static string CalculateAvgRating(IGalleryObject galleryObject, IGalleryObjectMetadataItem ratingItem, string userRatingStr) { var ratingCountItem = GetRatingCountMetaItem(galleryObject); int ratingCount; Int32.TryParse(ratingCountItem.Value, out ratingCount); float currentAvgRating, userRating; Single.TryParse(ratingItem.Value, out currentAvgRating); Single.TryParse(userRatingStr, out userRating); var moProfile = ProfileController.GetProfile().MediaObjectProfiles.Find(ratingItem.GalleryObject.Id); if (moProfile != null) { // User has previously rated this item. Reverse the influence that rating had on the item's average rating. currentAvgRating = RemoveUsersPreviousRating(ratingItem.Value, ratingCount, moProfile.Rating); // Subtract the user's previous rating from the total rating count while ensuring the # >= 0. ratingCount = Math.Max(ratingCount - 1, 0); } // Increment the rating count and persist. ratingCount++; ratingCountItem.Value = ratingCount.ToString(CultureInfo.InvariantCulture); Factory.SaveGalleryObjectMetadataItem(ratingCountItem, Utils.UserName); // Calculate the new rating. float newAvgRating = ((currentAvgRating * (ratingCount - 1)) + userRating) / (ratingCount); return newAvgRating.ToString("F4", CultureInfo.InvariantCulture); // Store rating to 4 decimal places }
/// <summary> /// Syncs the metadata value with the corresponding property on the album or media object. /// The album/media object properties are deprecated in version 3, but we want to sync them /// for backwards compatibility. A future version is expected to remove these properties, at /// which time this method will no longer be needed. /// </summary> /// <param name="md">An instance of <see cref="IGalleryObjectMetadataItem" /> being persisted to the data store.</param> /// <param name="userName">The user name of the currently logged on user. This will be used for the audit fields.</param> private static void SyncWithGalleryObjectProperties(IGalleryObjectMetadataItem md, string userName) { if ((md.MetadataItemName == MetadataItemName.Title) && (md.GalleryObject.GalleryObjectType == GalleryObjectType.Album)) { var album = LoadAlbumInstance(md.GalleryObject.Id, false, true); // If necessary, sync the directory name with the album title. var gs = LoadGallerySetting(album.GalleryId); if ((!album.IsRootAlbum) && (!album.IsVirtualAlbum) && (gs.SynchAlbumTitleAndDirectoryName)) { // Root albums do not have a directory name that reflects the album's title, so only update this property for non-root albums. if (!album.DirectoryName.Equals(album.Title, StringComparison.OrdinalIgnoreCase)) { // We only update the directory name when it is different. Without this check a user saving a // title without any changes would cause the directory name to get changed (e.g. 'Samples' // might get changed to 'Sample(1)') album.DirectoryName = HelperFunctions.ValidateDirectoryName(album.Parent.FullPhysicalPath, album.Title, gs.DefaultAlbumDirectoryNameLength); HelperFunctions.UpdateAuditFields(album, userName); album.Save(); } } } if (md.MetadataItemName == MetadataItemName.FileName) { // We are editing the filename item, so we want to rename the actual media file. // Load the media object instance and trigger a save. The save routine will detect // the metadata change and perform the rename for us. var mediaObject = LoadMediaObjectInstance(md.GalleryObject.Id, true); HelperFunctions.UpdateAuditFields(mediaObject, userName); mediaObject.Save(); } if (md.MetadataItemName == MetadataItemName.HtmlSource) { // We are editing the HTML content. This is the same as the media object's // ExternalHtmlSource, so update that item, too. var mediaObject = LoadMediaObjectInstance(md.GalleryObject.Id, true); // Verify the media object is an external one. It always should be, but we'll // double check to be sure. if (mediaObject.GalleryObjectType == GalleryObjectType.External) { mediaObject.Original.ExternalHtmlSource = md.Value; HelperFunctions.UpdateAuditFields(mediaObject, userName); mediaObject.Save(); } } }
/// <summary> /// Delete the specified metadata item from the data store. No error occurs if the record does not exist in the data store. /// </summary> /// <param name="metaDataItem">The metadata item to delete from the data store.</param> /// <param name="ctx">A database context.</param> private static void DeleteMetadataItem(IGalleryObjectMetadataItem metaDataItem, GspContext ctx) { MediaObjectMetadataDto mDto = ctx.MediaObjectMetadatas.Find(metaDataItem.MediaObjectMetadataId); if (mDto != null) { ctx.MediaObjectMetadatas.Remove(mDto); } }
/// <summary> /// Determines whether we can retrieve the value from <paramref name="metaItemSource" /> and assign it to the /// actual metadata item for the gallery object. Returns <c>true</c> when the metaitem has a value and when it /// does not belong to an album title or caption; otherwise returns <c>false</c>. /// </summary> /// <param name="metaItemSource">The source metaitem.</param> /// <returns>Returns <c>true</c> or <c>false</c>.</returns> private static bool OkToUpdateMetaItemValue(IGalleryObjectMetadataItem metaItemSource) { var hasValue = !String.IsNullOrWhiteSpace(metaItemSource.Value); var isAlbumTitleOrCaption = (metaItemSource.GalleryObject.GalleryObjectType == GalleryObjectType.Album) && ((metaItemSource.MetadataItemName == MetadataItemName.Title) || (metaItemSource.MetadataItemName == MetadataItemName.Caption)); return hasValue && !isAlbumTitleOrCaption; }
/// <summary> /// Returns a value indicating whether the <paramref name="mdItem" /> contains ALL the tags contained in SearchOptions.Tags. /// The comparison is case insensitive. /// </summary> /// <param name="mdItem">The metadata item.</param> /// <returns><c>true</c> if the metadata item contains all the tags, <c>false</c> otherwise</returns> private bool MetadataItemContainsAllTags(IGalleryObjectMetadataItem mdItem) { // First split the meta value into the separate tag items, trimming and converting to lower case. var albumTags = mdItem.Value.ToLowerInvariant().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()); // Now make sure that albumTags contains ALL the items in SearchOptions.Tags. return SearchOptions.Tags.Aggregate(true, (current, tag) => current & albumTags.Contains(tag.ToLowerInvariant())); }
/// <summary> /// Persists the metadata item to the data store, or deletes it when the delete flag is set. /// For certain items (title, filename, etc.), the associated gallery object's property is also /// updated. For items that are being deleted, it is also removed from the gallery object's metadata /// collection. /// </summary> /// <param name="md">An instance of <see cref="IGalleryObjectMetadataItem" /> to persist to the data store.</param> /// <param name="userName">The user name of the currently logged on user. This will be used for the audit fields.</param> /// <exception cref="InvalidMediaObjectException">Thrown when the requested meta item does not exist /// in the data store.</exception> public static void SaveGalleryObjectMetadataItem(IGalleryObjectMetadataItem md, string userName) { using (var repo = new MetadataRepository()) { repo.Save(md); } SyncWithGalleryObjectProperties(md, userName); }
/// <summary> /// Compares the current object with another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref name="other"/> parameter.Zero This object is equal to <paramref name="other"/>. Greater than zero This object is greater than <paramref name="other"/>. /// </returns> public int CompareTo(IGalleryObjectMetadataItem other) { if (other == null) return 1; else { return String.Compare(this.Description, other.Description, StringComparison.CurrentCulture); } }
/// <summary> /// Initializes a new instance of the <see cref="AddMetaEventArgs"/> class. /// </summary> /// <param name="metaItem"> </param> public AddMetaEventArgs(IGalleryObjectMetadataItem metaItem) { MetaItem = metaItem; }
private void AddExifMetadata(IGalleryObjectMetadataItemCollection metadataItems) { foreach (FormattedMetadataItemName metadataItemName in Enum.GetValues(typeof(FormattedMetadataItemName))) { IGalleryObjectMetadataItem mdi = null; switch (metadataItemName) { case FormattedMetadataItemName.Author: mdi = GetStringMetadataItem(RawMetadataItemName.Artist, FormattedMetadataItemName.Author, Resources.Metadata_Author); break; case FormattedMetadataItemName.CameraModel: mdi = GetStringMetadataItem(RawMetadataItemName.EquipModel, FormattedMetadataItemName.CameraModel, Resources.Metadata_CameraModel); break; case FormattedMetadataItemName.ColorRepresentation: mdi = GetColorRepresentationMetadataItem(); break; case FormattedMetadataItemName.Comment: mdi = GetStringMetadataItem(RawMetadataItemName.ExifUserComment, FormattedMetadataItemName.Comment, Resources.Metadata_Comment); break; case FormattedMetadataItemName.Copyright: mdi = GetStringMetadataItem(RawMetadataItemName.Copyright, FormattedMetadataItemName.Copyright, Resources.Metadata_Copyright); break; case FormattedMetadataItemName.DatePictureTaken: mdi = GetDatePictureTakenMetadataItem(); break; case FormattedMetadataItemName.Description: mdi = GetStringMetadataItem(RawMetadataItemName.ImageDescription, FormattedMetadataItemName.Description, Resources.Metadata_Description); break; case FormattedMetadataItemName.Dimensions: mdi = GetDimensionsMetadataItem(); break; case FormattedMetadataItemName.EquipmentManufacturer: mdi = GetStringMetadataItem(RawMetadataItemName.EquipMake, FormattedMetadataItemName.EquipmentManufacturer, Resources.Metadata_EquipmentManufacturer); break; case FormattedMetadataItemName.ExposureCompensation: mdi = GetExposureCompensationMetadataItem(); break; case FormattedMetadataItemName.ExposureProgram: mdi = GetExposureProgramMetadataItem(); break; case FormattedMetadataItemName.ExposureTime: mdi = GetExposureTimeMetadataItem(); break; case FormattedMetadataItemName.FlashMode: mdi = GetFlashModeMetadataItem(); break; case FormattedMetadataItemName.FNumber: mdi = GetFNumberMetadataItem(); break; case FormattedMetadataItemName.FocalLength: mdi = GetFocalLengthMetadataItem(); break; case FormattedMetadataItemName.Height: mdi = GetHeightMetadataItem(); break; case FormattedMetadataItemName.HorizontalResolution: mdi = GetXResolutionMetadataItem(); break; case FormattedMetadataItemName.IsoSpeed: mdi = GetStringMetadataItem(RawMetadataItemName.ExifISOSpeed, FormattedMetadataItemName.IsoSpeed, Resources.Metadata_IsoSpeed); break; case FormattedMetadataItemName.Keywords: break; // No way to access keywords through Exif, so just skip this one case FormattedMetadataItemName.LensAperture: mdi = GetApertureMetadataItem(); break; case FormattedMetadataItemName.LightSource: mdi = GetLightSourceMetadataItem(); break; case FormattedMetadataItemName.MeteringMode: mdi = GetMeteringModeMetadataItem(); break; case FormattedMetadataItemName.Rating: break; // No way to access rating through Exif, so just skip this one case FormattedMetadataItemName.Subject: break; // No way to access rating through Exif, so just skip this one case FormattedMetadataItemName.SubjectDistance: mdi = GetStringMetadataItem(RawMetadataItemName.ExifSubjectDist, FormattedMetadataItemName.SubjectDistance, Resources.Metadata_SubjectDistance, String.Concat("{0} ", Resources.Metadata_SubjectDistance_Units)); break; case FormattedMetadataItemName.Title: mdi = GetStringMetadataItem(RawMetadataItemName.ImageTitle, FormattedMetadataItemName.Title, Resources.Metadata_Title); break; case FormattedMetadataItemName.VerticalResolution: mdi = GetYResolutionMetadataItem(); break; case FormattedMetadataItemName.Width: mdi = GetWidthMetadataItem(); break; default: throw new System.ComponentModel.InvalidEnumArgumentException(string.Format(CultureInfo.CurrentCulture, "The FormattedMetadataItemName enumeration value {0} is not being processed in MediaObjectMetadataExtractor.AddExifMetadata().", metadataItemName.ToString())); } if ((mdi != null) && (!metadataItems.Contains(mdi))) { metadataItems.Add(mdi); } } }