本文整理汇总了C#中System.Web.HttpContextBase.GetClientCompression方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.GetClientCompression方法的具体用法?C# HttpContextBase.GetClientCompression怎么用?C# HttpContextBase.GetClientCompression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContextBase
的用法示例。
在下文中一共展示了HttpContextBase.GetClientCompression方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformCompression
internal static void PerformCompression(HttpContextBase context)
{
var cType = context.GetClientCompression();
context.AddCompressionResponseHeader(cType);
if (cType == CompressionType.deflate)
{
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
}
else if (cType == CompressionType.gzip)
{
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
}
}
示例2: ProcessRequestInternal
internal byte[] ProcessRequestInternal(HttpContextBase context, string fileset, ClientDependencyType type, int version, byte[] outputBytes, OutputCachedPage page)
{
//get the compression type supported
var clientCompression = context.GetClientCompression();
var x1 = ClientDependencySettings.Instance;
if (x1 == null) throw new Exception("x1");
var x2 = x1.DefaultFileMapProvider;
if (x2 == null) throw new Exception("x2");
//get the map to the composite file for this file set, if it exists.
var map = ClientDependencySettings.Instance.DefaultFileMapProvider.GetCompositeFile(fileset, version, clientCompression.ToString());
string compositeFileName = "";
if (map != null && map.HasFileBytes)
{
ProcessFromFile(context, map, out compositeFileName, out outputBytes);
}
else
{
lock (Lock)
{
//check again...
if (map != null && map.HasFileBytes)
{
//there's files there now, so process them
ProcessFromFile(context, map, out compositeFileName, out outputBytes);
}
else
{
List<CompositeFileDefinition> fileDefinitions;
byte[] fileBytes;
if (ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.UrlType == CompositeUrlType.MappedId)
{
//need to try to find the map by it's id/version (not compression)
var filePaths = ClientDependencySettings.Instance.DefaultFileMapProvider.GetDependentFiles(fileset, version);
if (filePaths == null)
{
throw new KeyNotFoundException("no map was found for the dependency key: " + fileset +
" ,CompositeUrlType.MappedId requires that a map is found");
}
//combine files and get the definition types of them (internal vs external resources)
fileBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider
.CombineFiles(filePaths.ToArray(), context, type, out fileDefinitions);
}
else
{
//need to do the combining, etc... and save the file map
fileBytes = GetCombinedFiles(context, fileset, type, out fileDefinitions);
}
//compress data
outputBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.CompressBytes(clientCompression, fileBytes);
context.AddCompressionResponseHeader(clientCompression);
//save combined file
var compositeFile = ClientDependencySettings.Instance
.DefaultCompositeFileProcessingProvider
.SaveCompositeFile(outputBytes, type, context.Server);
if (compositeFile != null)
{
compositeFileName = compositeFile.FullName;
if (!string.IsNullOrEmpty(compositeFileName))
{
//Update the XML file map
ClientDependencySettings.Instance.DefaultFileMapProvider.CreateUpdateMap(fileset, clientCompression.ToString(),
fileDefinitions.Select(x => new BasicFile(type) { FilePath = x.Uri }),
compositeFileName,
//TODO: We should probably use the passed in version param?
ClientDependencySettings.Instance.Version);
}
}
}
}
}
//set our caching params
SetCaching(context, compositeFileName, fileset, clientCompression, page);
return outputBytes;
}
示例3: ProcessRequestInternal
internal byte[] ProcessRequestInternal(HttpContextBase context, string fileset, ClientDependencyType type, int version, byte[] outputBytes)
{
//get the compression type supported
CompressionType cType = context.GetClientCompression();
//get the map to the composite file for this file set, if it exists.
CompositeFileMap map = CompositeFileXmlMapper.Instance.GetCompositeFile(fileset, version, cType.ToString());
string compositeFileName = "";
if (map != null && map.HasFileBytes)
{
ProcessFromFile(context, map, out compositeFileName, out outputBytes);
}
else
{
bool fromFile = false;
lock (m_Lock)
{
//check again...
if (map == null || !map.HasFileBytes)
{
//need to do the combining, etc... and save the file map
List<CompositeFileDefinition> fDefs;
byte[] fileBytes = GetCombinedFiles(context, fileset, type, out fDefs);
//compress data
outputBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.CompressBytes(cType, fileBytes);
context.AddCompressionResponseHeader(cType);
//save combined file
FileInfo compositeFile = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.SaveCompositeFile(outputBytes, type, context.Server);
if (compositeFile != null)
{
compositeFileName = compositeFile.FullName;
if (!string.IsNullOrEmpty(compositeFileName))
{
//Update the XML file map
CompositeFileXmlMapper.Instance.CreateMap(fileset, cType.ToString(),
fDefs
.Where(f => f.IsLocalFile)
.Select(x => new FileInfo(context.Server.MapPath(x.Uri))).ToList(), compositeFileName,
ClientDependencySettings.Instance.Version);
}
}
}
else
{
//files are there now, process from file.
fromFile = true;
}
}
if (fromFile)
{
ProcessFromFile(context, map, out compositeFileName, out outputBytes);
}
}
SetCaching(context, compositeFileName);
return outputBytes;
}