当前位置: 首页>>代码示例>>C#>>正文


C# IRecurrencePattern类代码示例

本文整理汇总了C#中IRecurrencePattern的典型用法代码示例。如果您正苦于以下问题:C# IRecurrencePattern类的具体用法?C# IRecurrencePattern怎么用?C# IRecurrencePattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IRecurrencePattern类属于命名空间,在下文中一共展示了IRecurrencePattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

 /// <summary>
 /// Creates the specified pattern.
 /// </summary>
 /// <param name="pattern">The pattern.</param>
 /// <param name="windowStart">The window start.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentException">pattern.Frequency</exception>
 public static IRecurrence Create(IRecurrencePattern pattern, DateTime windowStart)
 {
     AsyncServiceException.ThrowIfNull(pattern, "pattern");
     switch (pattern.Frequency)
     {
         case RecurrenceFrequency.Minutely:
             return new ConstantPeriodRecurrence(TimeSpan.FromMinutes(1.0), pattern.Interval,
                                                 pattern.PatternStart, windowStart);
         case RecurrenceFrequency.Hourly:
             return new ConstantPeriodRecurrence(TimeSpan.FromHours(1.0), pattern.Interval, pattern.PatternStart,
                                                 windowStart);
         case RecurrenceFrequency.Daily:
             return new ConstantPeriodRecurrence(TimeSpan.FromDays(1.0), pattern.Interval, pattern.PatternStart,
                                                 windowStart);
         case RecurrenceFrequency.Weekly:
             if (pattern.ByDay.Length == 0)
             {
                 return new ConstantPeriodRecurrence(TimeSpan.FromDays(7.0), pattern.Interval,
                                                     pattern.PatternStart, windowStart);
             }
             IModifier modifier = new ByDayWeeklyModifier(pattern.ByDay, pattern.WeekStartDay);
             IRecurrence recurrence = new WeeklyRecurrence(pattern.Interval, pattern.PatternStart,
                                                           pattern.WeekStartDay, windowStart);
             return new ModifiedRecurrence(recurrence, modifier, windowStart);
         case RecurrenceFrequency.Yearly:
             return new YearlyRecurrence(pattern.Interval, pattern.ByMonth, pattern.ByMonthDay, pattern.PatternStart, windowStart);
         case RecurrenceFrequency.Secondly:
             return new ConstantPeriodRecurrence(TimeSpan.FromSeconds(1.0), pattern.Interval,
                                                 pattern.PatternStart, windowStart);
         default:
             throw new ArgumentException(string.Format("不合法的重复频率{0}。", pattern.Frequency), "pattern.Frequency");
     }
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:40,代码来源:RecurrenceFactory.cs

示例2: RecurrenceInstances

 /// <summary>
 /// Initializes a new instance of the <see cref="RecurrenceInstances"/> class.
 /// </summary>
 /// <param name="pattern">The pattern.</param>
 /// <param name="scope">The scope.</param>
 /// <param name="maxInstances">The maximum instances.</param>
 public RecurrenceInstances(IRecurrencePattern pattern, TimeInterval scope, int maxInstances)
 {
     AsyncServiceException.ThrowIfNull(pattern, "pattern");
     AsyncServiceException.ThrowIfNotPositive(maxInstances, "maxInstances");
     this._pattern = pattern;
     this._scope = scope;
     this._maxInstances = maxInstances;
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:14,代码来源:RecurrenceInstances.cs

示例3: DetermineStartingRecurrence

 public void DetermineStartingRecurrence(IRecurrencePattern recur, ref IDateTime dt)
 {
     if (recur.Count != int.MinValue)
         dt = Todo.Start.Copy<IDateTime>();
     else
     {
         DateTime dtVal = dt.Value;
         IncrementDate(ref dtVal, recur, -recur.Interval);
         dt.Value = dtVal;
     }
 }
开发者ID:SpivEgin,项目名称:ndef-nfc,代码行数:11,代码来源:TodoEvaluator.cs

示例4: IncrementDate

 protected void IncrementDate(ref DateTime dt, IRecurrencePattern pattern, int interval)
 {
     DateTime old = dt;
     switch (pattern.Frequency)
     {
         case FrequencyType.Secondly: dt = old.AddSeconds(interval); break;
         case FrequencyType.Minutely: dt = old.AddMinutes(interval); break;
         case FrequencyType.Hourly: dt = old.AddHours(interval); break;
         case FrequencyType.Daily: dt = old.AddDays(interval); break;
         case FrequencyType.Weekly: dt = DateUtil.AddWeeks(Calendar, old, interval, pattern.FirstDayOfWeek); break;
         case FrequencyType.Monthly: dt = old.AddDays(-old.Day + 1).AddMonths(interval); break;
         case FrequencyType.Yearly: dt = old.AddDays(-old.DayOfYear + 1).AddYears(interval); break;
         default: throw new Exception("FrequencyType.NONE cannot be evaluated. Please specify a FrequencyType before evaluating the recurrence.");
     }
 }
开发者ID:MaitreDede,项目名称:dday-ical,代码行数:15,代码来源:Evaluator.cs

示例5: RecurrenceExpander

 /// <summary>
 /// Initializes a new instance of the <see cref="RecurrenceExpander"/> class.
 /// </summary>
 /// <param name="pattern">The pattern.</param>
 /// <param name="scope">The scope.</param>
 /// <param name="maxInstances">The maximum instances.</param>
 public RecurrenceExpander(IRecurrencePattern pattern, TimeInterval scope, int maxInstances)
 {
     AsyncServiceException.ThrowIfNull(pattern, "pattern");
     AsyncServiceException.ThrowIfNegative(maxInstances, "maxInstances");
     this._pattern = pattern;
     // 取消多时区支持
     //this._scope = new TimeInterval(pattern.TimeZone.ToLocalTime(scope.Start), scope.IsStartInclusive, pattern.TimeZone.ToLocalTime(scope.End), scope.IsEndInclusive);
     this._scope = new TimeInterval(scope.Start, scope.IsStartInclusive, scope.End, scope.IsEndInclusive);
     this._maxInstances = maxInstances;
     DateTime windowStart = this._pattern.PatternStart;
     if (this._pattern.Count == 0 && this._scope.Start - this._pattern.Duration > this._pattern.PatternStart)
     {
         windowStart = this._scope.Start - this._pattern.Duration;
     }
     this._generator = RecurrenceFactory.Create(this._pattern, windowStart);
     this._expandedInstances = 0;
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:23,代码来源:RecurrenceExpander.cs

示例6: IncrementDate

        protected void IncrementDate(ref DateTime dt, IRecurrencePattern pattern, int interval)
        {
            // FIXME: use a more specific exception.
            if (interval == 0)
                throw new Exception("Cannot evaluate with an interval of zero.  Please use an interval other than zero.");

            DateTime old = dt;
            switch (pattern.Frequency)
            {
                case FrequencyType.Secondly: dt = old.AddSeconds(interval); break;
                case FrequencyType.Minutely: dt = old.AddMinutes(interval); break;
                case FrequencyType.Hourly: dt = old.AddHours(interval); break;
                case FrequencyType.Daily: dt = old.AddDays(interval); break;
                case FrequencyType.Weekly: dt = DateUtil.AddWeeks(old, interval, pattern.FirstDayOfWeek); break;
                case FrequencyType.Monthly: dt = old.AddDays(-old.Day + 1).AddMonths(interval); break;
                case FrequencyType.Yearly: dt = old.AddDays(-old.DayOfYear + 1).AddYears(interval); break;
                // FIXME: use a more specific exception.
                default: throw new Exception("FrequencyType.NONE cannot be evaluated. Please specify a FrequencyType before evaluating the recurrence.");
            }
        }
开发者ID:nachocove,项目名称:DDay-iCal-Xamarin,代码行数:20,代码来源:Evaluator.cs

示例7: GetExpandBehaviorList

        static public bool?[] GetExpandBehaviorList(IRecurrencePattern p)
        {
            // See the table in RFC 5545 Section 3.3.10 (Page 43).
            switch (p.Frequency)
            {                
                case FrequencyType.Minutely: return new bool?[] { false, null, false, false, false, false, false, true, false };
                case FrequencyType.Hourly:   return new bool?[] { false, null, false, false, false, false, true, true, false };
                case FrequencyType.Daily:    return new bool?[] { false, null, null, false, false, true, true, true, false };
                case FrequencyType.Weekly:   return new bool?[] { false, null, null, null, true, true, true, true, false };
                case FrequencyType.Monthly:
                    {
                        bool?[] row = new bool?[] { false, null, null, true, true, true, true, true, false };

                        // Limit if BYMONTHDAY is present; otherwise, special expand for MONTHLY.
                        if (p.ByMonthDay.Count > 0)
                            row[4] = false;

                        return row;
                    }
                case FrequencyType.Yearly:
                    {
                        bool?[] row = new bool?[] { true, true, true, true, true, true, true, true, false };

                        // Limit if BYYEARDAY or BYMONTHDAY is present; otherwise,
                        // special expand for WEEKLY if BYWEEKNO present; otherwise,
                        // special expand for MONTHLY if BYMONTH present; otherwise,
                        // special expand for YEARLY.
                        if (p.ByYearDay.Count > 0 || p.ByMonthDay.Count > 0)
                            row[4] = false;

                        return row;
                    }
                default:
                    return new bool?[] { false, null, false, false, false, false, false, false, false };
            }
        }
开发者ID:logikonline,项目名称:DDay.iCal,代码行数:36,代码来源:RecurrenceUtil.cs

示例8: GetMonthVariants

        /**
         * Applies BYMONTH rules specified in this Recur instance to the specified date list. If no BYMONTH rules are
         * specified the date list is returned unmodified.
         * @param dates
         * @return
         */
        private List<DateTime> GetMonthVariants(List<DateTime> dates, IRecurrencePattern pattern, bool? expand)
        {
            if (expand == null || pattern.ByMonth.Count == 0)
                return dates;

            if (expand.HasValue && expand.Value)
            {
                // Expand behavior
                List<DateTime> monthlyDates = new List<DateTime>();
                for (int i = 0; i < dates.Count; i++)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByMonth.Count; j++)
                    {
                        int month = pattern.ByMonth[j];
                        date = date.AddMonths(month - date.Month);
                        monthlyDates.Add(date);
                    }
                }
                return monthlyDates;
            }
            else
            {
                // Limit behavior
                for (int i = dates.Count - 1; i >= 0; i--)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByMonth.Count; j++)
                    {
                        if (date.Month == pattern.ByMonth[j])
                            goto Next;
                    }
                    dates.RemoveAt(i);
                Next: ;
                }
                return dates;
            }
        }
