1

我目前正在研究一种解决方案,该解决方案允许用户在给定时间预订会议室,并可以选择使用我在客户端公开的日历组件使他们的会议重复发生。显然,在这种情况下,我不想允许任何冲突 - 一个房间不能重复预订。

我有一个可行的解决方案,可以检查以确保只有一个实例的事件不会与日历上的任何其他事件发生冲突,但我意识到这并不完全适用于新会议也重复发生的用例(不检查系列中的其他会议是否与其他会议冲突)。

我目前的计划是将新会议扩展到所有事件 X 时间,然后检查每个事件以确保没有冲突(如下所示):

bool available = true;

// Get all meetings for this conference room
var allMeetings = ...

// Create an ICalendar object
Calendar calendar = new Calendar();

// Add this new meeting to the calendar
var newMeetingEvent = calendar.Create<Event>();
newMeetingEvent.Start = new CalDateTime(meeting.StartTime, _timezone);
newMeetingEvent.End = new CalDateTime(meeting.EndTime, _timezone);
if (!string.IsNullOrEmpty(meeting.RecurrenceRule))
{
    newMeetingEvent.RecurrenceRules.Add(new RecurrencePattern(meeting.RecurrenceRule));
}
calendar.Events.Add(newMeetingEvent);

foreach (var m in allMeetings)
{
    // Create an ICalendar Event
    var calEvent = calendar.Create<Event>();
    calEvent.Start = new CalDateTime(m.StartTime, _timezone);
    calEvent.End = new CalDateTime(m.EndTime, _timezone);
    if (!string.IsNullOrEmpty(m.RecurrenceRule))
    {
        calEvent.RecurrenceRules.Add(new RecurrencePattern(m.RecurrenceRule));
    }
    calendar.Events.Add(calEvent);
}

// Expand the new meeting out over 10 years and check to make sure there are no collisions
var newMeetingOccurrences = newMeetingEvent.GetOccurrences(newMeetingEvent.DtStart, newMeetingEvent.DtStart.AddYears(10)).ToList();
foreach (var o in newMeetingOccurrences)
{
    var occurrences = calendar.GetOccurrences(o.Period.StartTime, o.Period.EndTime);
    if (occurrences.Count > 1)
    {
        available = false;
        break;
    }
}

有没有更好或替代的方法来检查这样的冲突?这是可行的并且是可以接受的,并且不会总是最终评估 3500 个实例,但它似乎不是最优雅的解决方案。

4

0 回答 0