Exemple #1
0
        protected override void ProcessRequestCore(System.Web.HttpContext context)
        {
            HttpResponse response = context.Response;

            response.Clear();
            try
            {
                if (this.CheckAccessRight(context))
                {
                    MemoryStream mStream = null;
                    using (Stream stream = this.GetFileStream(context))
                    {
                        ThumbImageViewer.CopyStream(mStream, stream);
                    }
                    long startPosition = this.GetStartPosition(context);
                    this.AddHeader(context, mStream, startPosition);
                    this.ResponseStream(context, mStream, startPosition);
                }
            }
            finally
            {
                //response.End();
            }
        }
Exemple #2
0
        protected virtual void ThumbImage(HttpContext context)
        {
            string fileName = this.FileID;

            if (!string.IsNullOrEmpty(fileName))
            {
                int width  = 0;
                int height = 0;
                GetImageSize(out width, out height);
                Guid fileID = FileGuid;

                SetResponseContentType(context);
                SetResponseHeader(context);

                Stream imageStream = null;

                LogicFileInfoData fileInfo = FileManager.GetFileInfo(fileID);
                //先看缓存目录里有没有
                string thumbImageDirPath = context.Server.MapPath("~/ThumbImage");
                string thumbImagePath    = Path.Combine(thumbImageDirPath, string.Format("{0}_{1}_{2}{3}", FileGuid, width, height, fileInfo.LogicFileExt));
                if (!Directory.Exists(thumbImageDirPath))
                {
                    Directory.CreateDirectory(thumbImageDirPath);
                }
                if (File.Exists(thumbImagePath))
                {
                    try
                    {
                        imageStream = File.OpenRead(thumbImagePath);
                        OutputStream(context, imageStream);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (imageStream != null)
                        {
                            imageStream.Dispose();
                        }
                    }
                }
                else
                {
                    try
                    {
                        using (Stream stream = FileManager.OpenReadFile(fileID))
                        {
                            imageStream = new MemoryStream();
                            ThumbImageViewer.CopyStream(imageStream, stream);
                        }

                        if (width <= 0 || height <= 0)
                        {
                            OutputStream(context, imageStream);
                        }
                        else
                        {
                            using (MemoryStream bufferOutput = new MemoryStream())
                            {
                                ThumbImageViewer.OutputImage(bufferOutput, imageStream, this.ClientFileID, width, height, img =>
                                {
                                    //保存缩列图缓存
                                    if (img != null)
                                    {
                                        try
                                        {
                                            img.Save(thumbImagePath);
                                        }
                                        catch (Exception ex)
                                        {
                                            throw ex;
                                        }
                                    }
                                });
                                if (bufferOutput.Length > 0)
                                {
                                    bufferOutput.Position = 0;
                                    OutputStream(context, bufferOutput);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (imageStream != null)
                        {
                            imageStream.Dispose();
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void OutputStream(HttpContext context, Stream inStream)
        {
            HttpResponse response = context.Response;

            ThumbImageViewer.CopyStream(response.OutputStream, inStream);
        }