當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpContextBase.GetClientCompression方法代碼示例

本文整理匯總了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);
            }
        }
開發者ID:ElijahGlover,項目名稱:ClientDependency,代碼行數:14,代碼來源:MimeTypeCompressor.cs

示例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;
        }
開發者ID:dufkaf,項目名稱:ClientDependency,代碼行數:85,代碼來源:CompositeDependencyHandler.cs

示例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;
        }
開發者ID:aozora,項目名稱:arashi,代碼行數:61,代碼來源:CompositeDependencyHandler.cs


注:本文中的System.Web.HttpContextBase.GetClientCompression方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。