示例#1
0
        /// <summary>
        /// Add a converter to this PatternString
        /// </summary>
        /// <param name="converterInfo">the converter info</param>
        /// <remarks>
        /// <para>
        /// This version of the method is used by the configurator.
        /// Programmatic users should use the alternative <see cref="M:AddConverter(string,Type)"/> method.
        /// </para>
        /// </remarks>
        public void AddConverter(ConverterInfo converterInfo)
        {
            if (converterInfo == null)
            {
                throw new ArgumentNullException("converterInfo");
            }

            if (!typeof(PatternConverter).IsAssignableFrom(converterInfo.Type))
            {
                throw new ArgumentException("The converter type specified [" + converterInfo.Type + "] must be a subclass of X3Platform.Logging.Util.PatternConverter", "converterInfo");
            }
            m_instanceRulesRegistry[converterInfo.Name] = converterInfo;
        }
示例#2
0
        /// <summary>
        /// Add a converter to this PatternString
        /// </summary>
        /// <param name="name">the name of the conversion pattern for this converter</param>
        /// <param name="type">the type of the converter</param>
        /// <remarks>
        /// <para>
        /// Add a converter to this PatternString
        /// </para>
        /// </remarks>
        public void AddConverter(string name, Type type)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            ConverterInfo converterInfo = new ConverterInfo();

            converterInfo.Name = name;
            converterInfo.Type = type;

            AddConverter(converterInfo);
        }
示例#3
0
        /// <summary>
        /// Create the <see cref="PatternParser"/> used to parse the pattern
        /// </summary>
        /// <param name="pattern">the pattern to parse</param>
        /// <returns>The <see cref="PatternParser"/></returns>
        /// <remarks>
        /// <para>
        /// Returns PatternParser used to parse the conversion string. Subclasses
        /// may override this to return a subclass of PatternParser which recognize
        /// custom conversion pattern name.
        /// </para>
        /// </remarks>
        private PatternParser CreatePatternParser(string pattern)
        {
            PatternParser patternParser = new PatternParser(pattern);

            // Add all the builtin patterns
            foreach (DictionaryEntry entry in s_globalRulesRegistry)
            {
                ConverterInfo converterInfo = new ConverterInfo();
                converterInfo.Name = (string)entry.Key;
                converterInfo.Type = (Type)entry.Value;
                patternParser.PatternConverters.Add(entry.Key, converterInfo);
            }
            // Add the instance patterns
            foreach (DictionaryEntry entry in m_instanceRulesRegistry)
            {
                patternParser.PatternConverters[entry.Key] = entry.Value;
            }

            return(patternParser);
        }
        /// <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);
            }
        }