开发者ID:devcrafting,项目名称:DDay.iCal,代码行数:44,代码来源:RecurrencePatternEvaluator.cs

示例9: GetWeekNoVariants

        /**
         * Applies BYWEEKNO rules specified in this Recur instance to the specified date list. If no BYWEEKNO rules are
         * specified the date list is returned unmodified.
         * @param dates
         * @return
         */
        private List<DateTime> GetWeekNoVariants(List<DateTime> dates, IRecurrencePattern pattern, bool? expand)
        {
            if (expand == null || pattern.ByWeekNo.Count == 0)
                return dates;

            if (expand.HasValue && expand.Value)
            {
                // Expand behavior
                List<DateTime> weekNoDates = new List<DateTime>();
                for (int i = 0; i < dates.Count; i++)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByWeekNo.Count; j++)
                    {
                        // Determine our target week number
                        int weekNo = pattern.ByWeekNo[j];

                        // Determine our current week number
                        int currWeekNo = Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, pattern.FirstDayOfWeek);
                        while (currWeekNo > weekNo)
                        {
                            // If currWeekNo > weekNo, then we're likely at the start of a year
                            // where currWeekNo could be 52 or 53.  If we simply step ahead 7 days
                            // we should be back to week 1, where we can easily make the calculation
                            // to move to weekNo.
                            date = date.AddDays(7);
                            currWeekNo = Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, pattern.FirstDayOfWeek);
                        }

                        // Move ahead to the correct week of the year
                        date = date.AddDays((weekNo - currWeekNo) * 7);

                        // Step backward single days until we're at the correct DayOfWeek
                        while (date.DayOfWeek != pattern.FirstDayOfWeek)
                            date = date.AddDays(-1);

                        for (int k = 0; k < 7; k++)
                        {
                            weekNoDates.Add(date);
                            date = date.AddDays(1);
                        }
                    }
                }
                return weekNoDates;
            }
            else
            {
                // Limit behavior
                for (int i = dates.Count - 1; i >= 0; i--)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByWeekNo.Count; j++)
                    {
                        // Determine our target week number
                        int weekNo = pattern.ByWeekNo[j];

                        // Determine our current week number
                        int currWeekNo = Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, pattern.FirstDayOfWeek);

                        if (weekNo == currWeekNo)
                            goto Next;
                    }

                    dates.RemoveAt(i);
                Next: ;
                }
                return dates;
            }
        }
