/// <summary> /// Loads the set of MIME types from the data store. These MIME types are the master list of MIME types and are not /// specific to a particular gallery. That is, the <see cref="IMimeType.GalleryId" /> property is set to <see cref="Int32.MinValue" /> /// and the <see cref="IMimeType.AllowAddToGallery" /> property is <c>false</c> for all items. During this function the /// static member variable <see cref="_mimeTypes" /> is cleared of all contents and populated with a single entry /// containing <see cref="Int32.MinValue" /> as the key and the MIME types as the value. /// </summary> /// <returns>Returns a <see cref="IMimeTypeCollection" /> containing MIME types. This is the same object as is added /// as the first item in the static member variable <see cref="_mimeTypes" />.</returns> /// <exception cref="BusinessException">Thrown when no records were found in the master list of MIME types in the data store.</exception> private static IMimeTypeCollection LoadMimeTypesFromDataStore() { IMimeTypeCollection baseMimeTypes = new MimeTypeCollection(); using (IDataReader dr = Factory.GetDataProvider().MimeType_GetMimeTypes()) { while (dr.Read()) { baseMimeTypes.Add(new MimeType(Convert.ToInt32(dr["MimeTypeId"], CultureInfo.InvariantCulture), Int32.MinValue, Int32.MinValue, dr["FileExtension"].ToString().Trim(), dr["MimeTypeValue"].ToString().Trim(), dr["BrowserMimeTypeValue"].ToString().Trim(), false)); } if (baseMimeTypes.Count == 0) { throw new BusinessException("No records were found in the master list of MIME types in the data store. Specifically, no records were returned by the IDataProvider.MimeType_GetMimeTypes method."); } lock (_sharedLock) { _mimeTypes.Clear(); _mimeTypes.Add(Int32.MinValue, baseMimeTypes); } } return(baseMimeTypes); }
/// <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> /// Loads the set of MIME types from the data store. These MIME types are the master list of MIME types and are not /// specific to a particular gallery. That is, the <see cref="IMimeType.GalleryId" /> property is set to <see cref="Int32.MinValue" /> /// and the <see cref="IMimeType.AllowAddToGallery" /> property is <c>false</c> for all items. /// </summary> /// <returns>Returns a <see cref="IMimeTypeCollection" /> containing MIME types..</returns> /// <exception cref="BusinessException">Thrown when no records were found in the master list of MIME types in the data store.</exception> private static IMimeTypeCollection LoadMimeTypesFromDataStore() { IMimeTypeCollection baseMimeTypes = new MimeTypeCollection(); using (var repo = new MimeTypeRepository()) { foreach (var mimeTypeDto in repo.GetAll().OrderBy(m => m.FileExtension)) { baseMimeTypes.Add(new MimeType(mimeTypeDto.MimeTypeId, Int32.MinValue, Int32.MinValue, mimeTypeDto.FileExtension.Trim(), mimeTypeDto.MimeTypeValue.Trim(), mimeTypeDto.BrowserMimeTypeValue.Trim(), false)); } } if (baseMimeTypes.Count == 0) { throw new BusinessException("No records were found in the master list of MIME types in the data store."); } return(baseMimeTypes); }
/// <summary> /// Loads the set of MIME types from the data store. These MIME types are the master list of MIME types and are not /// specific to a particular gallery. That is, the <see cref="IMimeType.GalleryId" /> property is set to <see cref="Int32.MinValue" /> /// and the <see cref="IMimeType.AllowAddToGallery" /> property is <c>false</c> for all items. During this function the /// static member variable <see cref="_mimeTypes" /> is cleared of all contents and populated with a single entry /// containing <see cref="Int32.MinValue" /> as the key and the MIME types as the value. /// </summary> /// <returns>Returns a <see cref="IMimeTypeCollection" /> containing MIME types. This is the same object as is added /// as the first item in the static member variable <see cref="_mimeTypes" />.</returns> /// <exception cref="BusinessException">Thrown when no records were found in the master list of MIME types in the data store.</exception> private static IMimeTypeCollection LoadMimeTypesFromDataStore() { IMimeTypeCollection baseMimeTypes = new MimeTypeCollection(); foreach (Data.MimeTypeDto mimeTypeDto in Factory.GetDataProvider().MimeType_GetMimeTypes()) { baseMimeTypes.Add(new MimeType(mimeTypeDto.MimeTypeId, Int32.MinValue, Int32.MinValue, mimeTypeDto.FileExtension.Trim(), mimeTypeDto.MimeTypeValue.Trim(), mimeTypeDto.BrowserMimeTypeValue.Trim(), false)); } if (baseMimeTypes.Count == 0) { throw new BusinessException("No records were found in the master list of MIME types in the data store. Specifically, no records were returned by the IDataProvider.MimeType_GetMimeTypes method."); } lock (_sharedLock) { _mimeTypes.Clear(); _mimeTypes.Add(Int32.MinValue, baseMimeTypes); } return(baseMimeTypes); }