Example #1
0
        /// <summary>
        /// Initialize the converter options
        /// </summary>
        /// <remarks>
        /// <para>
        /// This is part of the <see cref="T:log4net.Core.IOptionHandler" /> delayed object
        /// activation scheme. The <see cref="M:log4net.Util.PatternStringConverters.DatePatternConverter.ActivateOptions" /> method must
        /// be called on this object after the configuration properties have
        /// been set. Until <see cref="M:log4net.Util.PatternStringConverters.DatePatternConverter.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="M:log4net.Util.PatternStringConverters.DatePatternConverter.ActivateOptions" /> must be called again.
        /// </para>
        /// </remarks>
        public void ActivateOptions()
        {
            string text = Option;

            if (text == null)
            {
                text = "ISO8601";
            }
            if (SystemInfo.EqualsIgnoringCase(text, "ISO8601"))
            {
                m_dateFormatter = new Iso8601DateFormatter();
            }
            else if (SystemInfo.EqualsIgnoringCase(text, "ABSOLUTE"))
            {
                m_dateFormatter = new AbsoluteTimeDateFormatter();
            }
            else if (SystemInfo.EqualsIgnoringCase(text, "DATE"))
            {
                m_dateFormatter = new DateTimeDateFormatter();
            }
            else
            {
                try
                {
                    m_dateFormatter = new SimpleDateFormatter(text);
                }
                catch (Exception exception)
                {
                    LogLog.Error(declaringType, "Could not instantiate SimpleDateFormatter with [" + text + "]", exception);
                    m_dateFormatter = new Iso8601DateFormatter();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Initialize the converter pattern based on the <see cref="PatternConverter.Option"/> property.
        /// </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 void ActivateOptions()
        {
            string dateFormatStr = Option;

            if (dateFormatStr == null)
            {
                dateFormatStr = AbsoluteTimeDateFormatter.Iso8601TimeDateFormat;
            }

            if (SystemInfo.EqualsIgnoringCase(dateFormatStr, AbsoluteTimeDateFormatter.Iso8601TimeDateFormat))
            {
                m_dateFormatter = new Iso8601DateFormatter();
            }
            else if (SystemInfo.EqualsIgnoringCase(dateFormatStr, AbsoluteTimeDateFormatter.AbsoluteTimeDateFormat))
            {
                m_dateFormatter = new AbsoluteTimeDateFormatter();
            }
            else if (SystemInfo.EqualsIgnoringCase(dateFormatStr, AbsoluteTimeDateFormatter.DateAndTimeDateFormat))
            {
                m_dateFormatter = new DateTimeDateFormatter();
            }
            else
            {
                try
                {
                    m_dateFormatter = new SimpleDateFormatter(dateFormatStr);
                }
                catch (Exception e)
                {
                    LogLog.Error(declaringType, "Could not instantiate SimpleDateFormatter with [" + dateFormatStr + "]", e);
                    m_dateFormatter = new Iso8601DateFormatter();
                }
            }
        }
        /// <summary>
        /// Look for a method on the <paramref name="targetType"/> that matches the <paramref name="name"/> supplied
        /// </summary>
        /// <param name="targetType">the type that has the method</param>
        /// <param name="name">the name of the method</param>
        /// <returns>the method info found</returns>
        /// <remarks>
        /// <para>
        /// The method must be a public instance method on the <paramref name="targetType"/>.
        /// The method must be named <paramref name="name"/> or "Add" followed by <paramref name="name"/>.
        /// The method must take a single parameter.
        /// </para>
        /// </remarks>
        private MethodInfo FindMethodInfo(Type targetType, string name)
        {
            string requiredMethodNameA = name;
            string requiredMethodNameB = "Add" + name;

            MethodInfo[] methods = targetType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (MethodInfo methInfo in methods)
            {
                if (!methInfo.IsStatic)
                {
                    string methodInfoName = methInfo.Name;

                    if (SystemInfo.EqualsIgnoringCase(methodInfoName, requiredMethodNameA) ||
                        SystemInfo.EqualsIgnoringCase(methodInfoName, requiredMethodNameB))
                    {
                        // Found matching method name

                        // Look for version with one arg only
                        System.Reflection.ParameterInfo[] methParams = methInfo.GetParameters();
                        if (methParams.Length == 1)
                        {
                            return(methInfo);
                        }
                    }
                }
            }
            return(null);
        }
Example #4
0
 /// <summary>
 /// Initialize the converter
 /// </summary>
 /// <remarks>
 /// <para>
 /// This is part of the <see cref="T:log4net.Core.IOptionHandler" /> delayed object
 /// activation scheme. The <see cref="M:log4net.Util.PatternStringConverters.NewLinePatternConverter.ActivateOptions" /> method must
 /// be called on this object after the configuration properties have
 /// been set. Until <see cref="M:log4net.Util.PatternStringConverters.NewLinePatternConverter.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="M:log4net.Util.PatternStringConverters.NewLinePatternConverter.ActivateOptions" /> must be called again.
 /// </para>
 /// </remarks>
 public void ActivateOptions()
 {
     if (SystemInfo.EqualsIgnoringCase(Option, "DOS"))
     {
         Option = "\r\n";
     }
     else if (SystemInfo.EqualsIgnoringCase(Option, "UNIX"))
     {
         Option = "\n";
     }
     else
     {
         Option = SystemInfo.NewLine;
     }
 }
        /// <summary>
        /// Look for a method on the <paramref name="targetType" /> that matches the <paramref name="name" /> supplied
        /// </summary>
        /// <param name="targetType">the type that has the method</param>
        /// <param name="name">the name of the method</param>
        /// <returns>the method info found</returns>
        /// <remarks>
        /// <para>
        /// The method must be a public instance method on the <paramref name="targetType" />.
        /// The method must be named <paramref name="name" /> or "Add" followed by <paramref name="name" />.
        /// The method must take a single parameter.
        /// </para>
        /// </remarks>
        private MethodInfo FindMethodInfo(Type targetType, string name)
        {
            string b = "Add" + name;

            MethodInfo[] methods = targetType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            foreach (MethodInfo methodInfo in methods)
            {
                if (!methodInfo.IsStatic)
                {
                    string name2 = methodInfo.Name;
                    if ((SystemInfo.EqualsIgnoringCase(name2, name) || SystemInfo.EqualsIgnoringCase(name2, b)) && methodInfo.GetParameters().Length == 1)
                    {
                        return(methodInfo);
                    }
                }
            }
            return(null);
        }
Example #6
0
 public void EqualsIgnoringCase_DifferentStrings_false()
 {
     Assert.False(SystemInfo.EqualsIgnoringCase("foo", "foobar"));
 }
Example #7
0
 public void EqualsIgnoringCase_SameStringsDifferentCase_true()
 {
     Assert.True(SystemInfo.EqualsIgnoringCase("foo", "FOO"));
 }
Example #8
0
 public void EqualsIgnoringCase_SameStringsSameCase_true()
 {
     Assert.True(SystemInfo.EqualsIgnoringCase("foo", "foo"));
 }
Example #9
0
 public void EqualsIgnoringCase_RightNull_false()
 {
     Assert.False(SystemInfo.EqualsIgnoringCase("foo", null));
 }
Example #10
0
 public void EqualsIgnoringCase_LeftNull_false()
 {
     Assert.False(SystemInfo.EqualsIgnoringCase(null, "foo"));
 }
Example #11
0
 public void EqualsIgnoringCase_BothNull_true()
 {
     Assert.True(SystemInfo.EqualsIgnoringCase(null, null));
 }