示例#1
0
        /// <summary>
        /// Minify XML content
        /// </summary>
        /// <param name="content">XML content</param>
        /// <param name="fileContext">File context</param>
        /// <param name="encoding">Text encoding</param>
        /// <param name="generateStatistics">Flag for whether to allow generate minification statistics</param>
        /// <returns>Minification result</returns>
        public MarkupMinificationResult Minify(string content, string fileContext, Encoding encoding,
			bool generateStatistics)
        {
            MinificationStatistics statistics = null;
            string minifiedContent = string.Empty;
            var errors = new List<MinificationErrorInfo>();

            lock (_minificationSynchronizer)
            {
                try
                {
                    if (generateStatistics)
                    {
                        statistics = new MinificationStatistics(encoding);
                        statistics.Init(content);
                    }

                    _result = new StringBuilder(content.Length);
                    _buffer = new List<string>();
                    _errors = new List<MinificationErrorInfo>();
                    _currentNodeType = XmlNodeType.Unknown;
                    _currentText = string.Empty;

                    _xmlParser.Parse(content);

                    FlushBuffer();

                    if (_errors.Count == 0)
                    {
                        minifiedContent = _result.ToString();

                        if (generateStatistics)
                        {
                            statistics.End(minifiedContent);
                        }
                    }
                }
                catch (XmlParsingException e)
                {
                    WriteError(LogCategoryConstants.XmlParsingError, e.Message, fileContext,
                        e.LineNumber, e.ColumnNumber, e.SourceFragment);
                }
                finally
                {
                    _result.Clear();
                    _buffer.Clear();
                }

                if (_errors.Count == 0)
                {
                    _logger.Info(LogCategoryConstants.XmlMinificationSuccess,
                        string.Format(Strings.SuccesMessage_MarkupMinificationComplete, "XML"),
                        fileContext, statistics);
                }

                errors.AddRange(_errors);
                _errors.Clear();
            }

            return new MarkupMinificationResult(minifiedContent, errors, statistics);
        }
示例#2
0
 /// <summary>
 /// Constructs instance of markup minification result
 /// </summary>
 /// <param name="minifiedContent">Minified content</param>
 /// <param name="errors">List of the errors</param>
 /// <param name="warnings">List of the warnings</param>
 /// <param name="statistics">Minification statistics</param>
 public MarkupMinificationResult(string minifiedContent, IList <MinificationErrorInfo> errors, IList <MinificationErrorInfo> warnings,
                                 MinificationStatistics statistics)
     : base(minifiedContent, errors, warnings)
 {
     Statistics = statistics;
 }
示例#3
0
        /// <summary>
        /// Minify XML content
        /// </summary>
        /// <param name="content">XML content</param>
        /// <param name="fileContext">File context</param>
        /// <param name="encoding">Text encoding</param>
        /// <param name="generateStatistics">Flag for whether to allow generate minification statistics</param>
        /// <returns>Minification result</returns>
        public MarkupMinificationResult Minify(string content, string fileContext, Encoding encoding,
                                               bool generateStatistics)
        {
            MinificationStatistics statistics = null;
            string        cleanedContent      = Utils.RemoveByteOrderMark(content);
            string        minifiedContent     = string.Empty;
            var           stringBuilderPool   = StringBuilderPool.Shared;
            StringBuilder sb = null;
            XmlMinificationOutputWriter output = _output;
            var errors = new List <MinificationErrorInfo>();

            lock (_minificationSynchronizer)
            {
                try
                {
                    if (generateStatistics)
                    {
                        statistics = new MinificationStatistics(encoding);
                        statistics.Init(cleanedContent);
                    }

                    sb = stringBuilderPool.Rent(cleanedContent.Length);
                    output.StringBuilder = sb;

                    _xmlParser.Parse(cleanedContent);

                    output.Flush();

                    if (_errors.Count == 0)
                    {
                        minifiedContent = output.ToString();

                        if (generateStatistics)
                        {
                            statistics.End(minifiedContent);
                        }
                    }
                }
                catch (MarkupParsingException e)
                {
                    WriteError(LogCategoryConstants.XmlParsingError, e.Message, fileContext,
                               e.LineNumber, e.ColumnNumber, e.SourceFragment);
                }
                finally
                {
                    output.Clear();
                    output.StringBuilder = null;
                    stringBuilderPool.Return(sb);
                    _currentNodeType = XmlNodeType.Unknown;
                    _currentText     = string.Empty;

                    errors.AddRange(_errors);
                    _errors.Clear();
                }

                if (errors.Count == 0)
                {
                    _logger.Info(LogCategoryConstants.XmlMinificationSuccess,
                                 string.Format(Strings.SuccesMessage_MarkupMinificationComplete, "XML"),
                                 fileContext, statistics);
                }
            }

            return(new MarkupMinificationResult(minifiedContent, errors, statistics));
        }
示例#4
0
 /// <summary>
 /// Constructs instance of markup minification result
 /// </summary>
 /// <param name="minifiedContent">Minified content</param>
 /// <param name="errors">List of the errors</param>
 /// <param name="statistics">Minification statistics</param>
 public MarkupMinificationResult(string minifiedContent, IList <MinificationErrorInfo> errors, MinificationStatistics statistics)
     : this(minifiedContent, errors, new List <MinificationErrorInfo>(), statistics)
 {
 }
