Beispiel #1
0
        private void ProcessMediaObjectWithWatermark()
        {
            // Send the specified file to the client with the watermark overlayed on top.
            IMimeType mimeType = MimeType.LoadInstanceByFilePath(this._filename);

            this._context.Response.Clear();
            this._context.Response.ContentType = mimeType.FullType;

            Image watermarkedImage = null;

            try
            {
                try
                {
                    watermarkedImage = ImageHelper.AddWatermark(this._filepath);
                }
                catch (Exception ex)
                {
                    // Can't apply watermark to image. Substitute an error image and send that to the user.
                    AppErrorController.LogError(ex);
                    watermarkedImage = Image.FromFile(this._context.Request.MapPath(String.Concat(Util.GalleryRoot, "/images/error_48x48.png")));
                }

                watermarkedImage.Save(this._context.Response.OutputStream, ImageFormat.Jpeg);
            }
            finally
            {
                if (watermarkedImage != null)
                {
                    watermarkedImage.Dispose();
                }
            }
        }
Beispiel #2
0
        private void ProcessMediaObject()
        {
            // Send the specified file to the client.
            try
            {
                IMimeType mimeType = MimeType.LoadInstanceByFilePath(this._filename);

                this._context.Response.Clear();
                this._context.Response.ContentType = mimeType.FullType;
                this._context.Response.Buffer      = false;

                HttpCachePolicy cachePolicy = this._context.Response.Cache;
                cachePolicy.SetExpires(DateTime.Now.AddSeconds(2592000));                 // 30 days
                cachePolicy.SetCacheability(HttpCacheability.Public);
                cachePolicy.SetValidUntilExpires(true);

                FileStream fileStream = null;
                try
                {
                    int    bufferSize = Config.GetCore().MediaObjectDownloadBufferSize;
                    byte[] buffer     = new byte[bufferSize];
                    fileStream = File.OpenRead(this._filepath);

                    // Required for Silverlight to properly work
                    this._context.Response.AddHeader("Content-Length", fileStream.Length.ToString());

                    int byteCount;
                    while ((byteCount = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        if (this._context.Response.IsClientConnected)
                        {
                            this._context.Response.OutputStream.Write(buffer, 0, byteCount);
                            this._context.Response.Flush();
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                AppErrorController.LogError(ex);
            }
        }
Beispiel #3
0
        private void SaveSettings()
        {
            bool previousAllowAllValue = CoreConfig.allowUnspecifiedMimeTypes;

            this.wwDataBinder.Unbind(this);

            if (CoreConfig.allowUnspecifiedMimeTypes != previousAllowAllValue)
            {
                GspConfigController.SaveCore(this.CoreConfig);
            }

            if (wwDataBinder.BindingErrors.Count > 0)
            {
                this.wwMessage.CssClass = "wwErrorFailure gsp_msgwarning";
                this.wwMessage.Text     = wwDataBinder.BindingErrors.ToHtml();
                return;
            }

            // Loop through each record in the grid. For each file extension, find the matching MIME types from the
            // configuration file. If the value has changed, update it. When done looping, save config file.
            Dictionary <string, bool> mimeTypesToUpdate = new Dictionary <string, bool>();

            foreach (GridItem row in gdMimeTypes.Items)
            {
                object[] rowValues = (object[])row.DataItem;
                bool     enabled   = Convert.ToBoolean(rowValues[0], CultureInfo.InvariantCulture);
                string   fileExt   = rowValues[1].ToString();

                IMimeType mimeType = MimeType.LoadInstanceByFilePath(fileExt);
                if (mimeType.AllowAddToGallery != enabled)
                {
                    mimeTypesToUpdate.Add(mimeType.Extension, enabled);
                }
            }

            if (mimeTypesToUpdate.Count > 0)
            {
                GspConfigController.SaveMimeTypes(mimeTypesToUpdate);
            }

            this.wwMessage.CssClass = "wwErrorSuccess gsp_msgfriendly gsp_bold";
            this.wwMessage.ShowMessage(Resources.GalleryServerPro.Admin_Save_Success_Text);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a deep copy of this instance.
        /// </summary>
        /// <returns>Returns a deep copy of this instance.</returns>
        public IMimeType Copy()
        {
            IMimeType copy = new MimeType(this.MimeTypeId, this.MimeTypeGalleryId, this.GalleryId, this.Extension, this.FullType, this.BrowserMimeType, this.AllowAddToGallery);

            if (this.BrowserTemplates.Count > 0)
            {
                copy.BrowserTemplates.AddRange(this.BrowserTemplates.Copy());
            }

            return copy;
        }