Exemple #1
0
        /// <summary>
        /// Called to perform the main body of work for the application after command line arguments have been parsed.
        /// </summary>
        /// <param name="commandLine">Command line arguments.</param>
        protected override void Run(Arguments commandLine)
        {
            Log.WriteInfo("Starting up.\nUTC time: {0}\nLocal time: {1}\nVersion: {2}", DateTime.UtcNow, DateTime.Now, Assembly.GetExecutingAssembly().GetName().Version);
            Log.WriteInfo("Input file: {0}", commandLine.InputPath);
            Log.WriteInfo("Output file: {0}", commandLine.OutputPath);

            CompressionSupport.CompressFile(commandLine.InputPath, commandLine.OutputPath);
        }
        public CompressionFilter(Stream filterStream, HttpApplication application, CompressionSupport compressionType)
        {
            if (filterStream == null)
                throw new ArgumentNullException("filterStream");

            if (application == null)
                throw new ArgumentNullException("application");

            this.filterStream = filterStream;
            this.Application = application;
            this.SupportedCompression = compressionType;
            this.compressionStream = new MemoryStream();
        }
 public static void AddCompressionHeaders(this HttpResponse response, CompressionSupport compressionSupport)
 {
     switch (compressionSupport)
     {
         case CompressionSupport.Deflate:
             response.AppendHeader(HttpExtensions.ResponseCompressionHeaderKey, HttpExtensions.DeflateIdentifier1);
             break;
         case CompressionSupport.GZip:
             response.AppendHeader(HttpExtensions.ResponseCompressionHeaderKey, HttpExtensions.GZipIdentifier1);
             break;
         default:
             break;
     }
 }
Exemple #4
0
        /// <summary>
        /// Loads the embedded fixups resource.
        /// </summary>
        private void LoadInternalFixups()
        {
            string resourceName = null;

            try
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (string name in assembly.GetManifestResourceNames())
                {
                    if (name.EndsWith("Fixups.xml.compressed", StringComparison.OrdinalIgnoreCase))
                    {
                        resourceName = name;
                        break;
                    }
                }

                if (resourceName == null)
                {
                    throw new Exception("Missing embedded resource 'Fixups.xml.compressed'.");
                }
            }
            catch (Exception ex)
            {
                Log.WriteError(ex.Message);
                Log.WriteError("Unable to locate embedded fixups.");
                return;
            }

            int installedCount = 0;

            try
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                using (Stream fixupsStream = assembly.GetManifestResourceStream(resourceName))
                    using (Stream decompressionStream = CompressionSupport.DecompressStream(fixupsStream))
                    {
                        LoadFixupsStream(ref installedCount, decompressionStream);
                    }

                Log.WriteInfo("Installed embedded fixups: {0}", installedCount);
            }
            catch (Exception ex)
            {
                Log.WriteError(ex.Message);
                Log.WriteError("Unable to load embedded fixups: {0}", resourceName);
                return;
            }
        }
        public static void AddCompressionHeaders(this HttpResponse response, CompressionSupport compressionSupport)
        {
            switch (compressionSupport)
            {
            case CompressionSupport.Deflate:
                response.AppendHeader(HttpExtensions.ResponseCompressionHeaderKey, HttpExtensions.DeflateIdentifier1);
                break;

            case CompressionSupport.GZip:
                response.AppendHeader(HttpExtensions.ResponseCompressionHeaderKey, HttpExtensions.GZipIdentifier1);
                break;

            default:
                break;
            }
        }
Exemple #6
0
        public CompressionFilter(Stream filterStream, HttpApplication application, CompressionSupport compressionType)
        {
            if (filterStream == null)
            {
                throw new ArgumentNullException("filterStream");
            }

            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            this.filterStream         = filterStream;
            this.Application          = application;
            this.SupportedCompression = compressionType;
            this.compressionStream    = new MemoryStream();
        }
        public static void SendHttpResponse(HttpContext context, string contentToSend)
        {
            CompressionSupport compressionSupport = context.GetCompressionSupport();
            string             acceptEncoding     = context.Request.Headers["Accept-Encoding"];

            if (compressionSupport != CompressionSupport.None)
            {
                if (context.Response.Headers.AllKeys.FirstOrDefault(key => key.Equals(HttpExtensions.ResponseCompressionHeaderKey)) == null)
                {
                    context.AddCompressionHeaders(compressionSupport);
                }

                System.IO.MemoryStream stream = null;
                using (stream = new System.IO.MemoryStream())
                {
                    byte[] content = System.Text.Encoding.UTF8.GetBytes(contentToSend);
                    if (compressionSupport == CompressionSupport.Deflate)
                    {
                        using (System.IO.Compression.DeflateStream zip = new System.IO.Compression.DeflateStream(stream, System.IO.Compression.CompressionMode.Compress, false))
                        {
                            zip.Write(content, 0, content.Length);
                        }
                    }
                    else if (compressionSupport == CompressionSupport.GZip)
                    {
                        using (System.IO.Compression.GZipStream zip = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Compress, false))
                        {
                            zip.Write(content, 0, content.Length);
                        }
                    }
                }
                context.Response.BinaryWrite(stream.ToByteArray());
            }
            else
            {
                context.Response.Write(contentToSend);
            }
            context.Response.Flush();
        }
        public static void AddCompressionHeaders(this HttpContext context)
        {
            CompressionSupport compressionSupport = context.GetCompressionSupport();

            context.AddCompressionHeaders(compressionSupport);
        }
        public static void AddCompressionHeaders(this HttpResponse response)
        {
            CompressionSupport compressionSupport = response.GetCompressionSupport();

            response.AddCompressionHeaders(compressionSupport);
        }
 public static void AddCompressionHeaders(this HttpContext context, CompressionSupport compressionSupport)
 {
     context.Response.AddCompressionHeaders(compressionSupport);
 }
 public CompressionFilter(HttpContext context, CompressionSupport compressionType)
     : this(context.Response.Filter, context.ApplicationInstance, compressionType)
 {
 }
Exemple #12
0
 public CompressionFilter(HttpContext context, CompressionSupport compressionType)
     : this(context.Response.Filter, context.ApplicationInstance, compressionType)
 {
 }
 public static void AddCompressionHeaders(this HttpContext context, CompressionSupport compressionSupport)
 {
     context.Response.AddCompressionHeaders(compressionSupport);
 }