本文整理汇总了C#中CompressionType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# CompressionType.ToString方法的具体用法?C# CompressionType.ToString怎么用?C# CompressionType.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompressionType
的用法示例。
在下文中一共展示了CompressionType.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCompressor
public ICompressor CreateCompressor(CompressionType compressionType)
{
Lazy<ICompressor> compressor;
if(s_Dictionary.TryGetValue(compressionType.ToString(), out compressor))
{
return compressor.Value;
}
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unknown Compressor Type: '{0}'", compressionType.ToString()));
}
示例2: SetCaching
/// <summary>
/// Sets the output cache parameters and also the client side caching parameters
/// </summary>
/// <param name="context"></param>
/// <param name="fileName">The name of the file that has been saved to disk</param>
/// <param name="fileset">The Base64 encoded string supplied in the query string for the handler</param>
/// <param name="compressionType"></param>
/// <param name="page">The outputcache page - ensures server side output cache is stored</param>
private void SetCaching(HttpContextBase context, string fileName, string fileset, CompressionType compressionType, OutputCachedPage page)
{
//this initializes the webforms page part to get outputcaching working server side
page.ProcessRequest(HttpContext.Current);
// in any case, cache already varies by pathInfo (build-in) so for path formats, we do not need anything
// just add params for querystring format, just in case...
context.SetClientCachingResponse(
//the e-tag to use
(fileset + compressionType.ToString()).GenerateHash(),
//10 days
10,
//vary-by params
new[] { "t", "s", "cdv" });
//make this output cache dependent on the file if there is one.
if (!string.IsNullOrEmpty(fileName))
context.Response.AddFileDependency(fileName);
}
示例3: Compress
/// <summary>
/// Compresses the data using the specified compression type
/// </summary>
/// <param name="Data">Data to compress</param>
/// <param name="CompressionType">Compression type</param>
/// <returns>The compressed data</returns>
public static byte[] Compress(this byte[] Data, CompressionType CompressionType = CompressionType.Deflate)
{
return IoC.Manager.Bootstrapper.Resolve<Manager>().Compress(Data, CompressionType.ToString());
}
示例4: SetCaching
/// <summary>
/// Sets the output cache parameters and also the client side caching parameters
/// </summary>
/// <param name="context"></param>
/// <param name="fileName">The name of the file that has been saved to disk</param>
/// <param name="fileset">The Base64 encoded string supplied in the query string for the handler</param>
/// <param name="compressionType"></param>
private void SetCaching(HttpContextBase context, string fileName, string fileset, CompressionType compressionType)
{
if (string.IsNullOrEmpty(fileName))
{
ClientDependencySettings.Instance.Logger.Error("ClientDependency handler path is null", new Exception());
return;
}
//This ensures OutputCaching is set for this handler and also controls
//client side caching on the browser side. Default is 10 days.
var duration = TimeSpan.FromDays(10);
var cache = context.Response.Cache;
cache.SetCacheability(HttpCacheability.Public);
cache.SetExpires(DateTime.Now.Add(duration));
cache.SetMaxAge(duration);
cache.SetValidUntilExpires(true);
cache.SetLastModified(DateTime.Now);
cache.SetETag("\"" + FormsAuthentication.HashPasswordForStoringInConfigFile(fileset + compressionType.ToString(), "MD5") + "\"");
//set server OutputCache to vary by our params
/* // proper way to do it is to have
* cache.SetVaryByCustom("cdparms");
*
* // then have this in global.asax
* public override string GetVaryByCustomString(HttpContext context, string arg)
* {
* if (arg == "cdparms")
* {
* if (string.IsNullOrEmpty(context.Request.PathInfo))
* {
* // querystring format
* return context.Request["s"] + "+" + context.Request["t"] + "+" + (context.Request["v"] ?? "0");
* }
* else
* {
* // path format
* return context.Request.PathInfo.Replace('/', '');
* }
* }
* }
*
* // that way, there would be one cache entry for both querystring and path formats.
* // but, it requires a global.asax and I can't find a way to do without it.
*/
// in any case, cache already varies by pathInfo (build-in) so for path formats, we do not need anything
// just add params for querystring format, just in case...
cache.VaryByParams["t"] = true;
cache.VaryByParams["s"] = true;
cache.VaryByParams["cdv"] = true;
//ensure the cache is different based on the encoding specified per browser
cache.VaryByContentEncodings["gzip"] = true;
cache.VaryByContentEncodings["deflate"] = true;
//don't allow varying by wildcard
cache.SetOmitVaryStar(true);
//ensure client browser maintains strict caching rules
cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
//This is the only way to set the max-age cachability header in ASP.Net!
//FieldInfo maxAgeField = cache.GetType().GetField("_maxAge", BindingFlags.Instance | BindingFlags.NonPublic);
//maxAgeField.SetValue(cache, duration);
//make this output cache dependent on the file if there is one.
if (!string.IsNullOrEmpty(fileName))
context.Response.AddFileDependency(fileName);
}
示例5: GetCurrentCompositeFolder
/// <summary>
/// Returns the cache folder for composite files for the current compression supported
/// </summary>
/// <returns></returns>
public string GetCurrentCompositeFolder(CompressionType type)
{
return Path.Combine(CurrentCacheFolder, type.ToString());
}