예제 #1
0
        /// <summary>
        /// Process a parsed converter pattern
        /// </summary>
        /// <param name="converterName">the name of the converter</param>
        /// <param name="option">the optional option for the converter</param>
        /// <param name="formattingInfo">the formatting info for the converter</param>
        private void ProcessConverter(string converterName, string option, FormattingInfo formattingInfo)
        {
            LogLog.Debug(declaringType, "Converter [" + converterName + "] Option [" + option + "] Format [min=" + formattingInfo.Min + ",max=" + formattingInfo.Max + ",leftAlign=" + formattingInfo.LeftAlign.ToString() + "]");
            ConverterInfo converterInfo = (ConverterInfo)m_patternConverters[converterName];

            if (converterInfo == null)
            {
                LogLog.Error(declaringType, "Unknown converter name [" + converterName + "] in conversion pattern.");
                return;
            }
            PatternConverter patternConverter = null;

            try
            {
                patternConverter = (PatternConverter)Activator.CreateInstance(converterInfo.Type);
            }
            catch (Exception ex)
            {
                LogLog.Error(declaringType, "Failed to create instance of Type [" + converterInfo.Type.FullName + "] using default constructor. Exception: " + ex.ToString());
            }
            patternConverter.FormattingInfo = formattingInfo;
            patternConverter.Option         = option;
            patternConverter.Properties     = converterInfo.Properties;
            (patternConverter as IOptionHandler)?.ActivateOptions();
            AddConverter(patternConverter);
        }
예제 #2
0
 /// <summary>
 /// Resets the internal state of the parser and adds the specified pattern converter
 /// to the chain.
 /// </summary>
 /// <param name="pc">The pattern converter to add.</param>
 private void AddConverter(PatternConverter pc)
 {
     if (m_head == null)
     {
         m_head = (m_tail = pc);
     }
     else
     {
         m_tail = m_tail.SetNext(pc);
     }
 }
예제 #3
0
 private void AddConverter(PatternConverter pc)
 {
     if (this.m_head != null)
     {
         this.m_tail = this.m_tail.SetNext(pc);
     }
     else
     {
         this.m_head = this.m_tail = pc;
     }
 }
예제 #4
0
 public void Format(TextWriter writer)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     for (PatternConverter converter = this.m_head; converter != null; converter = converter.Next)
     {
         converter.Format(writer, null);
     }
 }
		/// <summary>
		/// Set the next converter in the chain
		/// </summary>
		/// <param name="pc">The next pattern converter in the chain</param>
		/// <returns>The next pattern converter</returns>
		/// <remarks>
		/// <para>
		/// Special case the building of the pattern converter chain
		/// for <see cref="LiteralPatternConverter"/> instances. Two adjacent
		/// literals in the pattern can be represented by a single combined
		/// pattern converter. This implementation detects when a 
		/// <see cref="LiteralPatternConverter"/> is added to the chain
		/// after this converter and combines its value with this converter's
		/// literal value.
		/// </para>
		/// </remarks>
		public override PatternConverter SetNext(PatternConverter pc)
		{
			LiteralPatternConverter literalPc = pc as LiteralPatternConverter;
			if (literalPc != null)
			{
				// Combine the two adjacent literals together
				Option = Option + literalPc.Option;

				// We are the next converter now
				return this;
			}

			return base.SetNext(pc);
		}
예제 #6
0
        /// <summary>
        /// Produces a formatted string as specified by the conversion pattern.
        /// </summary>
        /// <param name="writer">The TextWriter to write the formatted event to</param>
        /// <remarks>
        /// <para>
        /// Format the pattern to the <paramref name="writer"/>.
        /// </para>
        /// </remarks>
        public void Format(TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            PatternConverter c = m_head;

            // loop through the chain of pattern converters
            while (c != null)
            {
                c.Format(writer, null);
                c = c.Next;
            }
        }
예제 #7
0
        /// <summary>
        /// Resets the internal state of the parser and adds the specified pattern converter
        /// to the chain.
        /// </summary>
        /// <param name="pc">The pattern converter to add.</param>
        void AddConverter(PatternConverter pc)
        {
            // Add the pattern converter to the list.

            if (m_head == null)
            {
                m_head = m_tail = pc;
            }
            else // Set the next converter on the tail
                 // Update the tail reference
                 // note that a converter may combine the 'next' into itself
                 // and therefore the tail would not change!
            {
                m_tail = m_tail.SetNext(pc);
            }
        }
예제 #8
0
        private void ProcessConverter(string converterName, string option, FormattingInfo formattingInfo)
        {
            object[] objArray1 = new object[11];
            objArray1[0]  = "Converter [";
            objArray1[1]  = converterName;
            objArray1[2]  = "] Option [";
            objArray1[3]  = option;
            objArray1[4]  = "] Format [min=";
            objArray1[5]  = formattingInfo.Min;
            objArray1[6]  = ",max=";
            objArray1[7]  = formattingInfo.Max;
            objArray1[8]  = ",leftAlign=";
            objArray1[9]  = formattingInfo.LeftAlign;
            objArray1[10] = "]";
            LogLog.Debug(declaringType, string.Concat(objArray1));
            ConverterInfo info = (ConverterInfo)this.m_patternConverters[converterName];

            if (info == null)
            {
                LogLog.Error(declaringType, "Unknown converter name [" + converterName + "] in conversion pattern.");
            }
            else
            {
                PatternConverter pc = null;
                try
                {
                    pc = (PatternConverter)Activator.CreateInstance(info.Type);
                }
                catch (Exception exception)
                {
                    LogLog.Error(declaringType, "Failed to create instance of Type [" + info.Type.FullName + "] using default constructor. Exception: " + exception.ToString());
                }
                pc.FormattingInfo = formattingInfo;
                pc.Option         = option;
                pc.Properties     = info.Properties;
                IOptionHandler handler = pc as IOptionHandler;
                if (handler != null)
                {
                    handler.ActivateOptions();
                }
                this.AddConverter(pc);
            }
        }
예제 #9
0
        /// <summary>
        /// Process a parsed converter pattern
        /// 处理已解析的转换器模式
        /// </summary>
        /// <param name="converterName">the name of the converter</param>
        /// <param name="option">the optional option for the converter</param>
        /// <param name="formattingInfo">the formatting info for the converter</param>
        private void ProcessConverter(string converterName, string option, FormattingInfo formattingInfo)
        {
            LogLog.Debug(declaringType, "Converter [" + converterName + "] Option [" + option + "] Format [min=" + formattingInfo.Min + ",max=" + formattingInfo.Max + ",leftAlign=" + formattingInfo.LeftAlign + "]");

            // Lookup the converter type
            ConverterInfo converterInfo = (ConverterInfo)m_patternConverters[converterName];

            if (converterInfo == null)
            {
                //未知的转换器
                LogLog.Error(declaringType, "Unknown converter name [" + converterName + "] in conversion pattern.");
            }
            else
            {
                // Create the pattern converter
                // 创建模式转换器
                PatternConverter pc = null;
                try
                {
                    pc = (PatternConverter)Activator.CreateInstance(converterInfo.Type);
                }
                catch (Exception createInstanceEx)
                {
                    LogLog.Error(declaringType, "Failed to create instance of Type [" + converterInfo.Type.FullName + "] using default constructor. Exception: " + createInstanceEx.ToString());
                }

                // formattingInfo variable is an instance variable, occasionally reset and used over and over again
                // formattingInfo变量是一个实例变量,偶尔会重新设置并反复使用

                pc.FormattingInfo = formattingInfo;
                pc.Option         = option;
                pc.Properties     = converterInfo.Properties;

                IOptionHandler optionHandler = pc as IOptionHandler;
                if (optionHandler != null)
                {
                    optionHandler.ActivateOptions();
                }

                AddConverter(pc);
            }
        }
예제 #10
0
        /// <summary>
        /// Resets the internal state of the parser and adds the specified pattern converter to the chain.
        /// 重置解析器的内部状态,并将指定的模式转换器添加到链中。
        /// </summary>
        /// <param name="pc">The pattern converter to add.</param>
        private void AddConverter(PatternConverter pc)
        {
            // Add the pattern converter to the list.
            // 将模式转换器添加到列表中。

            if (m_head == null)
            {
                m_head = m_tail = pc;
            }
            else
            {
                // Set the next converter on the tail
                // 设置下一个转换器的尾部
                // Update the tail reference
                // 更新尾引用
                // note that a converter may combine the 'next' into itself and therefore the tail would not change!
                // 注意,转换器可能会将“next”合并到自身中,因此尾巴不会改变!
                m_tail = m_tail.SetNext(pc);
            }
        }
예제 #11
0
        public override void ActivateOptions()
        {
            m_head = CreatePatternParser(m_pattern).Parse();

            PatternConverter curConverter = m_head;
            while (curConverter != null)
            {
                PatternLayoutConverter layoutConverter = curConverter as PatternLayoutConverter;
                if (layoutConverter != null)
                {
                    if (!layoutConverter.IgnoresException)
                    {
                        this.IgnoresException = false;

                        break;
                    }
                }
                curConverter = curConverter.Next;
            }
        }
예제 #12
0
        /// <summary>
        /// Process a parsed converter pattern
        /// </summary>
        /// <param name="converterName">the name of the converter</param>
        /// <param name="option">the optional option for the converter</param>
        /// <param name="formattingInfo">the formatting info for the converter</param>
        void ProcessConverter(string converterName, string option, FormattingInfo formattingInfo)
        {
            LogLog.Debug("PatternParser: Converter [" + converterName + "] Option [" + option + "] Format [min=" +
                         formattingInfo.Min + ",max=" + formattingInfo.Max + ",leftAlign=" + formattingInfo.LeftAlign + "]");

            // Lookup the converter type
            var converterType = (Type)m_patternConverters[converterName];

            if (converterType == null)
            {
                LogLog.Error("PatternParser: Unknown converter name [" + converterName + "] in conversion pattern.");
            }
            else
            {
                // Create the pattern converter
                PatternConverter pc = null;
                try
                {
                    pc = (PatternConverter)Activator.CreateInstance(converterType);
                }
                catch (Exception createInstanceEx)
                {
                    LogLog.Error("PatternParser: Failed to create instance of Type [" + converterType.FullName +
                                 "] using default constructor. Exception: " + createInstanceEx);
                }

                // formattingInfo variable is an instance variable, occasionally reset
                // and used over and over again
                pc.FormattingInfo = formattingInfo;
                pc.Option         = option;

                var optionHandler = pc as IOptionHandler;
                if (optionHandler != null)
                {
                    optionHandler.ActivateOptions();
                }

                AddConverter(pc);
            }
        }
예제 #13
0
        /// <summary>
        /// Initialize layout options
        /// </summary>
        /// <remarks>
        /// <para>
        /// This is part of the <see cref="IOptionHandler"/> delayed object
        /// activation scheme. The <see cref="ActivateOptions"/> method must 
        /// be called on this object after the configuration properties have
        /// been set. Until <see cref="ActivateOptions"/> is called this
        /// object is in an undefined state and must not be used. 
        /// </para>
        /// <para>
        /// If any of the configuration properties are modified then 
        /// <see cref="ActivateOptions"/> must be called again.
        /// </para>
        /// </remarks>
        public override void ActivateOptions()
        {
            m_head = CreatePatternParser(m_pattern).Parse();

            var curConverter = m_head;
            while (curConverter != null)
            {
                var layoutConverter = curConverter as PatternLayoutConverter;
                if (layoutConverter != null)
                {
                    if (!layoutConverter.IgnoresException)
                    {
                        // Found converter that handles the exception
                        IgnoresException = false;

                        break;
                    }
                }
                curConverter = curConverter.Next;
            }
        }
예제 #14
0
                                      }; // 32 spaces

    /// <summary>
    /// Set the next pattern converter in the chains
    /// </summary>
    /// <param name="patternConverter">the pattern converter that should follow this converter in the chain</param>
    /// <returns>the next converter</returns>
    /// <remarks>
    /// <para>
    /// The PatternConverter can merge with its neighbor during this method (or a sub class).
    /// Therefore the return value may or may not be the value of the argument passed in.
    /// </para>
    /// </remarks>
    public virtual PatternConverter SetNext(PatternConverter patternConverter) {
      m_next = patternConverter;
      return m_next;
    }
예제 #15
0
        };                                 // 32 spaces

        /// <summary>
        /// Set the next pattern converter in the chains
        /// </summary>
        /// <param name="patternConverter">the pattern converter that should follow this converter in the chain</param>
        /// <returns>the next converter</returns>
        /// <remarks>
        /// <para>
        /// The PatternConverter can merge with its neighbor during this method (or a sub class).
        /// Therefore the return value may or may not be the value of the argument passed in.
        /// </para>
        /// </remarks>
        public virtual PatternConverter SetNext(PatternConverter patternConverter)
        {
            m_next = patternConverter;
            return(m_next);
        }
예제 #16
0
 /// <summary>
 /// Initialize object options
 /// </summary>
 /// <remarks>
 /// <para>
 /// This is part of the <see cref="IOptionHandler"/> delayed object
 /// activation scheme. The <see cref="ActivateOptions"/> method must
 /// be called on this object after the configuration properties have
 /// been set. Until <see cref="ActivateOptions"/> is called this
 /// object is in an undefined state and must not be used.
 /// </para>
 /// <para>
 /// If any of the configuration properties are modified then
 /// <see cref="ActivateOptions"/> must be called again.
 /// </para>
 /// </remarks>
 virtual public void ActivateOptions()
 {
     m_head = CreatePatternParser(m_pattern).Parse();
 }
예제 #17
0
		/// <summary>
		/// Resets the internal state of the parser and adds the specified pattern converter 
		/// to the chain.
		/// </summary>
		/// <param name="pc">The pattern converter to add.</param>
		private void AddConverter(PatternConverter pc) 
		{
			// Add the pattern converter to the list.

			if (m_head == null) 
			{
				m_head = m_tail = pc;
			}
			else 
			{
				// Set the next converter on the tail
				// Update the tail reference
				// note that a converter may combine the 'next' into itself
				// and therefore the tail would not change!
				m_tail = m_tail.SetNext(pc);
			}
		}
예제 #18
0
		/// <summary>
		/// Initialize object options
		/// </summary>
		/// <remarks>
		/// <para>
		/// This is part of the <see cref="IOptionHandler"/> delayed object
		/// activation scheme. The <see cref="ActivateOptions"/> method must 
		/// be called on this object after the configuration properties have
		/// been set. Until <see cref="ActivateOptions"/> is called this
		/// object is in an undefined state and must not be used. 
		/// </para>
		/// <para>
		/// If any of the configuration properties are modified then 
		/// <see cref="ActivateOptions"/> must be called again.
		/// </para>
		/// </remarks>
		virtual public void ActivateOptions() 
		{
			m_head = CreatePatternParser(m_pattern).Parse();
		}
예제 #19
0
 /// <summary>
 /// Initialize object options.
 /// </summary>
 /// <remarks>
 /// <para>
 /// This is part of the <see cref="IOptionHandler"/> delayed object
 /// activation scheme. The <see cref="ActivateOptions"/> method must
 /// be called on this object after the configuration properties have
 /// been set. Until <see cref="ActivateOptions"/> is called this
 /// object is in an undefined state and must not be used.
 /// </para>
 /// <para>
 /// If any of the configuration properties are modified then
 /// <see cref="ActivateOptions"/> must be called again.
 /// </para>
 /// </remarks>
 public virtual void ActivateOptions()
 {
     this.m_head = this.CreatePatternParser(this.m_pattern).Parse();
 }