开发者ID:devcrafting,项目名称:DDay.iCal,代码行数:75,代码来源:RecurrencePatternEvaluator.cs

示例10: GetCandidates

 /**
  * Returns a list of possible dates generated from the applicable BY* rules, using the specified date as a seed.
  * @param date the seed date
  * @param value the type of date list to return
  * @return a DateList
  */
 private List<DateTime> GetCandidates(DateTime date, IRecurrencePattern pattern, bool?[] expandBehaviors)
 {
     List<DateTime> dates = new List<DateTime>();
     dates.Add(date);
     dates = GetMonthVariants(dates, pattern, expandBehaviors[0]);
     dates = GetWeekNoVariants(dates, pattern, expandBehaviors[1]);
     dates = GetYearDayVariants(dates, pattern, expandBehaviors[2]);
     dates = GetMonthDayVariants(dates, pattern, expandBehaviors[3]);
     dates = GetDayVariants(dates, pattern, expandBehaviors[4]);
     dates = GetHourVariants(dates, pattern, expandBehaviors[5]);
     dates = GetMinuteVariants(dates, pattern, expandBehaviors[6]);
     dates = GetSecondVariants(dates, pattern, expandBehaviors[7]);
     dates = ApplySetPosRules(dates, pattern);
     return dates;
 }
