Example #1
0
 /// <summary>
 /// Activate the options on the file appender.
 /// </summary>
 public override void ActivateOptions()
 {
     if (this.m_rollDate && (this.m_datePattern != null))
     {
         this.m_now       = this.m_dateTime.Now;
         this.m_rollPoint = this.ComputeCheckPeriod(this.m_datePattern);
         if (this.m_rollPoint == RollPoint.InvalidRollPoint)
         {
             throw new ArgumentException("Invalid RollPoint, unable to parse [" + this.m_datePattern + "]");
         }
         this.m_nextCheck = this.NextCheckDate(this.m_now, this.m_rollPoint);
     }
     else if (this.m_rollDate)
     {
         this.ErrorHandler.Error("Either DatePattern or rollingStyle options are not set for [" + base.Name + "].");
     }
     if (base.SecurityContext == null)
     {
         base.SecurityContext = SecurityContextProvider.DefaultProvider.CreateSecurityContext(this);
     }
     using (base.SecurityContext.Impersonate(this))
     {
         base.File           = FileAppender.ConvertToFullPath(base.File.Trim());
         this.m_baseFileName = base.File;
     }
     if ((this.m_rollDate && (this.File != null)) && (this.m_scheduledFilename == null))
     {
         this.m_scheduledFilename = this.File + this.m_now.ToString(this.m_datePattern, DateTimeFormatInfo.InvariantInfo);
     }
     this.ExistingInit();
     base.ActivateOptions();
 }
Example #2
0
        protected DateTime NextCheckDate(DateTime currentDateTime, RollPoint rollPoint)
        {
            DateTime dateTime = currentDateTime;

            switch (rollPoint)
            {
            case RollPoint.TopOfMinute:
                dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
                dateTime = dateTime.AddSeconds(-dateTime.Second);
                dateTime = dateTime.AddMinutes(1.0);
                break;

            case RollPoint.TopOfHour:
                dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
                dateTime = dateTime.AddSeconds(-dateTime.Second);
                dateTime = dateTime.AddMinutes(-dateTime.Minute);
                dateTime = dateTime.AddHours(1.0);
                break;

            case RollPoint.HalfDay:
                dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
                dateTime = dateTime.AddSeconds(-dateTime.Second);
                dateTime = dateTime.AddMinutes(-dateTime.Minute);
                if (dateTime.Hour < 12)
                {
                    dateTime = dateTime.AddHours(12 - dateTime.Hour);
                    break;
                }
                dateTime = dateTime.AddHours(-dateTime.Hour);
                dateTime = dateTime.AddDays(1.0);
                break;

            case RollPoint.TopOfDay:
                dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
                dateTime = dateTime.AddSeconds(-dateTime.Second);
                dateTime = dateTime.AddMinutes(-dateTime.Minute);
                dateTime = dateTime.AddHours(-dateTime.Hour);
                dateTime = dateTime.AddDays(1.0);
                break;

            case RollPoint.TopOfWeek:
                dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
                dateTime = dateTime.AddSeconds(-dateTime.Second);
                dateTime = dateTime.AddMinutes(-dateTime.Minute);
                dateTime = dateTime.AddHours(-dateTime.Hour);
                dateTime = dateTime.AddDays(7 - (int)dateTime.DayOfWeek);
                break;

            case RollPoint.TopOfMonth:
                dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
                dateTime = dateTime.AddSeconds(-dateTime.Second);
                dateTime = dateTime.AddMinutes(-dateTime.Minute);
                dateTime = dateTime.AddHours(-dateTime.Hour);
                dateTime = dateTime.AddDays(1 - dateTime.Day);
                dateTime = dateTime.AddMonths(1);
                break;
            }
            return(dateTime);
        }
Example #3
0
        public override void ActivateOptions()
        {
            base.ActivateOptions();

            //DateTimeStrategy инициализируется в base.ActivateOptions()
            _prevDate  =
                _now   = DateTimeStrategy.Now;
            _rollPoint = ComputeCheckPeriod(DatePattern);
            _nextCheck = NextCheckDate(_now, _rollPoint);
            _file      = File;
        }
