Esempio n. 1
0
        private void btnCompress_Click(object sender, System.EventArgs e)
        {
            DateTime dtStartTime;
            TimeSpan tsElapsed;
            long lOriginalSize, lCompressedSize, lBytesSaved;

            // Compress the script
            JSCompressor jsc = new JSCompressor(chkRemoveLFs.Checked,
                chkCompressVariables.Checked);

            // If checked only test variable name compression.  The script
            // itself will not be compressed with the exception of comment
            // removal.
            if(chkVarCompTest.Checked)
                jsc.TestVariableNameCompression = true;

            dtStartTime = DateTime.Now;
            this.txtCompressed.Text = jsc.Compress(this.txtScript.Text);
            tsElapsed = DateTime.Now - dtStartTime;

            // Display stats
            lOriginalSize = txtScript.Text.Length;
            lCompressedSize = txtCompressed.Text.Length;
            lBytesSaved = lOriginalSize - lCompressedSize;

            this.lblElapsedTime.Text = String.Format("{0:F2}", tsElapsed.TotalSeconds);
            this.lblOriginalSize.Text = lOriginalSize.ToString();
            this.lblCompressedSize.Text = lCompressedSize.ToString();
            this.lblBytesSaved.Text = lBytesSaved.ToString();
            this.lblPercentSaved.Text = String.Format("{0:P}",
                (lBytesSaved < 1) ? 0.0 : (double)lBytesSaved / (double)lOriginalSize);
        }