本文整理汇总了C#中ScheduleWidget.ScheduledEvents.Schedule.Occurrences方法的典型用法代码示例。如果您正苦于以下问题:C# Schedule.Occurrences方法的具体用法?C# Schedule.Occurrences怎么用?C# Schedule.Occurrences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScheduleWidget.ScheduledEvents.Schedule
的用法示例。
在下文中一共展示了Schedule.Occurrences方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EventOptionsPreviousOccurrenceTest
public void EventOptionsPreviousOccurrenceTest()
{
var holidays = GetHolidays();
var aEvent = CreateStreetCleaningEvent();
var schedule = new Schedule(aEvent, holidays);
Assert.IsNotNull(holidays);
Assert.IsNotNull(aEvent);
Assert.IsNotNull(schedule);
var range = new DateRange()
{
StartDateTime = new DateTime(2016, 1, 1),
EndDateTime = new DateTime(2016, 12, 31)
};
foreach (var item in schedule.Occurrences(range))
{
System.Diagnostics.Debug.WriteLine(item);
}
var prev = schedule.PreviousOccurrence(new DateTime(2016, 6, 6));
Assert.IsTrue(prev.Equals(new DateTime(2016, 5, 16)));
Assert.IsFalse(prev.Equals(new DateTime(2016, 6, 6)));
Assert.IsFalse(prev.Equals(new DateTime(2016, 6, 20)));
}
示例2: AnniversaryTest2
public void AnniversaryTest2()
{
var anniversary = new Anniversary()
{
Day = 5,
Month = 6
};
var aEvent = new Event()
{
ID = 1,
Title = "Give Flowers to Wife",
Frequency = 16, // yearly
Anniversary = anniversary
};
var schedule = new Schedule(aEvent);
Assert.IsFalse(schedule.IsOccurring(new DateTime(2009, 6, 4)));
var range = new DateRange()
{
StartDateTime = new DateTime(2010, 1, 1),
EndDateTime = new DateTime(2020, 12, 31)
};
var occurrences = schedule.Occurrences(range).ToList();
Assert.IsTrue(occurrences.Count.Equals(11));
}
示例3: YearTest2
public void YearTest2()
{
var aEvent = new Event()
{
ID = 1,
Title = "Event 2",
FrequencyTypeOptions = FrequencyTypeEnum.Yearly,
Anniversary = new Anniversary()
{
Month = 9,
Day = 27
}
};
var schedule = new Schedule(aEvent);
Assert.IsTrue(schedule.IsOccurring(new DateTime(2014, 9, 27)));
Assert.IsTrue(schedule.IsOccurring(new DateTime(2015, 9, 27)));
Assert.IsTrue(schedule.IsOccurring(new DateTime(2016, 9, 27)));
var range = new DateRange()
{
StartDateTime = new DateTime(2012, 1, 1),
EndDateTime = new DateTime(2016, 12, 31)
};
var occurrences = schedule.Occurrences(range);
Assert.AreEqual(5, occurrences.Count());
Assert.AreEqual(new DateTime(2012, 9, 27), occurrences.First());
Assert.AreEqual(new DateTime(2016, 9, 27), occurrences.Last());
}
示例4: Run
/// <summary>
/// The canonical Critical Mass monthly bicycle ride
/// </summary>
public static void Run()
{
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Running monthly scenario 1.");
Console.WriteLine(Environment.NewLine);
var aEvent = new Event()
{
ID = 1,
Title = "Critical Mass",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
MonthlyIntervalOptions = MonthlyIntervalEnum.Last,
DaysOfWeekOptions = DayOfWeekEnum.Fri
};
var during = new DateRange()
{
StartDateTime = new DateTime(2013, 12, 1),
EndDateTime = new DateTime(2013, 12, 31)
};
var schedule = new Schedule(aEvent);
var dates = schedule.Occurrences(during);
foreach (var date in dates)
{
Console.WriteLine(date.ToShortDateString());
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Printed out all dates between {0} and {1}",
during.StartDateTime.ToShortDateString(),
during.EndDateTime.ToShortDateString());
}
示例5: OneTimeOnlyTest2
public void OneTimeOnlyTest2()
{
var laborDay = new DateTime(2012, 9, 1);
var aEvent = new Event()
{
ID = 1,
Title = "Labor Day Extravaganza",
Frequency = 0, // one-time only
OneTimeOnlyEventDate = laborDay,
MonthlyInterval = 0, // not applicable
DaysOfWeek = 0 // not applicable
};
var schedule = new Schedule(aEvent);
var range = new DateRange()
{
StartDateTime = new DateTime(2012, 8, 1),
EndDateTime = new DateTime(2012, 10, 1)
};
var occurrences = schedule.Occurrences(range);
var count = 0;
using (var items = occurrences.GetEnumerator())
{
while (items.MoveNext())
count++;
}
Assert.IsTrue(count > 0);
}
示例6: 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());
}
示例7: Run
public static void Run()
{
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Running daily scenario 1 with a StartDateTime value of 12/1/2013");
Console.WriteLine(Environment.NewLine);
var aEvent = new Event()
{
ID = 1,
Title = "Event 1",
Frequency = 1, // daily
MonthlyInterval = 0, // not applicable
DaysOfWeek = 127, // every day of week
StartDateTime = new DateTime(2013, 12, 1)
};
var during = new DateRange()
{
StartDateTime = new DateTime(2013, 12, 1),
EndDateTime = new DateTime(2013, 12, 31)
};
var schedule = new Schedule(aEvent);
var dates = schedule.Occurrences(during);
foreach (var date in dates)
{
Console.WriteLine(date.ToShortDateString());
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Printed out all dates between {0} and {1}",
during.StartDateTime.ToShortDateString(),
during.EndDateTime.ToShortDateString());
}
示例8: TestMontlyCalendar
public void TestMontlyCalendar()
{
var aEvent = new Event()
{
ID = 1,
Title = "Critical Mass",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
MonthlyIntervalOptions = MonthlyIntervalEnum.First,
DaysOfWeekOptions = DayOfWeekEnum.Fri
}; var schedule = new Schedule(aEvent);
var range = new DateRange()
{
StartDateTime = DateTime.Now,
EndDateTime = DateTime.Now.AddYears(1)
};
var occurrences = schedule.Occurrences(range);
}
示例9: 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());
}
示例10: DailyEventTest7
public void DailyEventTest7()
{
// FirstDateTime should be optional for daily events
var aEvent = new Event()
{
ID = 1,
Title = "Event 1",
Frequency = 1, // daily
MonthlyInterval = 0, // not applicable
DaysOfWeek = 127 // every day of week
};
var schedule = new Schedule(aEvent);
var during = new DateRange()
{
StartDateTime = DateTime.Now.AddDays(-30),
EndDateTime = DateTime.Now.AddDays(30)
};
var occurrences = schedule.Occurrences(during);
Assert.IsTrue(occurrences.Any());
}
示例11: GetRecurringEvents
private List<EventsOverviewModel> GetRecurringEvents(int id, int start = 0, int end = 0)
{
var db = UmbracoContext.Application.DatabaseContext.Database;
//Handle recurring events
List<EventsOverviewModel> events = new List<EventsOverviewModel>();
DateTime startDate = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
startDate = startDate.AddSeconds(start);
DateTime endDate = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
endDate = endDate.AddSeconds(end);
DateRange range = new DateRange();
range.StartDateTime = startDate;
range.EndDateTime = endDate;
var calendar = db.SingleOrDefault<ECalendar>(id);
var recurring_events = db.Query<RecurringEvent>("SELECT * FROM ec_recevents WHERE calendarId = @0 ORDER BY id DESC", id).ToList();
foreach (var e in recurring_events)
{
var schedule = new Schedule(
new ScheduleWidget.ScheduledEvents.Event()
{
Title = e.title,
ID = e.Id,
DaysOfWeekOptions = (DayOfWeekEnum)e.day,
FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency,
MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval
});
foreach (var tmp in schedule.Occurrences(range))
{
events.Add(new EventsOverviewModel()
{
title = e.title,
id = e.Id,
allDay = e.allDay,
//description = e.description,
start = tmp,
type = EventType.Recurring,
color = !String.IsNullOrEmpty(calendar.Color) ? calendar.Color : "",
calendar = e.calendarId
});
}
}
return events;
}
示例12: CreateNewEventReOcurring
//.........这里部分代码省略.........
{
RDN.Library.DataModels.Calendar.CalendarEventReoccuringGroup newGroup = new RDN.Library.DataModels.Calendar.CalendarEventReoccuringGroup();
newGroup.Group = group;
newGroup.Event = ev;
if (ev.Groups.Where(x => x.Group.Id == id).FirstOrDefault() == null)
ev.Groups.Add(newGroup);
}
}
ev.AllowSelfCheckIn = AllowSelfCheckIn;
ev.Location = dc.Locations.Include("Contact").Include("Contact.Addresses").Include("Contact.Communications").Where(x => x.LocationId == locationId).FirstOrDefault();
ev.Name = eventName;
ev.Notes = notes;
ev.TicketUrl = ticketUrl;
ev.Link = link;
ev.IsPublic = isEventPublic;
ev.LastDateEventsWereCreated = DateTime.UtcNow.AddMonths(-3);
ev.EventType = dc.CalendarEventTypes.Where(x => x.CalendarEventTypeId == selectedEventTypeId).FirstOrDefault();
dc.CalendarEventsReocurring.Add(ev);
ev.Calendar.CalendarEventsReocurring.Add(ev);
int cc = dc.SaveChanges();
var schedule = new Schedule(aEvent);
var range = new DateRange()
{
StartDateTime = ev.StartReocurring
};
//date is null if the event is never ending.
if (ev.EndReocurring.HasValue)
range.EndDateTime = ev.EndReocurring.Value;
else
range.EndDateTime = endDate.AddMonths(1);
foreach (var date in schedule.Occurrences(range))
{
DateTime endDateEv = new DateTime();
DateTime startDateEv = new DateTime();
if (!ev.IsInUTCTime)
{
startDateEv = new DateTime(date.Year, date.Month, date.Day, ev.StartDate.Hour, ev.StartDate.Minute, ev.StartDate.Second);
endDateEv = new DateTime(date.Year, date.Month, date.Day, ev.EndDate.Hour, ev.EndDate.Minute, ev.EndDate.Second);
}
else
{
//we have to create a temp dates so we can add the timezone information without going back a day
//if the time being used is on the border.
//without the tempdates 1/4/2013 7pm turned into 1/3/2013 7pm because the timezones didn't account for the
//fact the dates were already in utc.
var startTempDate = new DateTime(date.Year, date.Month, date.Day, ev.StartDate.Hour, ev.StartDate.Minute, ev.StartDate.Second) + new TimeSpan(ev.Calendar.TimeZone, 0, 0);
var endTempDate = new DateTime(date.Year, date.Month, date.Day, ev.EndDate.Hour, ev.EndDate.Minute, ev.EndDate.Second) + new TimeSpan(ev.Calendar.TimeZone, 0, 0);
startDateEv = new DateTime(date.Year, date.Month, date.Day, startTempDate.Hour, startTempDate.Minute, startTempDate.Second);
endDateEv = new DateTime(date.Year, date.Month, date.Day, endTempDate.Hour, endTempDate.Minute, endTempDate.Second);
}
Guid calItemId = CalendarEventFactory.CreateNewEvent(ev.Calendar.CalendarId, startDateEv, endDateEv, locationId, ev.Name, ev.Link, ev.Notes, ev.AllowSelfCheckIn, ev.IsPublic, true, ev.CalendarItemId, ev.EventType.CalendarEventTypeId, false, ev.TicketUrl, hexColor, new List<long>(), memberId);
}
if (broadcastEvent)
{
List<Guid> memIds = new List<Guid>();
var memberCreated = MemberCache.GetMemberDisplay(memberId);
示例13: UpdateEventReOcurring
//.........这里部分代码省略.........
}
//adds any groups not in list.
foreach (var id in groupIds)
{
var group = dc.LeagueGroups.Where(x => x.Id == id).FirstOrDefault();
if (group != null)
{
if (ev.Groups.Where(x => x.Group.Id == id).FirstOrDefault() == null)
{
RDN.Library.DataModels.Calendar.CalendarEventReoccuringGroup newGroup = new RDN.Library.DataModels.Calendar.CalendarEventReoccuringGroup();
newGroup.Group = group;
newGroup.Event = ev;
ev.Groups.Add(newGroup);
editGroupsOfAllEvents = true;
}
}
}
ev.EventType = dc.CalendarEventTypes.Where(x => x.CalendarEventTypeId == selectedEventTypeId).FirstOrDefault();
if (editColorsOfAllEvents)
{
foreach (var eventReoccure in ev.ReoccuringEvents.Where(x => x.IsRemovedFromCalendar == false))
{
eventReoccure.Color = ev.Color;
}
}
if (editGroupsOfAllEvents)
{
foreach (var eventReoccure in ev.ReoccuringEvents.Where(x => x.IsRemovedFromCalendar == false))
{
UpdateGroupsOfEvent(groupIds, dc, eventReoccure);
}
}
int c = dc.SaveChanges();
if (editAllEventDates)
{
var eventsReoccur = ev.ReoccuringEvents.Where(x => x.Attendees.Count == 0 && x.IsRemovedFromCalendar == false).ToList();
foreach (var eve in eventsReoccur)
{
eve.IsRemovedFromCalendar = true;
}
var schedule = new Schedule(aEvent);
var range = new DateRange()
{
StartDateTime = ev.StartReocurring
};
//date is null if the event is never ending.
if (ev.EndReocurring.HasValue)
range.EndDateTime = ev.EndReocurring.Value;
else
range.EndDateTime = endDate.AddMonths(1);
foreach (var date in schedule.Occurrences(range))
{
DateTime endDateEv = new DateTime();
DateTime startDateEv = new DateTime();
if (!ev.IsInUTCTime)
{
startDateEv = new DateTime(date.Year, date.Month, date.Day, ev.StartDate.Hour, ev.StartDate.Minute, ev.StartDate.Second);
endDateEv = new DateTime(date.Year, date.Month, date.Day, ev.EndDate.Hour, ev.EndDate.Minute, ev.EndDate.Second);
}
else
{
//we have to create a temp dates so we can add the timezone information without going back a day
//if the time being used is on the border.
//without the tempdates 1/4/2013 7pm turned into 1/3/2013 7pm because the timezones didn't account for the
//fact the dates were already in utc.
var startTempDate = new DateTime(date.Year, date.Month, date.Day, ev.StartDate.Hour, ev.StartDate.Minute, ev.StartDate.Second) + new TimeSpan(ev.Calendar.TimeZone, 0, 0);
var endTempDate = new DateTime(date.Year, date.Month, date.Day, ev.EndDate.Hour, ev.EndDate.Minute, ev.EndDate.Second) + new TimeSpan(ev.Calendar.TimeZone, 0, 0);
startDateEv = new DateTime(date.Year, date.Month, date.Day, startTempDate.Hour, startTempDate.Minute, startTempDate.Second);
endDateEv = new DateTime(date.Year, date.Month, date.Day, endTempDate.Hour, endTempDate.Minute, endTempDate.Second);
}
//only add more dates to dates in the future. No need to go back in time.
if (startDateEv > DateTime.UtcNow)
CalendarEventFactory.CreateNewEvent(ev.Calendar.CalendarId, startDateEv, endDateEv, locationId, ev.Name, ev.Link, ev.Notes, ev.AllowSelfCheckIn, ev.IsPublic, true, ev.CalendarItemId, ev.EventType.CalendarEventTypeId, false, ev.TicketUrl, hexColor, new List<long>(), memId);
}
}
c = dc.SaveChanges();
}
catch (Exception exception)
{
ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: startDate + " " + endDate + " " + endsOnDateReoccuring + " " + endsWhen.ToString());
}
}
return reoccurringEventId;
}
示例14: GetRecurringEvents
private List<EventsOverviewModel> GetRecurringEvents(int id, string culture, DateTime start, DateTime end)
{
var db = UmbracoContext.Application.DatabaseContext.Database;
//Handle recurring events
List<EventsOverviewModel> events = new List<EventsOverviewModel>();
DateTime startDate = start;
DateTime endDate = end;
DateRange range = new DateRange();
range.StartDateTime = startDate;
range.EndDateTime = endDate;
var calendar = db.SingleOrDefault<ECalendar>(id);
var recurring_events = db.Query<RecurringEvent>("SELECT * FROM ec_recevents WHERE calendarId = @0 ORDER BY id DESC", id).ToList();
foreach (var e in recurring_events)
{
var schedule = new Schedule(
new ScheduleWidget.ScheduledEvents.Event()
{
Title = e.title,
ID = e.Id,
DaysOfWeekOptions = (DayOfWeekEnum)e.day,
FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency,
MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval
});
foreach (var tmp in schedule.Occurrences(range))
{
List<EventDescription> descriptions = db.Query<EventDescription>("SELECT * FROM ec_eventdescriptions WHERE eventid = @0 AND calendarid = @1 AND type = @2", e.Id, e.calendarId, (int)EventType.Recurring).ToList();
EventDescription currentDescription = descriptions.SingleOrDefault(x => x.CultureCode.ToLower() == culture);
string description = String.Empty;
System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("<[^>]*>");
if (null != currentDescription && null != currentDescription.Content)
{
description = rx.Replace(currentDescription.Content, "");
description = description.Substring(0, (description.Length > 150) ? 150 : description.Length) + "...";
}
events.Add(new EventsOverviewModel()
{
title = e.title,
id = e.Id,
allDay = e.allDay,
description = description,
start = tmp,
type = EventType.Recurring,
color = !String.IsNullOrEmpty(calendar.Color) ? calendar.Color : "",
textColor = !String.IsNullOrEmpty(calendar.TextColor) ? calendar.TextColor : "",
categories = e.categories,
calendar = e.calendarId
});
}
}
return events;
}
示例15: QuarterlyOccurancesSingleEventCorrect
public void QuarterlyOccurancesSingleEventCorrect()
{
var aEvent = new Event()
{
ID = 1,
Title = "Quarterly, Third Quarter, Second Month, Second Week, Wednesday",
Frequency = 8, // quarterly
QuarterInterval = 4, // third quarter
QuarterlyInterval = 2, // 2nd month of quarter
MonthlyInterval = 2, // 2nd week of the month
DaysOfWeek = 8 // Wednesday
};
var schedule = new Schedule(aEvent);
// test # of occurrances
DateTime start = new DateTime(2014, 1, 1);
var occurances = schedule.Occurrences(
new DateRange { StartDateTime = start, EndDateTime = new DateTime(2014, 12, 31) });
Assert.IsTrue(occurances.Count() == 1, "expect only 1 occurance");
var occurances2 = schedule.Occurrences(
new DateRange { StartDateTime = start, EndDateTime = new DateTime(2015, 12, 31) });
Assert.IsTrue(occurances2.Count() == 2, "expect 2 occurances");
}