Example #4
0
        /// <summary>
        /// Nexts the check date.
        /// </summary>
        /// <param name="currentDateTime">The current date time.</param>
        /// <param name="rollPoint">The roll point.</param>
        /// <returns></returns>
        protected DateTime NextCheckDate(DateTime currentDateTime, RollPoint rollPoint)
        {
            DateTime current = currentDateTime;

            switch (rollPoint)
            {
            case RollPoint.TopOfMinute:
                current = current.AddMilliseconds((double)-current.Millisecond);
                return(current.AddSeconds((double)-current.Second).AddMinutes(1.0));

            case RollPoint.TopOfHour:
                current = current.AddMilliseconds((double)-current.Millisecond);
                current = current.AddSeconds((double)-current.Second);
                return(current.AddMinutes((double)-current.Minute).AddHours(1.0));

            case RollPoint.HalfDay:
                current = current.AddMilliseconds((double)-current.Millisecond);
                current = current.AddSeconds((double)-current.Second);
                current = current.AddMinutes((double)-current.Minute);
                if (current.Hour >= 12)
                {
                    return(current.AddHours((double)-current.Hour).AddDays(1.0));
                }
                return(current.AddHours((double)(12 - current.Hour)));

            case RollPoint.TopOfDay:
                current = current.AddMilliseconds((double)-current.Millisecond);
                current = current.AddSeconds((double)-current.Second);
                current = current.AddMinutes((double)-current.Minute);
                return(current.AddHours((double)-current.Hour).AddDays(1.0));

            case RollPoint.TopOfWeek:
                current = current.AddMilliseconds((double)-current.Millisecond);
                current = current.AddSeconds((double)-current.Second);
                current = current.AddMinutes((double)-current.Minute);
                current = current.AddHours((double)-current.Hour);
                return(current.AddDays((double)(7 - current.DayOfWeek)));

            case RollPoint.TopOfMonth:
                current = current.AddMilliseconds((double)-current.Millisecond);
                current = current.AddSeconds((double)-current.Second);
                current = current.AddMinutes((double)-current.Minute);
                current = current.AddHours((double)-current.Hour);
                return(current.AddDays((double)(1 - current.Day)).AddMonths(1));
            }
            return(current);
        }
