예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeType"/> class.
        /// </summary>
        /// <param name="mimeTypeId">The value that uniquely identifies the MIME type.</param>
        /// <param name="mimeTypeGalleryId">The value that uniquely identifies the MIME type that applies to a particular gallery.</param>
        /// <param name="galleryId">The gallery ID. Specify <see cref="Int32.MinValue"/> if creating an instance that is not
        /// specific to a particular gallery.</param>
        /// <param name="fileExtension">A string representing the file's extension, including the period (e.g. ".jpg", ".avi").
        /// It is not case sensitive.</param>
        /// <param name="mimeTypeValue">The full mime type. This is the <see cref="MajorType"/> concatenated with the <see cref="Subtype"/>,
        /// with a '/' between them (e.g. image/jpeg, video/quicktime).</param>
        /// <param name="browserMimeType">The MIME type that can be understood by the browser for displaying this media object.  Specify null or
        /// <see cref="String.Empty"/> if the MIME type appropriate for the browser is the same as <paramref name="mimeTypeValue"/>.</param>
        /// <param name="allowAddToGallery">Indicates whether a file having this MIME type can be added to Gallery Server.
        /// This parameter is only relevant when a valid <paramref name="galleryId"/> is specified.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="fileExtension" /> or <paramref name="mimeTypeValue" /> is
        /// null or an empty string.</exception>
        private MimeType(int mimeTypeId, int mimeTypeGalleryId, int galleryId, string fileExtension, string mimeTypeValue, string browserMimeType, bool allowAddToGallery)
        {
            #region Validation

            if (String.IsNullOrEmpty(fileExtension))
            {
                throw new ArgumentOutOfRangeException("fileExtension", "Parameter cannot be null or empty.");
            }

            if (String.IsNullOrEmpty(mimeTypeValue))
            {
                throw new ArgumentOutOfRangeException("mimeTypeValue", "Parameter cannot be null or empty.");
            }

            // If browserMimeType is specified, it better be valid.
            if (!String.IsNullOrEmpty(browserMimeType))
            {
                ValidateMimeType(browserMimeType);
            }

            // Validate fullMimeType and separate it into its major and sub types.
            string majorType;
            string subType;
            ValidateMimeType(mimeTypeValue, out majorType, out subType);

            #endregion

            this._mimeTypeId        = mimeTypeId;
            this._mimeTypeGalleryId = mimeTypeGalleryId;
            this._galleryId         = galleryId;
            this._extension         = fileExtension;
            this._typeCategory      = MimeTypeEnumHelper.ParseMimeTypeCategory(majorType);
            this._majorType         = majorType;
            this._subtype           = subType;
            this._browserMimeType   = (String.IsNullOrEmpty(browserMimeType) ? mimeTypeValue : browserMimeType);
            this._allowAddToGallery = allowAddToGallery;
        }