开发者ID:devcrafting,项目名称:DDay.iCal,代码行数:21,代码来源:RecurrencePatternEvaluator.cs

示例11: ApplySetPosRules

        /**
         * Applies BYSETPOS rules to <code>dates</code>. Valid positions are from 1 to the size of the date list. Invalid
         * positions are ignored.
         * @param dates
         */
        private List<DateTime> ApplySetPosRules(List<DateTime> dates, IRecurrencePattern pattern)
        {
            // return if no SETPOS rules specified..
            if (pattern.BySetPosition.Count == 0)
                return dates;

            // sort the list before processing..
            dates.Sort();

            List<DateTime> setPosDates = new List<DateTime>();
            int size = dates.Count;

            for (int i = 0; i < pattern.BySetPosition.Count; i++)
            {
                int pos = pattern.BySetPosition[i];
                if (pos > 0 && pos <= size)
                {
                    setPosDates.Add(dates[pos - 1]);
                }
                else if (pos < 0 && pos >= -size)
                {
                    setPosDates.Add(dates[size + pos]);
                }
            }
            return setPosDates;
        }
开发者ID:devcrafting,项目名称:DDay.iCal,代码行数:31,代码来源:RecurrencePatternEvaluator.cs

示例12: GetAbsWeekDays

        /**
         * Returns a list of applicable dates corresponding to the specified week day in accordance with the frequency
         * specified by this recurrence rule.
         * @param date
         * @param weekDay
         * @return
         */
        private List<DateTime> GetAbsWeekDays(DateTime date, IWeekDay weekDay, IRecurrencePattern pattern, bool? expand)
        {
            List<DateTime> days = new List<DateTime>();

            DayOfWeek dayOfWeek = weekDay.DayOfWeek;
            if (pattern.Frequency == FrequencyType.Daily)
            {
                if (date.DayOfWeek == dayOfWeek)
                    days.Add(date);
            }
            else if (pattern.Frequency == FrequencyType.Weekly || pattern.ByWeekNo.Count > 0)
            {
                // Rewind to the first day of the week
                while (date.DayOfWeek != pattern.FirstDayOfWeek)
                    date = date.AddDays(-1);

                // Step forward until we're on the day of week we're interested in
                while (date.DayOfWeek != dayOfWeek)
                    date = date.AddDays(1);
                
                days.Add(date);                   
            }
            else if (pattern.Frequency == FrequencyType.Monthly || pattern.ByMonth.Count > 0)
            {
                int month = date.Month;

                // construct a list of possible month days..
                date = date.AddDays(-date.Day + 1);
                while (date.DayOfWeek != dayOfWeek)
                    date = date.AddDays(1);

                while (date.Month == month)
                {
                    days.Add(date);
                    date = date.AddDays(7);
                }
            }
            else if (pattern.Frequency == FrequencyType.Yearly)
            {
                int year = date.Year;

                // construct a list of possible year days..
                date = date.AddDays(-date.DayOfYear + 1);
                while (date.DayOfWeek != dayOfWeek)
                    date = date.AddDays(1);

                while (date.Year == year)
                {
                    days.Add(date);
                    date = date.AddDays(7);
                }
            }
            return GetOffsetDates(days, weekDay.Offset);
        }
