コード例 #1
0
 internal RollingFileAppender(IElementConfiguration configuration)
     : base(configuration)
 {
     mDatePattern = new DatePattern(Properties);
     mMaximumFileSize = new MaximumFileSize(Properties);
     mCountDirection = new CountDirection(Properties);
 }
コード例 #2
0
 internal RollingFileAppender(IElementConfiguration configuration)
     : base(configuration)
 {
     mDatePattern      = new DatePattern();
     mMaximumFileSize  = new MaximumFileSize();
     mCountDirection   = new CountDirection();
     mDateTimeStrategy = new StringValueProperty("Date Time Strategy:", "dateTimeStrategy", Log4NetXmlConstants.Type)
     {
         ToolTip = "Sets the strategy for determining the current date and time.\n" +
                   "The default implementation is to use LocalDateTime (log4net.Appender.RollingFileAppender+LocalDateTime,log4net) which internally calls through to DateTime.Now.\n" +
                   "DateTime.UtcNow may be used on frameworks newer than .NET 1.0 by specifying UniversalDateTime (log4net.Appender.RollingFileAppender+UniversalDateTime,log4net).\n" +
                   "A custom implementation that implements IDateTime can be specified here as well. Leave blank to use LocalDateTime."
     };
 }
        /// <summary>
        /// Gets a pattern string for formatting and parsing dates according to the client's user preferences.
        /// </summary>
        /// <param name="options"></param>
        public void getDatePattern(string options)
        {
            GlobalizationOptions globalOptions;

            try
            {
                string[] args = JSON.JsonHelper.Deserialize <string[]>(options);
                globalOptions = JSON.JsonHelper.Deserialize <GlobalizationOptions>(args[0]);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            try
            {
                DateTimeFormatInfo dateFormatInfo = DateTimeFormatInfo.CurrentInfo;
                string             pattern        = dateFormatInfo.FullDateTimePattern; // full datetime by default
                int formatLength = 0;                                                   //default format
                int selector     = 0;                                                   //default selector

                if (globalOptions.AdditionalOptions != null)
                {
                    if (globalOptions.AdditionalOptions.FormatLength != null)
                    {
                        string t = globalOptions.AdditionalOptions.FormatLength;

                        if (t.Equals(GlobalizationOptions.Full))
                        {
                            formatLength++;
                        }
                    }

                    if (globalOptions.AdditionalOptions.Selector != null)
                    {
                        string t = globalOptions.AdditionalOptions.Selector;

                        if (t.Equals(GlobalizationOptions.DateSelector))
                        {
                            selector += 10;
                        }
                        else if (t.Equals(GlobalizationOptions.TimeSelector))
                        {
                            selector += 20;
                        }
                    }

                    //determine return value
                    int method = formatLength + selector;

                    switch (method)
                    {
                    case 1:     // full datetime
                    {
                        pattern = dateFormatInfo.FullDateTimePattern;
                        break;
                    }

                    case 10:     // short date
                    {
                        pattern = dateFormatInfo.ShortDatePattern;
                        break;
                    }

                    case 11:     // full date
                    {
                        pattern = dateFormatInfo.LongDatePattern;
                        break;
                    }

                    case 20:     // short time
                    {
                        pattern = dateFormatInfo.ShortTimePattern;
                        break;
                    }

                    case 21:     // full time
                    {
                        pattern = dateFormatInfo.LongTimePattern;
                        break;
                    }

                    default:     // short datetime
                    {
                        // Seems like C# doesn't support short datetime pattern so we use full format
                        // http://msdn.microsoft.com/en-us/library/1at0z4ew%28v=vs.71%29.aspx
                        pattern = dateFormatInfo.FullDateTimePattern;
                        break;
                    }
                    }
                }

                TimeZoneInfo localZone   = TimeZoneInfo.Local;
                DatePattern  datePattern = new DatePattern(pattern, localZone.DisplayName, localZone.BaseUtcOffset.TotalSeconds, 0);
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, datePattern));
            }
            catch (Exception)
            {
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.PatternError)));
            }
        }
コード例 #4
0
 public void SetUp()
 {
     mSut = new DatePattern();
 }
コード例 #5
0
 public void SetUp()
 {
     mSut = new DatePattern(new ReadOnlyCollection <IProperty>(new List <IProperty>()));
 }