/// <summary> /// Creates a collection of MIME types for the specified <paramref name="galleryId" /> by copying the master list of MIME /// types and updating each copied instance with gallery-specific properties, most notable <see cref="IMimeType.AllowAddToGallery" />. /// The collection is added to the static member variable <see cref="_mimeTypes" /> where <paramref name="galleryId" /> is /// the key and the collection of MIME types is the value. Returns <c>true</c> when this function successfully creates the /// collection and adds it to the static member variable <see cref="_mimeTypes" />; otherwise returns <c>false</c>. /// </summary> /// <param name="galleryId">The gallery ID.</param> /// <returns>Returns <c>true</c> when this function successfully creates the collection and adds it to the static member /// variable <see cref="_mimeTypes" />; otherwise returns <c>false</c>. A value of <c>false</c> indicates no gallery-specific /// MIME type records were found in the data store.</returns> private static bool GenerateMimeTypesForGallery(int galleryId) { IMimeTypeCollection baseMimeTypes = LoadMimeTypes(Int32.MinValue); IMimeTypeCollection newMimeTypes = new MimeTypeCollection(); IBrowserTemplateCollection browserTemplates = Factory.LoadBrowserTemplates(); bool foundRows = false; using (IDataReader dr = Factory.GetDataProvider().MimeType_GetMimeTypeGalleries()) { //SELECT mtg.MimeTypeGalleryId, mtg.FKGalleryId, mt.FileExtension, mtg.IsEnabled //FROM gs_MimeType mt INNER JOIN gs_MimeTypeGallery mtg ON mt.MimeTypeId = mtg.FKMimeTypeId //ORDER BY mt.FileExtension; while (dr.Read()) { int galleryIdInDb = Convert.ToInt32(dr["FKGalleryId"], CultureInfo.InvariantCulture); if (galleryIdInDb != galleryId) { continue; // We only care about loading items for the requested gallery, so skip any others. } foundRows = true; IMimeType mimeType = baseMimeTypes.Find(dr["FileExtension"].ToString()); if (mimeType == null) { throw new BusinessException(String.Format("Could not find a IMimeType with file extension \"{0}\" in the list of base MIME types.", dr["FileExtension"].ToString())); } IMimeType newMimeType = mimeType.Copy(); newMimeType.GalleryId = galleryId; newMimeType.MimeTypeGalleryId = Convert.ToInt32(dr["MimeTypeGalleryId"], CultureInfo.InvariantCulture); newMimeType.AllowAddToGallery = Convert.ToBoolean(dr["IsEnabled"], CultureInfo.InvariantCulture); // Populate the browser collection. newMimeType.BrowserTemplates.AddRange(browserTemplates.Get(newMimeType)); // Validate the browser templates. There may not be any, which is OK (for example, there isn't one defined for 'application/msword'). // But if there *IS* one defined, there must be one with a browser ID of "default". if ((newMimeType.BrowserTemplates.Count > 0) && (newMimeType.BrowserTemplates.Get("default") == null)) { throw new BusinessException(string.Format("No default browser template. Could not find a browser template for MIME type \"{0}\" or \"{1}\" with browser ID = \"default\".", newMimeType.FullType, String.Concat(newMimeType.MajorType, "/*"))); } newMimeTypes.Add(newMimeType); } } if (foundRows) { lock (_sharedLock) { _mimeTypes.Add(galleryId, newMimeTypes); } } return(foundRows); }
/// <summary> /// Updates the <paramref name="baseMimeTypes" /> with configuration data for the <paramref name="galleryId" />. /// Returns <c>true</c> when at least one record in the <see cref="MimeTypeGalleryDto" /> table exists for the /// <paramref name="galleryId" />; otherwise returns <c>false</c>. /// </summary> /// <param name="baseMimeTypes">A collection of MIME types to be updated with gallery-specific data.</param> /// <param name="galleryId">The gallery ID.</param> /// <returns>Returns <c>true</c> when at least one record in the <see cref="MimeTypeGalleryDto" /> table exists for the /// <paramref name="galleryId" />; otherwise returns <c>false</c>.</returns> private static bool ConfigureMimeTypesForGallery(IMimeTypeCollection baseMimeTypes, int galleryId) { //IMimeTypeCollection baseMimeTypes = LoadMimeTypes(Int32.MinValue); //IMimeTypeCollection newMimeTypes = new MimeTypeCollection(); var mediaTemplates = Factory.LoadMediaTemplates(); var foundRows = false; using (var repo = new MimeTypeGalleryRepository()) { foreach (var mtgDto in repo.Where(m => m.FKGalleryId == galleryId, m => m.MimeType)) { foundRows = true; var mimeType = baseMimeTypes.Find(mtgDto.MimeType.FileExtension); if (mimeType == null) { throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "Could not find a IMimeType with file extension \"{0}\" in the list of base MIME types.", mtgDto.MimeType.FileExtension)); } mimeType.GalleryId = galleryId; mimeType.MimeTypeGalleryId = mtgDto.MimeTypeGalleryId; mimeType.AllowAddToGallery = mtgDto.IsEnabled; // Populate the media template collection. mimeType.MediaTemplates.AddRange(mediaTemplates.Find(mimeType)); // Validate the media templates. There may not be any, which is OK (for example, there isn't one defined for 'application/msword'). // But if there *IS* one defined, there must be one with a browser ID of "default". if ((mimeType.MediaTemplates.Count > 0) && (mimeType.MediaTemplates.Find("default") == null)) { throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "No default media template. Could not find a media template for MIME type \"{0}\" or \"{1}\" with browser ID = \"default\".", mimeType.FullType, String.Concat(mimeType.MajorType, "/*"))); } } } return(foundRows); }
/// <summary> /// Updates the <paramref name="baseMimeTypes" /> with configuration data for the <paramref name="galleryId" />. /// Returns <c>true</c> when at least one record in the <see cref="MimeTypeGalleryDto" /> table exists for the /// <paramref name="galleryId" />; otherwise returns <c>false</c>. /// </summary> /// <param name="baseMimeTypes">A collection of MIME types to be updated with gallery-specific data.</param> /// <param name="galleryId">The gallery ID.</param> /// <returns>Returns <c>true</c> when at least one record in the <see cref="MimeTypeGalleryDto" /> table exists for the /// <paramref name="galleryId" />; otherwise returns <c>false</c>.</returns> private static bool ConfigureMimeTypesForGallery(IMimeTypeCollection baseMimeTypes, int galleryId) { //IMimeTypeCollection baseMimeTypes = LoadMimeTypes(Int32.MinValue); //IMimeTypeCollection newMimeTypes = new MimeTypeCollection(); var mediaTemplates = Factory.LoadMediaTemplates(); var foundRows = false; using (var repo = new MimeTypeGalleryRepository()) { foreach (var mtgDto in repo.Where(m => m.FKGalleryId == galleryId, m => m.MimeType)) { foundRows = true; var mimeType = baseMimeTypes.Find(mtgDto.MimeType.FileExtension); if (mimeType == null) { throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "Could not find a IMimeType with file extension \"{0}\" in the list of base MIME types.", mtgDto.MimeType.FileExtension)); } mimeType.GalleryId = galleryId; mimeType.MimeTypeGalleryId = mtgDto.MimeTypeGalleryId; mimeType.AllowAddToGallery = mtgDto.IsEnabled; // Populate the media template collection. mimeType.MediaTemplates.AddRange(mediaTemplates.Find(mimeType)); // Validate the media templates. There may not be any, which is OK (for example, there isn't one defined for 'application/msword'). // But if there *IS* one defined, there must be one with a browser ID of "default". if ((mimeType.MediaTemplates.Count > 0) && (mimeType.MediaTemplates.Find("default") == null)) { throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "No default media template. Could not find a media template for MIME type \"{0}\" or \"{1}\" with browser ID = \"default\".", mimeType.FullType, String.Concat(mimeType.MajorType, "/*"))); } } } return foundRows; }