开发者ID:devcrafting,项目名称:DDay.iCal,代码行数:61,代码来源:RecurrencePatternEvaluator.cs

示例13: ThrowIfInvalid

 /// <summary>
 /// Throws the difference invalid.
 /// </summary>
 /// <param name="pattern">The pattern.</param>
 public virtual void ThrowIfInvalid(IRecurrencePattern pattern)
 {
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:7,代码来源:RecurrencePatternFactory.cs

示例14: GetMinuteVariants

        /**
         * Applies BYMINUTE rules specified in this Recur instance to the specified date list. If no BYMINUTE rules are
         * specified the date list is returned unmodified.
         * @param dates
         * @return
         */
        private List<DateTime> GetMinuteVariants(List<DateTime> dates, IRecurrencePattern pattern, bool? expand)
        {
            if (expand == null || pattern.ByMinute.Count == 0)
                return dates;

            if (expand.HasValue && expand.Value)
            {
                // Expand behavior
                List<DateTime> minutelyDates = new List<DateTime>();
                for (int i = 0; i < dates.Count; i++)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByMinute.Count; j++)
                    {
                        int minute = pattern.ByMinute[j];
                        date = date.AddMinutes(-date.Minute + minute);
                        minutelyDates.Add(date);
                    }
                }
                return minutelyDates;
            }
            else
            {
                // Limit behavior
                for (int i = dates.Count - 1; i >= 0; i--)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByMinute.Count; j++)
                    {
                        int minute = pattern.ByMinute[j];
                        if (date.Minute == minute)
                            goto Next;
                    }
                    // Remove unmatched dates
                    dates.RemoveAt(i);
                Next: ;
                }
                return dates;
            }
        }
开发者ID:devcrafting,项目名称:DDay.iCal,代码行数:46,代码来源:RecurrencePatternEvaluator.cs

示例15: GetMonthDayVariants

        /**
         * Applies BYMONTHDAY rules specified in this Recur instance to the specified date list. If no BYMONTHDAY rules are
         * specified the date list is returned unmodified.
         * @param dates
         * @return
         */
        private List<DateTime> GetMonthDayVariants(List<DateTime> dates, IRecurrencePattern pattern, bool? expand)
        {
            if (expand == null || pattern.ByMonthDay.Count == 0)
                return dates;

            if (expand.HasValue && expand.Value)
            {
                // Expand behavior
                List<DateTime> monthDayDates = new List<DateTime>();
                for (int i = 0; i < dates.Count; i++)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByMonthDay.Count; j++)
                    {
                        int monthDay = pattern.ByMonthDay[j];

                        int daysInMonth = Calendar.GetDaysInMonth(date.Year, date.Month);
                        if (Math.Abs(monthDay) <= daysInMonth)
                        {
                            // Account for positive or negative numbers
                            DateTime newDate;
                            if (monthDay > 0)
                                newDate = date.AddDays(-date.Day + monthDay);
                            else
                                newDate = date.AddDays(-date.Day + 1).AddMonths(1).AddDays(monthDay);

                            monthDayDates.Add(newDate);
                        }
                    }
                }
                return monthDayDates;
            }
            else
            {
                // Limit behavior
                for (int i = dates.Count - 1; i >= 0; i--)
                {
                    DateTime date = dates[i];
                    for (int j = 0; j < pattern.ByMonthDay.Count; j++)
                    {
                        int monthDay = pattern.ByMonthDay[j];

                        int daysInMonth = Calendar.GetDaysInMonth(date.Year, date.Month);
                        if (Math.Abs(monthDay) > daysInMonth)
                            throw new ArgumentException("Invalid day of month: " + date + " (day " + monthDay + ")");

                        // Account for positive or negative numbers
                        DateTime newDate;
                        if (monthDay > 0)
                            newDate = date.AddDays(-date.Day + monthDay);
                        else
                            newDate = date.AddDays(-date.Day + 1).AddMonths(1).AddDays(monthDay);

                        if (newDate.Day.Equals(date.Day))
                            goto Next;
                    }

                Next: ;
                    dates.RemoveAt(i);
                }                
            
                return dates;
            }
        }
开发者ID:devcrafting,项目名称:DDay.iCal,代码行数:70,代码来源:RecurrencePatternEvaluator.cs


注:本文中的IRecurrencePattern类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。