コード例 #1
0
        private static IEnumerable <Event> GenerateEvents(ulong chatId, ScheduleTemplate t)
        {
            var persons    = GeneratePersons(t);
            var categories = GenerateCategories(chatId, t);

            var events = new List <Event>();
            var days   = CollectDays(t);

            foreach (var(dayOfWeek, eventTemplates) in days)
            {
                var startDay = t.FirstWeekMonday + TimeSpan.FromDays((int)dayOfWeek - 1);

                foreach (var eventTemplate in eventTemplates)
                {
                    var eventTimePeriod = t.RegularScheduleTime[eventTemplate.Order];
                    var weeks           = WeekPeriodTemplate.GetWeekRange(eventTemplate.WeekPeriods);

                    foreach (var week in weeks)
                    {
                        var weekDay    = startDay + TimeSpan.FromDays(7 * (week - 1));
                        var eventStart = weekDay.Date + eventTimePeriod.StartTime;

                        var ev = new Event
                        {
                            StartUtcDateTime = eventStart,
                            Duration         = eventTimePeriod.Duration,
                            Category         = categories[eventTemplate.CategoryIndex],
                            Description      = eventTemplate.Description,
                            Location         = eventTemplate.Location,
                            TagId            = (ulong)eventTemplate.Tag
                        };

                        ev.Participants = eventTemplate.ParticipantsIndexes.Select(pi => new EventParticipant
                        {
                            Event  = ev,
                            Person = persons[pi]
                        }).ToList();

                        ev.Organizers = eventTemplate.OrganizerIndexes.Select(oi => new EventOrganizer
                        {
                            Event  = ev,
                            Person = persons[oi]
                        }).ToList();

                        events.Add(ev);
                    }
                }
            }

            return(events);
        }
コード例 #2
0
        private static void ValidateLimitErrors(ScheduleTemplate t, ICollection <ScheduleGenerateError> errors)
        {
            if (t.CategoryNames.Count > MaxCategories)
            {
                errors.Add(ScheduleGenerateError.ExceedsLimitCategories);
            }

            if (t.Persons.Count > MaxPersons)
            {
                errors.Add(ScheduleGenerateError.ExceedsLimitPersons);
            }

            if (t.RegularScheduleTime.Count > MaxRegularScheduleCount)
            {
                errors.Add(ScheduleGenerateError.ExceedsLimitRegularSchedule);
            }

            foreach (var(_, events) in CollectDays(t))
            {
                if (events.Count > MaxEventTemplatesPerDay)
                {
                    errors.Add(ScheduleGenerateError.ExceedsLimitEventTemplatesPerDay);
                }
                else
                {
                    foreach (var eventTemplate in events)
                    {
                        if (eventTemplate.OrganizerIndexes.Count > MaxOrganizersPerEvent)
                        {
                            errors.Add(ScheduleGenerateError.ExceedsLimitOrganizersPerEvent);
                        }

                        if (eventTemplate.ParticipantsIndexes.Count > MaxParticipantsPerEvent)
                        {
                            errors.Add(ScheduleGenerateError.ExceedsLimitParticipantsPerEvent);
                        }

                        var weeksCount = WeekPeriodTemplate.GetWeekRange(eventTemplate.WeekPeriods).Count();
                        if (weeksCount > MaxEventRepeatWeekPeriod)
                        {
                            errors.Add(ScheduleGenerateError.ExceedsLimitWeeksPerEvent);
                        }
                    }
                }
            }
        }