📄 gallerypictureshttphandler.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Web;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;
namespace CommunityServer.Galleries.HttpHandler
{
public class GalleryPicturesHttpHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
try
{
int galleryID = Galleries.GetGalleryID(CSContext.Current.ApplicationKey);
int pictureID = CSContext.Current.PostID;
string imageType = null;
int width = 0;
int height = 0;
DateTime modified = DateTime.Now;
// See if we had width/height settings
imageType = context.Request.QueryString["ImageType"];
if(context.Request.QueryString["Width"] != null)
width = int.Parse(context.Request.QueryString["Width"]);
if(context.Request.QueryString["Height"] != null)
height = int.Parse(context.Request.QueryString["Height"]);
// Clear the response buffer
context.Response.Clear();
if(imageType == "original")
{
// Show the original image
PostAttachment data = Pictures.GetPictureData(pictureID);
modified = data.DateCreated;
// Send the picture
context.Response.ContentType = data.ContentType + "; name=\"" + context.Server.UrlEncode(data.FileName) + "\"";
context.Response.AddHeader("Content-disposition", "inline; filename=\"" + context.Server.UrlEncode(data.FileName) + "\"");
context.Response.OutputStream.Write(data.Content, 0, data.Length);
}
else if(imageType != null)
{
string filename = "";
// Show a cached scaled image
if(imageType == "thumb")
filename = Picture.CacheFilename(galleryID, pictureID, GalleryImageType.Thumbnail, 0, 0);
else if(imageType == "secondarythumb")
filename = Picture.CacheFilename(galleryID, pictureID, GalleryImageType.SecondaryThumbnail, 0, 0);
modified = File.GetCreationTime(filename);
// Send the file
context.Response.ContentType = "image/jpeg";
context.Response.WriteFile(filename, true);
}
else
{
// Show a cached scaled image
string filename = Picture.CacheFilename(galleryID, pictureID, width, height);
modified = File.GetCreationTime(filename);
// Send the file
context.Response.ContentType = "image/jpeg";
context.Response.WriteFile(filename, true);
}
// Browser cache settings
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(modified);
context.Response.Cache.SetAllowResponseInBrowserHistory(true);
context.Response.Cache.SetValidUntilExpires(true);
context.Response.Cache.VaryByParams["PostID"] = true;
context.Response.Cache.VaryByParams["Width"] = true;
context.Response.Cache.VaryByParams["Height"] = true;
context.Response.Cache.VaryByParams["ImageType"] = true;
}
catch {}
}
public bool IsReusable { get { return false; } }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -