Exemplo n.º 1
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;
            }
        }
Exemplo n.º 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)
        {
            // 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);
            }
        }
Exemplo n.º 3
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
                pc.FormattingInfo = formattingInfo;
                pc.Option         = option;
                pc.Properties     = converterInfo.Properties;

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

                AddConverter(pc);
            }
        }
Exemplo n.º 4
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();
 }
Exemplo n.º 5
0
 /// <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);
 }