示例#5
0
        /// <summary>
        /// Minify XML content
        /// </summary>
        /// <param name="content">XML content</param>
        /// <param name="fileContext">File context</param>
        /// <param name="encoding">Text encoding</param>
        /// <param name="generateStatistics">Flag for whether to allow generate minification statistics</param>
        /// <returns>Minification result</returns>
        public MarkupMinificationResult Minify(string content, string fileContext, Encoding encoding,
                                               bool generateStatistics)
        {
            MinificationStatistics statistics = null;
            string cleanedContent             = Utils.RemoveByteOrderMark(content);
            string minifiedContent            = string.Empty;
            var    errors = new List <MinificationErrorInfo>();

            lock (_minificationSynchronizer)
            {
                try
                {
                    if (generateStatistics)
                    {
                        statistics = new MinificationStatistics(encoding);
                        statistics.Init(cleanedContent);
                    }

                    int estimatedCapacity = (int)Math.Floor(cleanedContent.Length * AVERAGE_COMPRESSION_RATIO);
                    _result = StringBuilderPool.GetBuilder(estimatedCapacity);

                    _xmlParser.Parse(cleanedContent);

                    FlushBuffer();

                    if (_errors.Count == 0)
                    {
                        minifiedContent = _result.ToString();

                        if (generateStatistics)
                        {
                            statistics.End(minifiedContent);
                        }
                    }
                }
                catch (XmlParsingException e)
                {
                    WriteError(LogCategoryConstants.XmlParsingError, e.Message, fileContext,
                               e.LineNumber, e.ColumnNumber, e.SourceFragment);
                }
                finally
                {
                    StringBuilderPool.ReleaseBuilder(_result);
                    _buffer.Clear();
                    _currentNodeType = XmlNodeType.Unknown;
                    _currentText     = string.Empty;

                    errors.AddRange(_errors);
                    _errors.Clear();
                }

                if (errors.Count == 0)
                {
                    _logger.Info(LogCategoryConstants.XmlMinificationSuccess,
                                 string.Format(Strings.SuccesMessage_MarkupMinificationComplete, "XML"),
                                 fileContext, statistics);
                }
            }

            return(new MarkupMinificationResult(minifiedContent, errors, statistics));
        }
示例#6
0
        /// <summary>
        /// Minify XML content
        /// </summary>
        /// <param name="content">XML content</param>
        /// <param name="fileContext">File context</param>
        /// <param name="encoding">Text encoding</param>
        /// <param name="generateStatistics">Flag for whether to allow generate minification statistics</param>
        /// <returns>Minification result</returns>
        public MarkupMinificationResult Minify(string content, string fileContext, Encoding encoding,
			bool generateStatistics)
        {
            MinificationStatistics statistics = null;
            string cleanedContent = Utils.RemoveByteOrderMark(content);
            string minifiedContent = string.Empty;
            var errors = new List<MinificationErrorInfo>();

            lock (_minificationSynchronizer)
            {
                try
                {
                    if (generateStatistics)
                    {
                        statistics = new MinificationStatistics(encoding);
                        statistics.Init(cleanedContent);
                    }

                    int estimatedCapacity = (int)Math.Floor(cleanedContent.Length * AVERAGE_COMPRESSION_RATIO);
                    _result = StringBuilderPool.GetBuilder(estimatedCapacity);

                    _xmlParser.Parse(cleanedContent);

                    FlushBuffer();

                    if (_errors.Count == 0)
                    {
                        minifiedContent = _result.ToString();

                        if (generateStatistics)
                        {
                            statistics.End(minifiedContent);
                        }
                    }
                }
                catch (MarkupParsingException e)
                {
                    WriteError(LogCategoryConstants.XmlParsingError, e.Message, fileContext,
                        e.LineNumber, e.ColumnNumber, e.SourceFragment);
                }
                finally
                {
                    StringBuilderPool.ReleaseBuilder(_result);
                    _buffer.Clear();
                    _currentNodeType = XmlNodeType.Unknown;
                    _currentText = string.Empty;

                    errors.AddRange(_errors);
                    _errors.Clear();
                }

                if (errors.Count == 0)
                {
                    _logger.Info(LogCategoryConstants.XmlMinificationSuccess,
                        string.Format(Strings.SuccesMessage_MarkupMinificationComplete, "XML"),
                        fileContext, statistics);
                }
            }

            return new MarkupMinificationResult(minifiedContent, errors, statistics);
        }
		/// <summary>
		/// Constructs instance of markup minification result
		/// </summary>
		/// <param name="minifiedContent">Minified content</param>
		/// <param name="errors">List of the errors</param>
		/// <param name="warnings">List of the warnings</param>
		/// <param name="statistics">Minification statistics</param>
		public MarkupMinificationResult(string minifiedContent, IList<MinificationErrorInfo> errors, IList<MinificationErrorInfo> warnings,
			MinificationStatistics statistics)
			: base(minifiedContent, errors, warnings)
		{
			Statistics = statistics;
		}
		/// <summary>
		/// Constructs instance of markup minification result
		/// </summary>
		/// <param name="minifiedContent">Minified content</param>
		/// <param name="errors">List of the errors</param>
		/// <param name="statistics">Minification statistics</param>
		public MarkupMinificationResult(string minifiedContent, IList<MinificationErrorInfo> errors, MinificationStatistics statistics)
			: this(minifiedContent, errors, new List<MinificationErrorInfo>(), statistics)
		{ }