Beispiel #1
0
        public static string FirewallScript(string virtualPath, string source, bool compacted)
        {
            ScriptCompactionSection config = ScriptCompactionSection.GetSettings();

            if (!config.Firewall)
            {
                return(source);
            }

            if (compacted)
            {
                return(String.Concat(
                           ScriptResourceCodeProvider.TryStart,
                           source,
                           ScriptResourceCodeProvider.CatchCompact));
            }

            virtualPath = ResourceHandler.EnsureAppRelative(virtualPath);
            virtualPath = (virtualPath != null) ? virtualPath.Replace("\"", "\\\"") : "script";
            return(String.Concat(
                       Environment.NewLine,
                       ScriptResourceCodeProvider.TryStart,
                       Environment.NewLine,
                       source,
                       Environment.NewLine,
                       ScriptResourceCodeProvider.CatchStart,
                       virtualPath,
                       ScriptResourceCodeProvider.CatchEnd));
        }
Beispiel #2
0
        public static string Compact(string virtalPath, string source, List <ParseException> errors)
        {
            BuildErrorReporter errorReporter = null;

            if (errors != null)
            {
                errorReporter = new BuildErrorReporter(virtalPath, errors);
            }

            ScriptCompactionSection config = ScriptCompactionSection.GetSettings();

            StringBuilder builder = new StringBuilder(source.Length);

            try
            {
                JavaScriptCompressor compressor = new JavaScriptCompressor(
                    source,
                    config.Verbose,                                                             // verbose logging
                    Encoding.UTF8,
                    CultureInfo.InvariantCulture,
                    config.IgnoreEval,                                                          // ignore eval
                    errorReporter);

                string compacted = compressor.Compress(
                    config.Obfuscate,                                           // obfuscate
                    config.PreserveSemicolons,                                  // preserve unneccessary semicolons
                    config.DisableMicroOptimizations,                           // disable micro-optimizations
                    config.WordWrapWidth);                                      // word wrap width

                builder.Append(compacted);
            }
            catch (EcmaScriptRuntimeException ex)
            {
                if (errors.Count > 0 && String.IsNullOrEmpty(ex.SourceName))
                {
                    // EcmaScript.NET provides an extra error which is a summary count of other errors
                    errors.Add(new ParseWarning(ex.Message, virtalPath, ex.LineNumber, ex.ColumnNumber, ex));
                }
                else
                {
                    errors.Add(new ParseError(ex.Message, ex.SourceName, ex.LineNumber, ex.ColumnNumber, ex));
                }
            }
            catch (Exception ex)
            {
                errors.Add(new ParseError(ex.Message, virtalPath, -1, -1, ex));
            }

            return(builder.ToString());
        }