本文整理匯總了C#中ScheduleWidget.ScheduledEvents.Schedule.NextOccurrence方法的典型用法代碼示例。如果您正苦於以下問題:C# Schedule.NextOccurrence方法的具體用法?C# Schedule.NextOccurrence怎麽用?C# Schedule.NextOccurrence使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ScheduleWidget.ScheduledEvents.Schedule
的用法示例。
在下文中一共展示了Schedule.NextOccurrence方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MonthTest1
public void MonthTest1()
{
var aEvent = new Event()
{
ID = 1,
Title = "Event 1",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
MonthlyIntervalOptions = MonthlyIntervalEnum.EveryWeek,
DaysOfWeekOptions = DayOfWeekEnum.Mon | DayOfWeekEnum.Fri
};
var range = new DateRange()
{
StartDateTime = new DateTime(2013, 1, 15),
EndDateTime = new DateTime(2013, 4, 30)
};
var occurringDate = new DateTime(2013, 1, 21);
var schedule = new Schedule(aEvent);
Assert.IsTrue(schedule.IsOccurring(occurringDate));
var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2013, 1, 18), previousOccurrence.Value);
var nextOccurrence = schedule.NextOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2013, 1, 25), nextOccurrence.Value);
var occurrences = schedule.Occurrences(range);
Assert.AreEqual(30, occurrences.Count());
Assert.AreEqual(new DateTime(2013, 1, 18), occurrences.First());
Assert.AreEqual(new DateTime(2013, 4, 29), occurrences.Last());
}
示例2: RecurringScheduleNextOccurrenceTest2
public void RecurringScheduleNextOccurrenceTest2()
{
var aEvent = CreateRecurringEvent();
var schedule = new Schedule(aEvent);
Assert.IsNotNull(schedule);
var nextOccurrence = schedule.NextOccurrence(new DateTime(2012, 12, 19));
Assert.IsTrue(nextOccurrence == new DateTime(2013, 1, 2));
}
示例3: GetEventDetails
public ActionResult GetEventDetails(int id, int type = 0)
{
EventLocation l = null;
EventDetailsModel evm = null;
if (type == 0)
{
CalendarEntry e = ApplicationContext.DatabaseContext.Database.Single<CalendarEntry>("SELECT * FROM ec_events WHERE [email protected]", id);
if (e.locationId != 0)
{
l = ApplicationContext.DatabaseContext.Database.Single<EventLocation>("SELECT * FROM ec_locations WHERE id = @0", e.locationId);
}
evm = new EventDetailsModel()
{
Title = e.title,
Description = e.description,
LocationId = e.locationId,
Location = l
};
if (null != e.start)
{
evm.StartDate = ((DateTime)e.start).ToString("F", CultureInfo.CurrentCulture);
}
if (null != e.end)
{
evm.EndDate = ((DateTime)e.end).ToString("F", CultureInfo.CurrentCulture);
}
}
else if (type == 1)
{
RecurringEvent e = ApplicationContext.DatabaseContext.Database.Single<RecurringEvent>("SELECT * FROM ec_recevents WHERE [email protected]", id);
if (e.locationId != 0)
{
l = ApplicationContext.DatabaseContext.Database.Single<EventLocation>("SELECT * FROM ec_locations WHERE id = @0", e.locationId);
}
Schedule schedule = new Schedule(new Event()
{
Title = e.title,
DaysOfWeekOptions = (DayOfWeekEnum)e.day,
FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency,
MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval
});
evm = new EventDetailsModel()
{
Title = e.title,
Description = e.description,
LocationId = e.locationId,
Location = l,
StartDate = ((DateTime)schedule.NextOccurrence(DateTime.Now)).ToString("F", CultureInfo.CurrentCulture)
};
}
return PartialView("EventDetails",evm);
}
示例4: EventOptionsNextOccurrenceTest
public void EventOptionsNextOccurrenceTest()
{
var holidays = GetHolidays();
var aEvent = CreateStreetCleaningEvent();
var schedule = new Schedule(aEvent, holidays);
Assert.IsNotNull(holidays);
Assert.IsNotNull(aEvent);
Assert.IsNotNull(schedule);
var next = schedule.NextOccurrence(new DateTime(2016, 6, 6));
Assert.IsTrue(next.Equals(new DateTime(2016, 6, 20)));
Assert.IsFalse(next.Equals(new DateTime(2016, 5, 16)));
Assert.IsFalse(next.Equals(new DateTime(2016, 6, 6)));
}
示例5: RecurringScheduleExclusionsTest2
public void RecurringScheduleExclusionsTest2()
{
var aEvent = CreateRecurringEvent();
var excludedDays = new List<DateTime>()
{
new DateTime(2012, 12, 5),
new DateTime(2012, 12, 25),
new DateTime(2013, 1, 2),
new DateTime(2013, 2, 18)
};
var schedule = new Schedule(aEvent, excludedDays);
Assert.IsNotNull(schedule);
var nextOccurrence = schedule.NextOccurrence(new DateTime(2013, 1, 1));
Assert.IsTrue(nextOccurrence == new DateTime(2013, 1, 7));
}
示例6: MonthTest2
public void MonthTest2()
{
var aEvent = new Event()
{
ID = 1,
Title = "Event 2",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
RepeatInterval = 2,
MonthlyIntervalOptions = MonthlyIntervalEnum.Last,
DaysOfWeekOptions = DayOfWeekEnum.Mon | DayOfWeekEnum.Fri,
StartDateTime = new DateTime(2013, 1, 15)
};
var range = new DateRange()
{
StartDateTime = aEvent.StartDateTime.Value,
EndDateTime = new DateTime(2013, 4, 30)
};
var nonOccurringDate = new DateTime(2013, 1, 29);
var schedule = new Schedule(aEvent);
Assert.IsFalse(schedule.IsOccurring(nonOccurringDate));
var previousOccurrence = schedule.PreviousOccurrence(nonOccurringDate, range);
Assert.AreEqual(new DateTime(2013, 1, 28), previousOccurrence.Value);
var nextOccurrence = schedule.NextOccurrence(nonOccurringDate, range);
Assert.AreEqual(new DateTime(2013, 3, 25), nextOccurrence.Value);
var occurrences = schedule.Occurrences(range);
Assert.AreEqual(4, occurrences.Count());
Assert.AreEqual(new DateTime(2013, 1, 25), occurrences.First());
Assert.AreEqual(new DateTime(2013, 3, 29), occurrences.Last());
}
示例7: CanProduceOccurrences
/// <summary>
/// CanProduceOccurrences,
/// This will return true if this event is capable of generating occurrences, otherwise false.
/// For performance reasons, it is a good idea to include a limit on the number of years that are
/// searched for occurrences. (For example, 110 years).
///
/// If no limit is supplied, and the event has no end date, then this function can
/// (in the worst-case scenario) search for an occurrence until DateTime.MaxDate which is the year 9999,
/// which can take a lot of processing time.
/// </summary>
public bool CanProduceOccurrences(int? withinYears)
{
if (HasBrokenZeroOccurrenceConfiguration())
return false;
DateRange eventLimits = GetEventLimitsAsDateRange();
int daysInRange = eventLimits.GetNumberOfDaysInRange();
int maximumDaysWithoutOccurrence = RepeatInterval;
switch (FrequencyTypeOptions)
{
case FrequencyTypeEnum.Daily:
break;
case FrequencyTypeEnum.Weekly:
case FrequencyTypeEnum.EveryWeekDay:
case FrequencyTypeEnum.EveryMonWedFri:
case FrequencyTypeEnum.EveryTuTh:
maximumDaysWithoutOccurrence *= 7;
break;
case FrequencyTypeEnum.Monthly:
maximumDaysWithoutOccurrence *= 31;
break;
case FrequencyTypeEnum.Quarterly:
maximumDaysWithoutOccurrence *= 96;
break;
case FrequencyTypeEnum.Yearly:
// Leap years have 366 days.
maximumDaysWithoutOccurrence *= 366;
break;
}
if (daysInRange > maximumDaysWithoutOccurrence)
return true;
Schedule schedule = new Schedule(this);
DateTime? occurrence;
if (withinYears != null)
{
occurrence = schedule.NextOccurrence(eventLimits.StartDateTime,
new DateRange(eventLimits.StartDateTime, eventLimits.StartDateTime.SafeAddYears((int)withinYears)));
}
else
{
occurrence = schedule.NextOccurrence(eventLimits.StartDateTime,
new DateRange(eventLimits.StartDateTime, eventLimits.EndDateTime));
}
if (occurrence != null) { return true; }
return false;
}
示例8: MonthTest3
public void MonthTest3()
{
var aEvent = new Event()
{
ID = 1,
Title = "Event 3",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
DayOfMonth = 3
};
var range = new DateRange()
{
StartDateTime = new DateTime(2013, 1, 1),
EndDateTime = new DateTime(2014, 12, 31)
};
var occurringDate = new DateTime(2013, 12, 3);
var schedule = new Schedule(aEvent);
Assert.IsTrue(schedule.IsOccurring(occurringDate));
var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2013, 11, 3), previousOccurrence.Value);
var nextOccurrence = schedule.NextOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2014, 1, 3), nextOccurrence.Value);
var occurrences = schedule.Occurrences(range);
Assert.AreEqual(24, occurrences.Count());
Assert.AreEqual(new DateTime(2013, 1, 3), occurrences.First());
Assert.AreEqual(new DateTime(2014, 12, 3), occurrences.Last());
}
示例9: MonthTest5
public void MonthTest5()
{
var holidays = new UnionTE();
holidays.Add(new FixedHolidayTE(1, 25));
holidays.Add(new FloatingHolidayTE(3, DayOfWeekEnum.Mon, MonthlyIntervalEnum.First));
var aEvent = new Event()
{
ID = 1,
Title = "Event 5",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
MonthlyIntervalOptions = MonthlyIntervalEnum.EveryWeek,
DaysOfWeekOptions = DayOfWeekEnum.Mon | DayOfWeekEnum.Fri
};
var range = new DateRange()
{
StartDateTime = new DateTime(2013, 1, 15),
EndDateTime = new DateTime(2013, 4, 30)
};
var occurringDate = new DateTime(2013, 1, 21);
var schedule = new Schedule(aEvent, holidays);
Assert.IsTrue(schedule.IsOccurring(occurringDate));
Assert.IsFalse(schedule.IsOccurring(new DateTime(2013, 3, 4)));
var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2013, 1, 18), previousOccurrence.Value);
var nextOccurrence = schedule.NextOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2013, 1, 28), nextOccurrence.Value);
var occurrences = schedule.Occurrences(range);
Assert.AreEqual(28, occurrences.Count());
Assert.AreEqual(new DateTime(2013, 1, 18), occurrences.First());
Assert.AreEqual(new DateTime(2013, 4, 29), occurrences.Last());
}
示例10: MonthTest4
public void MonthTest4()
{
var aEvent = new Event()
{
ID = 1,
Title = "Event 4",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
RepeatInterval = 3,
DayOfMonth = 30,
StartDateTime = new DateTime(2013, 2, 1)
};
var range = new DateRange()
{
StartDateTime = aEvent.StartDateTime.Value,
EndDateTime = new DateTime(2014, 12, 31)
};
var occurringDate = new DateTime(2014, 2, 28);
var schedule = new Schedule(aEvent);
Assert.IsTrue(schedule.IsOccurring(occurringDate));
var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2013, 11, 30), previousOccurrence.Value);
var nextOccurrence = schedule.NextOccurrence(occurringDate, range);
Assert.AreEqual(new DateTime(2014, 5, 30), nextOccurrence.Value);
var occurrences = schedule.Occurrences(range);
Assert.AreEqual(8, occurrences.Count());
Assert.AreEqual(new DateTime(2013, 2, 28), occurrences.First());
Assert.AreEqual(new DateTime(2014, 11, 30), occurrences.Last());
}
示例11: GetEventDetails
public ActionResult GetEventDetails(int id, int calendar, int type = 0)
{
EventLocation l = null;
EventDetailsModel evm = null;
var lctrl = new LocationApiController();
if (type == 0)
{
//Fetch Event
var ectrl = new EventApiController();
var e = ectrl.GetById(id);
//If it has a location fetch it
if (e.locationId != 0)
{
l = lctrl.GetById(e.locationId);
}
evm = new EventDetailsModel()
{
Title = e.title,
LocationId = e.locationId,
Location = l,
Descriptions = e.descriptions
};
if (null != e.start)
{
evm.StartDate = ((DateTime)e.start).ToString("F", CultureInfo.CurrentCulture);
}
if (null != e.end)
{
evm.EndDate = ((DateTime)e.end).ToString("F", CultureInfo.CurrentCulture);
}
}
else if (type == 1)
{
var ectrl = new REventApiController();
var e = ectrl.GetById(id);
if (e.locationId != 0)
{
l = lctrl.GetById(e.locationId);
}
Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event()
{
Title = e.title,
DaysOfWeekOptions = (DayOfWeekEnum)e.day,
FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency,
MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval
});
evm = new EventDetailsModel()
{
Title = e.title,
LocationId = e.locationId,
Location = l,
StartDate = ((DateTime)schedule.NextOccurrence(DateTime.Now)).ToString("F", CultureInfo.CurrentCulture),
Descriptions = e.descriptions
};
}
return PartialView("EventDetails", evm);
}
示例12: MultifunctionTest1
public void MultifunctionTest1()
{
var aEvent = new Event()
{
FrequencyTypeOptions = FrequencyTypeEnum.Yearly,
RepeatInterval = 2,
StartDateTime = new DateTime(2000, 9, 27), // even years only
Anniversary = new Anniversary()
{
Month = 9,
Day = 27
}
};
// Occurs 2000,2002,2004,2006,2008,2010
aEvent.SetEndDateWithNumberOfOccurrences(6);
// Check that the ending date was set correctly.
Assert.IsTrue(aEvent.EndDateTime == new DateTime(2010, 9, 27));
// Check that the number of occurrences is retrievable.
Assert.IsTrue(aEvent.NumberOfOccurrencesThatWasLastSet == 6);
// Exclude 2000,2006,2010.
var excludedDates = new List<DateTime>
{
new DateTime(2000, 9, 27),
new DateTime(2005, 9, 27),
new DateTime(2005, 9, 28),
new DateTime(2006, 9, 27),
new DateTime(2010, 9, 27)
};
var schedule = new Schedule(aEvent, excludedDates);
// Make sure it is not occurring on excluded dates.
Assert.IsFalse(schedule.IsOccurring(new DateTime(2000, 9, 27)));
Assert.IsFalse(schedule.IsOccurring(new DateTime(2006, 9, 27)));
Assert.IsFalse(schedule.IsOccurring(new DateTime(2010, 9, 27)));
// Make sure it is not occurring outside the set range.
Assert.IsFalse(schedule.IsOccurring(new DateTime(1998, 9, 27)));
Assert.IsFalse(schedule.IsOccurring(new DateTime(2012, 9, 27)));
// Make sure it is occurring on desired dates.
Assert.IsTrue(schedule.IsOccurring(new DateTime(2002, 9, 27)));
Assert.IsTrue(schedule.IsOccurring(new DateTime(2004, 9, 27)));
Assert.IsTrue(schedule.IsOccurring(new DateTime(2008, 9, 27)));
// Check the occurrences function.
var during = new DateRange(new DateTime(1995, 1, 1),new DateTime(2015, 1, 1));
var occurrences = schedule.Occurrences(during);
Assert.IsTrue(occurrences.Count() == 3);
// Check the last occurrence date function.
var lastDate = schedule.GetLastOccurrenceDate();
Assert.IsTrue(lastDate == new DateTime(2008, 9, 27));
// Check the next occurrence (date only) function.
Assert.IsTrue(schedule.NextOccurrence(new DateTime(1995, 1, 1)) == new DateTime(2002, 9, 27));
Assert.IsTrue(schedule.NextOccurrence(new DateTime(2004, 9, 26)) == new DateTime(2004, 9, 27));
Assert.IsTrue(schedule.NextOccurrence(new DateTime(2004, 9, 27)) == new DateTime(2008, 9, 27));
Assert.IsTrue(schedule.NextOccurrence(new DateTime(2008, 9, 27)) == null);
// Check the previous occurrence (date only) function.
Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(1995, 1, 1)) == null);
Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2004, 9, 26)) == new DateTime(2002, 9, 27));
Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2004, 9, 28)) == new DateTime(2004, 9, 27));
Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2013, 9, 27)) == new DateTime(2008, 9, 27));
// Check the next occurrence ranged function.
var range1 = new DateRange(new DateTime(2004, 9, 1), new DateTime(2004, 10, 1));
var range2 = new DateRange(new DateTime(2004, 11, 1), new DateTime(2002, 9, 27));
Assert.IsTrue(schedule.NextOccurrence(new DateTime(1995, 1, 1), range1) == new DateTime(2004, 9, 27));
Assert.IsTrue(schedule.NextOccurrence(new DateTime(1995, 1, 1), range2) == null);
// Check the previous occurrence ranged function.
Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2015, 1, 1), range1) == new DateTime(2004, 9, 27));
Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2015, 1, 1), range2) == null);
}
示例13: GetIcsForCalendar
//.........這裏部分代碼省略.........
{
rp = new RecurrencePattern(FrequencyType.Weekly);
break;
}
case FrequencyTypeEnum.Yearly:
{
rp = new RecurrencePattern(FrequencyType.Yearly);
break;
}
default:
{
rp = new RecurrencePattern(FrequencyType.Monthly);
break;
}
}
switch (e.day)
{
case (int)DayOfWeekEnum.Mon:
{
rp.ByDay.Add(new WeekDay(DayOfWeek.Monday));
break;
}
case (int)DayOfWeekEnum.Tue:
{
rp.ByDay.Add(new WeekDay(DayOfWeek.Tuesday));
break;
}
case (int)DayOfWeekEnum.Wed:
{
rp.ByDay.Add(new WeekDay(DayOfWeek.Wednesday));
break;
}
case (int)DayOfWeekEnum.Thu:
{
rp.ByDay.Add(new WeekDay(DayOfWeek.Thursday));
break;
}
case (int)DayOfWeekEnum.Fri:
{
rp.ByDay.Add(new WeekDay(DayOfWeek.Friday));
break;
}
case (int)DayOfWeekEnum.Sat:
{
rp.ByDay.Add(new WeekDay(DayOfWeek.Saturday));
break;
}
case (int)DayOfWeekEnum.Sun:
{
rp.ByDay.Add(new WeekDay(DayOfWeek.Sunday));
break;
}
}
evt.RecurrenceRules.Add(rp);
Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event()
{
Title = e.title,
DaysOfWeekOptions = (DayOfWeekEnum)e.day,
FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency,
MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval
});
var occurence = Convert.ToDateTime(schedule.NextOccurrence(DateTime.Now));
evt.Start = new iCalDateTime(new DateTime(occurence.Year, occurence.Month, occurence.Day, e.start.Hour, e.start.Minute, 0));
var attendes = new List<IAttendee>();
if (e.Organisator != null && e.Organisator != 0)
{
var ms = Services.MemberService;
var member = ms.GetById(e.Organisator);
string attendee = "MAILTO:" + member.Email;
IAttendee reqattendee = new DDay.iCal.Attendee(attendee)
{
CommonName = member.Name,
Role = "REQ-PARTICIPANT"
};
attendes.Add(reqattendee);
}
if (attendes != null && attendes.Count > 0)
{
evt.Attendees = attendes;
}
}
// Create a serialization context and serializer factory.
// These will be used to build the serializer for our object.
ISerializationContext ctx = new SerializationContext();
ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory();
// Get a serializer for our object
IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer;
string output = serializer.SerializeToString(iCal);
var contentType = "text/calendar";
var bytes = Encoding.UTF8.GetBytes(output);
return File(bytes, contentType, cal.Calendarname + ".ics");
}
示例14: GetEventDetails
public ActionResult GetEventDetails(int id, int calendar, int type = 0)
{
EventLocation l = null;
EventDetailsModel evm = null;
var ms = Services.MemberService;
if (type == 0)
{
//Fetch Event
var e = EventService.GetEvent(id);
//If it has a location fetch it
if (e.locationId != 0)
{
l = LocationService.GetLocation(e.locationId);
}
evm = new EventDetailsModel()
{
CalendarId = calendar,
Title = e.title,
LocationId = e.locationId,
Location = l,
Descriptions = e.descriptions
};
if (null != e.start)
{
evm.StartDate = ((DateTime)e.start).ToString("F", CultureInfo.CurrentCulture);
}
if (null != e.end)
{
evm.EndDate = ((DateTime)e.end).ToString("F", CultureInfo.CurrentCulture);
}
if (e.Organisator != null && e.Organisator != 0)
{
var member = ms.GetById(e.Organisator);
evm.Organisator = new Organisator() { Name = member.Name, Email = member.Email };
}
}
else if (type == 1)
{
var e = RecurringEventService.GetRecurringEvent(id);
if (e.locationId != 0)
{
l = LocationService.GetLocation(e.locationId);
}
Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event()
{
Title = e.title,
DaysOfWeekOptions = (DayOfWeekEnum)e.day,
FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency,
MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval
});
evm = new EventDetailsModel()
{
CalendarId = calendar,
Title = e.title,
LocationId = e.locationId,
Location = l,
Descriptions = e.descriptions
};
if (null != e.start)
{
var start = ((DateTime)schedule.NextOccurrence(DateTime.Now));
evm.StartDate = new DateTime(start.Year, start.Month, start.Day, e.start.Hour, e.start.Minute, 0).ToString("F", CultureInfo.CurrentCulture);
}
if (null != e.end)
{
var end = ((DateTime)schedule.NextOccurrence(DateTime.Now));
evm.EndDate = new DateTime(end.Year, end.Month, end.Day, e.end.Hour, e.end.Minute, 0).ToString("F", CultureInfo.CurrentCulture);
}
if (e.Organisator != null && e.Organisator != 0)
{
var member = ms.GetById(e.Organisator);
evm.Organisator = new Organisator() { Name = member.Name, Email = member.Email };
}
}
return PartialView("EventDetails", evm);
}