Exemplo n.º 1
0
        public IEnumerable <Approval_Inspection> GenerateInspections(TaskGeneratorConfig taskGeneratorConfig)
        {
            if (!taskGeneratorConfig.Repeat)
            {
                return(new[]
                {
                    CreateInspection(taskGeneratorConfig.Begin, taskGeneratorConfig.End, taskGeneratorConfig.IsAllDay, taskGeneratorConfig.ConditionInspections, taskGeneratorConfig.ResponsibleSubject,
                                     taskGeneratorConfig.Series)
                });
            }

            IEnumerable <DateTime> dates;

            switch (taskGeneratorConfig.Cycle)
            {
            case 0:
            {
                dates = GenerateDailyRecurrence(taskGeneratorConfig.Begin, taskGeneratorConfig.RecurrenceInterval, taskGeneratorConfig.EndsWithDate, taskGeneratorConfig.RepeatUntilDate,
                                                taskGeneratorConfig.NumberOfRecurrences);
                break;
            }

            case 1:
            {
                dates = GenerateWeeklyRecurrence(taskGeneratorConfig.Begin, taskGeneratorConfig.RecurrenceInterval, taskGeneratorConfig.EndsWithDate, taskGeneratorConfig.RepeatUntilDate,
                                                 taskGeneratorConfig.NumberOfRecurrences, taskGeneratorConfig.WeekDays);
                break;
            }

            case 2:
            {
                dates = GenerateMonthlyRecurrence(taskGeneratorConfig.Begin, taskGeneratorConfig.RecurrenceInterval, taskGeneratorConfig.EndsWithDate, taskGeneratorConfig.RepeatUntilDate,
                                                  taskGeneratorConfig.NumberOfRecurrences, taskGeneratorConfig.IsWeekdayRecurrence);
                break;
            }

            case 3:
            {
                dates = GenerateYearlyRecurrence(taskGeneratorConfig.Begin, taskGeneratorConfig.RecurrenceInterval, taskGeneratorConfig.EndsWithDate, taskGeneratorConfig.RepeatUntilDate,
                                                 taskGeneratorConfig.NumberOfRecurrences);
                break;
            }

            default:
                throw new InvalidOperationException();
            }

            var range = taskGeneratorConfig.End.Subtract(taskGeneratorConfig.Begin);

            return
                (dates.Select(date => CreateInspection(date, date.Add(range), taskGeneratorConfig.IsAllDay, taskGeneratorConfig.ConditionInspections, taskGeneratorConfig.ResponsibleSubject, taskGeneratorConfig.Series)));
        }
Exemplo n.º 2
0
        public IEnumerable <Approval_Inspection> GenerateInspections(ObservableCollection <ConditionInspection> conditionInspections, ResponsibleSubject responsibleSubject, Series series, DayOfWeek[] weekDays)
        {
            var taskGeneratorConfig = new TaskGeneratorConfig();

            taskGeneratorConfig.ConditionInspections = conditionInspections;

            taskGeneratorConfig.Series             = series;
            taskGeneratorConfig.ResponsibleSubject = responsibleSubject;
            taskGeneratorConfig.WeekDays           = weekDays;

            taskGeneratorConfig.Begin               = series.Begin;
            taskGeneratorConfig.End                 = series.End;
            taskGeneratorConfig.Repeat              = series.Repeat;
            taskGeneratorConfig.RecurrenceInterval  = series.RecurrenceInterval;
            taskGeneratorConfig.EndsWithDate        = series.EndsWithDate;
            taskGeneratorConfig.RepeatUntilDate     = series.RepeatUntilDate;
            taskGeneratorConfig.NumberOfRecurrences = series.NumberOfRecurrences;
            taskGeneratorConfig.IsWeekdayRecurrence = series.IsWeekdayRecurrence;
            taskGeneratorConfig.IsAllDay            = series.IsAllDay;
            taskGeneratorConfig.Cycle               = series.Cycle;

            return(GenerateInspections(taskGeneratorConfig));
        }