Ejemplo n.º 1
0
        /// <summary>
        /// Processes the specified script.
        /// </summary>
        /// <param name="path">The script path.</param>
        /// <param name="context">The context.</param>
        public void Process(FilePath path, ScriptProcessorContext context)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // Already processed this script?
            if (context.HasScriptBeenProcessed(path.FullPath))
            {
                _log.Debug("Skipping {0} since it's already been processed.", path.GetFilename().FullPath);
                return;
            }

            // Add the script.
            context.MarkScriptAsProcessed(path.MakeAbsolute(_environment).FullPath);

            // Read the source.
            _log.Debug("Processing {0}...", path.GetFilename().FullPath);
            var lines = ReadSource(path);

            // Iterate all lines in the script.
            foreach (var line in lines)
            {
                if (!_lineProcessors.Any(p => p.Process(this, context, path, line)))
                {
                    context.AppendScriptLine(line);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the specified script.
        /// </summary>
        /// <param name="path">The script path.</param>
        /// <param name="context">The context.</param>
        public void Process(FilePath path, ScriptProcessorContext context)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // Already processed this script?
            if (context.HasScriptBeenProcessed(path.FullPath))
            {
                _log.Debug("Skipping {0} since it's already been processed.", path.GetFilename().FullPath);
                return;
            }

            // Add the script.
            context.MarkScriptAsProcessed(path.MakeAbsolute(_environment).FullPath);

            // Read the source.
            _log.Debug("Processing {0}...", path.GetFilename().FullPath);
            var lines = ReadSource(path);

            // Iterate all lines in the script.
            var firstLine = true;

            foreach (var line in lines)
            {
                if (!_lineProcessors.Any(p => p.Process(this, context, path, line)))
                {
                    if (firstLine)
                    {
                        // Append the line directive for the script.
                        var scriptFullPath = path.MakeAbsolute(_environment);
                        context.AppendScriptLine(string.Format(CultureInfo.InvariantCulture, "#line 1 \"{0}\"", scriptFullPath.FullPath));
                        firstLine = false;
                    }

                    context.AppendScriptLine(line);
                }
            }
        }