Example #5
0
        public override void ActivateOptions()
        {
            if (IsTemplate)
            {
                return;
            }

            _now       = _dateTime.Now;
            _rollPoint = ComputeCheckPeriod(ActivityLogFile.FileDatePattern);
            if (_rollPoint == RollPoint.InvalidRollPoint)
            {
                throw new ArgumentException("Invalid RollPoint, unable to parse [" + ActivityLogFile.FileDatePattern + "]");
            }
            _nextCheck = NextCheckDate(_now, _rollPoint);

            if (SecurityContext == null)
            {
                SecurityContext = SecurityContextProvider.DefaultProvider.CreateSecurityContext(this);
            }

            using (SecurityContext.Impersonate(this))
            {
                File = ConvertToFullPath(File.Trim());

                _baseFileName = File;
            }

            if (_rollDate && File != null && _scheduledFilename == null)
            {
                _scheduledFilename = ActivityLogFile.ComposeFileName(File, _now);
            }

            ExistingInit();

            base.ActivateOptions();

            Folder = ConvertToFullPath(Folder);
            Closed = false;
        }
        /// <summary>
        /// Get the start time of the next window for the current rollpoint
        /// </summary>
        /// <param name="currentDateTime">the current date</param>
        /// <param name="rollPoint">the type of roll point we are working with</param>
        /// <returns>the start time for the next roll point an interval after the currentDateTime date</returns>
        /// <remarks>
        /// <para>
        /// Returns the date of the next roll point after the currentDateTime date passed to the method.
        /// </para>
        /// <para>
        /// The basic strategy is to subtract the time parts that are less significant
        /// than the rollpoint from the current time. This should roll the time back to
        /// the start of the time window for the current rollpoint. Then we add 1 window
        /// worth of time and get the start time of the next window for the rollpoint.
        /// </para>
        /// </remarks>
        protected DateTime NextCheckDate(DateTime currentDateTime, RollPoint rollPoint) 
        {
            // Local variable to work on (this does not look very efficient)
            DateTime current = currentDateTime;

            // Do slightly different things depending on what the type of roll point we want.
            switch(rollPoint) 
            {
                case RollPoint.TopOfMinute:
                    current = current.AddMilliseconds(-current.Millisecond);
                    current = current.AddSeconds(-current.Second);
                    current = current.AddMinutes(1);
                    break;

                case RollPoint.TopOfHour:
                    current = current.AddMilliseconds(-current.Millisecond);
                    current = current.AddSeconds(-current.Second);
                    current = current.AddMinutes(-current.Minute);
                    current = current.AddHours(1);
                    break;

                case RollPoint.HalfDay:
                    current = current.AddMilliseconds(-current.Millisecond);
                    current = current.AddSeconds(-current.Second);
                    current = current.AddMinutes(-current.Minute);

                    if (current.Hour < 12) 
                    {
                        current = current.AddHours(12 - current.Hour);
                    } 
                    else 
                    {
                        current = current.AddHours(-current.Hour);
                        current = current.AddDays(1);
                    }
                    break;

                case RollPoint.TopOfDay:
                    current = current.AddMilliseconds(-current.Millisecond);
                    current = current.AddSeconds(-current.Second);
                    current = current.AddMinutes(-current.Minute);
                    current = current.AddHours(-current.Hour);
                    current = current.AddDays(1);
                    break;

                case RollPoint.TopOfWeek:
                    current = current.AddMilliseconds(-current.Millisecond);
                    current = current.AddSeconds(-current.Second);
                    current = current.AddMinutes(-current.Minute);
                    current = current.AddHours(-current.Hour);
                    current = current.AddDays(7 - (int)current.DayOfWeek);
                    break;

                case RollPoint.TopOfMonth:
                    current = current.AddMilliseconds(-current.Millisecond);
                    current = current.AddSeconds(-current.Second);
                    current = current.AddMinutes(-current.Minute);
                    current = current.AddHours(-current.Hour);
                    current = current.AddDays(1 - current.Day); /* first day of month is 1 not 0 */
                    current = current.AddMonths(1);
                    break;
            }      
            return current;
        }
		protected DateTime NextCheckDate(DateTime currentDateTime, RollPoint rollPoint)
		{
			DateTime dateTime = currentDateTime;

			switch (rollPoint)
			{
				case RollPoint.TopOfMinute:
					dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
					dateTime = dateTime.AddSeconds(-dateTime.Second);
					dateTime = dateTime.AddMinutes(1.0);
					break;
				case RollPoint.TopOfHour:
					dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
					dateTime = dateTime.AddSeconds(-dateTime.Second);
					dateTime = dateTime.AddMinutes(-dateTime.Minute);
					dateTime = dateTime.AddHours(1.0);
					break;
				case RollPoint.HalfDay:
					dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
					dateTime = dateTime.AddSeconds(-dateTime.Second);
					dateTime = dateTime.AddMinutes(-dateTime.Minute);
					if (dateTime.Hour < 12)
					{
						dateTime = dateTime.AddHours(12 - dateTime.Hour);
						break;
					}
					dateTime = dateTime.AddHours(-dateTime.Hour);
					dateTime = dateTime.AddDays(1.0);
					break;
				case RollPoint.TopOfDay:
					dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
					dateTime = dateTime.AddSeconds(-dateTime.Second);
					dateTime = dateTime.AddMinutes(-dateTime.Minute);
					dateTime = dateTime.AddHours(-dateTime.Hour);
					dateTime = dateTime.AddDays(1.0);
					break;
				case RollPoint.TopOfWeek:
					dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
					dateTime = dateTime.AddSeconds(-dateTime.Second);
					dateTime = dateTime.AddMinutes(-dateTime.Minute);
					dateTime = dateTime.AddHours(-dateTime.Hour);
					dateTime = dateTime.AddDays(7 - (int) dateTime.DayOfWeek);
					break;
				case RollPoint.TopOfMonth:
					dateTime = dateTime.AddMilliseconds(-dateTime.Millisecond);
					dateTime = dateTime.AddSeconds(-dateTime.Second);
					dateTime = dateTime.AddMinutes(-dateTime.Minute);
					dateTime = dateTime.AddHours(-dateTime.Hour);
					dateTime = dateTime.AddDays(1 - dateTime.Day);
					dateTime = dateTime.AddMonths(1);
					break;
			}
			return dateTime;
		}
		public override void ActivateOptions()
		{
			if (IsTemplate)
			{
				return;
			}

			_now = _dateTime.Now;
			_rollPoint = ComputeCheckPeriod(ActivityLogFile.FileDatePattern);
			if (_rollPoint == RollPoint.InvalidRollPoint)
			{
				throw new ArgumentException("Invalid RollPoint, unable to parse [" + ActivityLogFile.FileDatePattern + "]");
			}
			_nextCheck = NextCheckDate(_now, _rollPoint);

			if (SecurityContext == null)
			{
				SecurityContext = SecurityContextProvider.DefaultProvider.CreateSecurityContext(this);
			}

			using (SecurityContext.Impersonate(this))
			{
				File = ConvertToFullPath(File.Trim());

				_baseFileName = File;
			}

			if (_rollDate && File != null && _scheduledFilename == null)
			{
				_scheduledFilename = ActivityLogFile.ComposeFileName(File, _now);
			}

			ExistingInit();

			base.ActivateOptions();

			Folder = ConvertToFullPath(Folder);
			Closed = false;
		}
