Exemplo n.º 1
0
        protected override void UpdateDisplayValue()
        {
            string pattern = this.Rate == 1
                                 ? StringResources.CustomFrequency_Each
                                 : StringResources.CustomFrequency_Every;
            string scale = string.Empty;

            switch (this.Scale)
            {
            case CustomFrequencyScale.Day:
                scale = this.Rate == 1 ? StringResources.CustomFrequency_Day : StringResources.CustomFrequency_Days;
                break;

            case CustomFrequencyScale.Week:
                scale = this.Rate == 1 ? StringResources.CustomFrequency_Week : StringResources.CustomFrequency_Weeks;
                break;

            case CustomFrequencyScale.Month:
                scale = this.Rate == 1 ? StringResources.CustomFrequency_Month : StringResources.CustomFrequency_Months;
                break;

            case CustomFrequencyScale.Year:
                scale = this.Rate == 1 ? StringResources.CustomFrequency_Year : StringResources.CustomFrequency_Years;
                break;
            }
            this.displayValue           = string.Format(pattern, (this.Rate == 1 ? string.Empty : this.Rate + " ") + scale);
            this.invalidateDisplayValue = false;
        }
Exemplo n.º 2
0
 protected override void ParseValue(string value)
 {
     if (String.IsNullOrEmpty(value))
     {
         // Should occur only at initialization
         this.rate  = 1;
         this.scale = CustomFrequencyScale.Day;
     }
     else
     {
         string[] values = value.Split(valueSeparator);
         if (values.Length != 2)
         {
             throw new ArgumentException("Invalid value", "value");
         }
         if (!int.TryParse(values[0], out this.rate))
         {
             throw new ArgumentException("Invalid rate value", "value");
         }
         try
         {
             int scaleInt;
             if (!int.TryParse(values[1], out scaleInt))
             {
                 throw new ArgumentException("Invalid scale value", "value");
             }
             this.scale = (CustomFrequencyScale)scaleInt;
         }
         catch (InvalidCastException)
         {
             throw new ArgumentException("Invalid scale value", "value");
         }
     }
     this.invalidateDisplayValue = true;
 }
Exemplo n.º 3
0
        private async Task Basic_recurrence(FrequencyType frequencyType, CustomFrequencyScale scale = CustomFrequencyScale.Day, int rate = 0, bool useFixedDate = true)
        {
            var folder = this.CreateFolder("folder");

            var task = this.CreateTask("task", folder);

            task.Due           = DateSunday17Aug;
            task.FrequencyType = frequencyType;
            task.UseFixedDate  = useFixedDate;

            switch (frequencyType)
            {
            case FrequencyType.Daily:
                task.CustomFrequency = new DailyFrequency();
                break;

            case FrequencyType.Weekly:
                task.CustomFrequency = new WeeklyFrequency();
                break;

            case FrequencyType.Monthly:
                task.CustomFrequency = new MonthlyFrequency();
                break;

            case FrequencyType.Yearly:
                task.CustomFrequency = new YearlyFrequency();
                break;

            case FrequencyType.DaysOfWeek:
                task.CustomFrequency = new DaysOfWeekFrequency {
                    IsSunday = true, IsWednesday = true
                };
                break;

            case FrequencyType.OnXDayOfEachMonth:
                task.CustomFrequency = new OnXDayFrequency {
                    DayOfWeek = DayOfWeek.Sunday, RankingPosition = RankingPosition.Third
                };
                break;

            case FrequencyType.EveryXPeriod:
                task.CustomFrequency = new EveryXPeriodFrequency {
                    Scale = scale, Rate = rate
                };
                break;

            default:
                throw new ArgumentOutOfRangeException("frequencyType");
            }

            await this.SyncFull();

            AssertEx.ContainsTasks(this.Workbook, "task");
            AssertEx.IsDue(this.Workbook, 0, task.Due);
            AssertEx.IsRecurringLike(task, this.Workbook.Tasks[0]);

            Assert.AreEqual(task.UseFixedDate, this.Workbook.Tasks[0].UseFixedDate);
        }
Exemplo n.º 4
0
        private static ICustomFrequency Get2DayEveryPeriodFrequency(string toodleDoFrequency)
        {
            Regex regex = new Regex(ToodleDoConstants.RecurrencyToodleDoEveryPeriodRegex, RegexOptions.IgnoreCase);
            Match match = regex.Match(toodleDoFrequency);

            if (match == null || !match.Success)
            {
                return(null);
            }
            int    rate                = int.Parse(match.Groups["Rate"].Value);
            string scaleString         = match.Groups["Scale"].Value;
            CustomFrequencyScale scale = GetFrequencyScaleFromString(scaleString);

            if (scale == CustomFrequencyScale.None)
            {
                return(null);
            }

            if (rate <= 1)
            {
                // We've got a standard frequency
                switch (scale)
                {
                case CustomFrequencyScale.Day:
                    return(new DailyFrequency());

                case CustomFrequencyScale.Week:
                    return(new WeeklyFrequency());

                case CustomFrequencyScale.Month:
                    return(new MonthlyFrequency());

                case CustomFrequencyScale.Year:
                    return(new YearlyFrequency());

                default:
                    return(null);
                }
            }
            else
            {
                EveryXPeriodFrequency frequency = new EveryXPeriodFrequency();
                frequency.Rate  = rate;
                frequency.Scale = scale;
                return(frequency);
            }
        }