Exemple #1
0
        /// <summary>
        /// Initialize the class level variables with information from the query string. Returns false if the variables cannot
        /// be properly initialized.
        /// </summary>
        /// <param name="context">The HttpContext for the current request.</param>
        /// <returns>Returns true if all variables were initialized; returns false if there was a problem and one or more variables
        /// could not be set.</returns>
        private bool InitializeVariables(HttpContext context)
        {
            this._context = context;

            if (!ExtractQueryStringParms(context.Request.Url.Query))
            {
                return(false);
            }

            this._isUserAuthenticated = Util.IsAuthenticated;
            this._filename            = Path.GetFileName(this._filepath);

            if ((_albumId > 0) &&
                (!String.IsNullOrEmpty(_filepath)) &&
                (!String.IsNullOrEmpty(_filename)) &&
                (MimeTypeEnumHelper.IsValidMimeTypeCategory(this._mimeTypeCategory)) &&
                (DisplayObjectTypeEnumHelper.IsValidDisplayObjectType(this._displayType)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        private void ShowMediaObject()
        {
            if (this._filename == GlobalConstants.DefaultFileName)
            {
                // A filename matching the DefaultFilename constant is our signal to generate the
                // default album thumbnail and send to client.
                ProcessDefaultThumbnail();
            }
            else
            {
                if (!MimeTypeEnumHelper.IsValidMimeTypeCategory(this._mimeTypeCategory))
                {
                    throw new UnexpectedQueryStringException();
                }

                if ((this._mimeTypeCategory != MimeTypeCategory.Image) && (this._mediaObjectId > int.MinValue))
                {
                    // We never apply the watermark to non-image media objects.
                    ProcessMediaObject();
                }
                else
                {
                    // Apply watermark to thumbnails only when the config setting applyWatermarkToThumbnails = true.
                    // Apply watermark to optimized and original images only when applyWatermark = true.
                    bool applyWatermark             = Config.GetCore().ApplyWatermark;
                    bool applyWatermarkToThumbnails = Config.GetCore().ApplyWatermarkToThumbnails;
                    bool isThumbnail = (_displayType == DisplayObjectType.Thumbnail);

                    if (AppSetting.Instance.IsInReducedFunctionalityMode && !isThumbnail)
                    {
                        ProcessMediaObjectWithWatermark();
                    }

                    if ((applyWatermark && !isThumbnail) || (applyWatermark && applyWatermarkToThumbnails && isThumbnail))
                    {
                        // If the user belongs to a role with watermarks set to visible, then show it; otherwise don't show the watermark.
                        if (Util.IsUserAuthorized(SecurityActions.HideWatermark, RoleController.GetGalleryServerRolesForUser(), this._albumId, this._isPrivate))
                        {
                            // Show the image without the watermark.
                            ProcessMediaObject();
                        }
                        else
                        {
                            // Overlay watermark on image before sending it to client.
                            ProcessMediaObjectWithWatermark();
                        }
                    }
                    else
                    {
                        ProcessMediaObject();
                    }
                }
            }
        }
        /// <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;
        }
Exemple #4
0
        /// <summary>
        /// Extract information from the query string and assign to our class level variables. Return false if something goes wrong
        /// and the variables cannot be set. This will happen when the query string is in an unexpected format.
        /// </summary>
        /// <param name="queryString">The query string for the current request. Can be populated with HttpContext.Request.Url.Query.
        /// Must start with a question mark (?).</param>
        /// <returns>Returns true if all relevant variables were assigned from the query string; returns false if there was a problem.</returns>
        private bool ExtractQueryStringParms(string queryString)
        {
            if (String.IsNullOrEmpty(queryString))
            {
                return(false);
            }

            queryString = queryString.Remove(0, 1);             // Strip off the ?

            bool filepathIsEncrypted = Config.GetCore().EncryptMediaObjectUrlOnClient;

            if (filepathIsEncrypted)
            {
                // Decode, then decrypt the query string. Note that we must replace spaces with a '+'. This is required when the the URL is
                // used in javascript to create the Silverlight media player. Apparently, Silverlight or the media player javascript decodes
                // the query string when it requests the URL, so that means any instances of '%2b' are decoded into '+' before it gets here.
                // Ideally, we wouldn't even call UrlDecode in this case, but we don't have a way of knowing that it has already been decoded.
                // So we decode anyway, which doesn't cause any harm *except* it converts '+' to a space, so we need to convert them back.
                queryString = HelperFunctions.Decrypt(HttpUtility.UrlDecode(queryString).Replace(" ", "+"));
            }

            //moid={0}&aid={1}&mo={2}&mtc={3}&dt={4}&isp={5}
            foreach (string nameValuePair in queryString.Split(new char[] { '&' }))
            {
                string[] nameOrValue = nameValuePair.Split(new char[] { '=' });
                switch (nameOrValue[0])
                {
                case "moid":
                {
                    int moid;
                    if (Int32.TryParse(nameOrValue[1], out moid))
                    {
                        _mediaObjectId = moid;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "aid":
                {
                    int aid;
                    if (Int32.TryParse(nameOrValue[1], out aid))
                    {
                        _albumId = aid;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "mo": _filepath = Uri.UnescapeDataString(nameOrValue[1]); break;

                case "mtc":
                {
                    int mtcInt;
                    if (Int32.TryParse(nameOrValue[1], out mtcInt))
                    {
                        if (MimeTypeEnumHelper.IsValidMimeTypeCategory((MimeTypeCategory)mtcInt))
                        {
                            _mimeTypeCategory = (MimeTypeCategory)mtcInt; break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                case "dt":
                {
                    int dtInt;
                    if (Int32.TryParse(nameOrValue[1], out dtInt))
                    {
                        if (DisplayObjectTypeEnumHelper.IsValidDisplayObjectType((DisplayObjectType)dtInt))
                        {
                            _displayType = (DisplayObjectType)dtInt; break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                case "isp":
                {
                    bool isPrivate;

                    if (Boolean.TryParse(nameOrValue[1], out isPrivate))
                    {
                        _isPrivate = isPrivate;
                    }
                    else
                    {
                        _isPrivate = true;
                    }

                    break;
                }

                default: return(false);                        // Unexpected query string parm. Return false so execution is aborted.
                }
            }

            return(true);
        }