Example #9
0
        protected DateTime NextCheckDate(DateTime currentDateTime, RollPoint rollPoint)
        {
            // Local variable to work on (this does not look very efficient)
            DateTime current = currentDateTime;

            // Do slightly different things depending on what the type of roll point we want.
            switch (rollPoint)
            {
            case RollPoint.TopOfMinute:
                current = current.AddMilliseconds(-current.Millisecond);
                current = current.AddSeconds(-current.Second);
                current = current.AddMinutes(1);
                break;

            case RollPoint.TopOfHour:
                current = current.AddMilliseconds(-current.Millisecond);
                current = current.AddSeconds(-current.Second);
                current = current.AddMinutes(-current.Minute);
                current = current.AddHours(1);
                break;

            case RollPoint.HalfDay:
                current = current.AddMilliseconds(-current.Millisecond);
                current = current.AddSeconds(-current.Second);
                current = current.AddMinutes(-current.Minute);

                if (current.Hour < 12)
                {
                    current = current.AddHours(12 - current.Hour);
                }
                else
                {
                    current = current.AddHours(-current.Hour);
                    current = current.AddDays(1);
                }
                break;

            case RollPoint.TopOfDay:
                current = current.AddMilliseconds(-current.Millisecond);
                current = current.AddSeconds(-current.Second);
                current = current.AddMinutes(-current.Minute);
                current = current.AddHours(-current.Hour);
                current = current.AddDays(1);
                break;

            case RollPoint.TopOfWeek:
                current = current.AddMilliseconds(-current.Millisecond);
                current = current.AddSeconds(-current.Second);
                current = current.AddMinutes(-current.Minute);
                current = current.AddHours(-current.Hour);
                current = current.AddDays(7 - (int)current.DayOfWeek);
                break;

            case RollPoint.TopOfMonth:
                current = current.AddMilliseconds(-current.Millisecond);
                current = current.AddSeconds(-current.Second);
                current = current.AddMinutes(-current.Minute);
                current = current.AddHours(-current.Hour);
                current = current.AddDays(1 - current.Day);     /* first day of month is 1 not 0 */
                current = current.AddMonths(1);
                break;
            }
            return(current);
        }
Example #10
0
        /// <summary>
        /// Initialize the appender based on the options set
        /// </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>
        /// <para>
        /// Sets initial conditions including date/time roll over information, first check,
        /// scheduledFilename, and calls <see cref="ExistingInit"/> to initialize
        /// the current number of backups.
        /// </para>
        /// </remarks>
        public override void ActivateOptions()
        {
            if (m_dateTime == null)
            {
                m_dateTime = new LocalDateTime();
            }

            if (m_rollDate && m_datePattern != null)
            {
                m_now = m_dateTime.Now;
                m_rollPoint = ComputeCheckPeriod(m_datePattern);

                if (m_rollPoint == RollPoint.InvalidRollPoint)
                {
                    throw new ArgumentException("Invalid RollPoint, unable to parse ["+m_datePattern+"]");
                }

                // next line added as this removes the name check in rollOver
                m_nextCheck = NextCheckDate(m_now, m_rollPoint);
            }
            else
            {
                if (m_rollDate)
                {
                    ErrorHandler.Error("Either DatePattern or rollingStyle options are not set for ["+Name+"].");
                }
            }

            if (SecurityContext == null)
            {
                SecurityContext = SecurityContextProvider.DefaultProvider.CreateSecurityContext(this);
            }

            using(SecurityContext.Impersonate(this))
            {
                // Must convert the FileAppender's m_filePath to an absolute path before we
                // call ExistingInit(). This will be done by the base.ActivateOptions() but
                // we need to duplicate that functionality here first.
                base.File = ConvertToFullPath(base.File.Trim());

                // Store fully qualified base file name
                m_baseFileName = base.File;
            }

            // initialize the mutex that is used to lock rolling
            m_mutexForRolling = new Mutex(false, m_baseFileName.Replace("\\", "_").Replace(":", "_").Replace("/", "_"));

            if (m_rollDate && File != null && m_scheduledFilename == null)
            {
                m_scheduledFilename = CombinePath(File, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo));
            }

            ExistingInit();

            base.ActivateOptions();
        }