public async void ExportToCalendar(object item) { var animeItemViewModel = item as AnimeItemViewModel; DayOfWeek day = Utilities.StringToDay(animeItemViewModel.TopLeftInfoBind); var date = GetNextWeekday(DateTime.Today, day); var timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now); var startTime = new DateTimeOffset(date.Year, date.Month, date.Day, 0, 0, 0, timeZoneOffset); var appointment = new Appointment(); appointment.StartTime = startTime; appointment.Subject = "Anime - " + animeItemViewModel.Title; appointment.AllDay = true; var recurrence = new AppointmentRecurrence(); recurrence.Unit = AppointmentRecurrenceUnit.Weekly; recurrence.Interval = 1; recurrence.DaysOfWeek = UWPUtilities.DayToAppointementDay(day); if (animeItemViewModel.EndDate != AnimeItemViewModel.InvalidStartEndDate) { var endDate = DateTime.Parse(animeItemViewModel.EndDate); recurrence.Until = endDate; } else if (animeItemViewModel.StartDate != AnimeItemViewModel.InvalidStartEndDate && animeItemViewModel.AllEpisodes != 0) { var weeksPassed = (DateTime.Today - DateTime.Parse(animeItemViewModel.StartDate)).Days / 7; if (weeksPassed < 0) { return; } var weeks = (uint)(animeItemViewModel.AllEpisodes - weeksPassed); recurrence.Until = DateTime.Today.Add(TimeSpan.FromDays(weeks * 7)); } else if (animeItemViewModel.AllEpisodes != 0) { var epsLeft = animeItemViewModel.AllEpisodes - animeItemViewModel.MyEpisodes; recurrence.Until = DateTime.Today.Add(TimeSpan.FromDays(epsLeft * 7)); } else { var msg = new MessageDialog("Not enough data to create event."); await msg.ShowAsync(); return; } appointment.Recurrence = recurrence; var rect = new Rect(new Point(Window.Current.Bounds.Width / 2, Window.Current.Bounds.Height / 2), new Size()); try { await AppointmentManager.ShowAddAppointmentAsync(appointment, rect, Placement.Default); } catch (Exception) { //appointpent is already being created } }
public async void ExportToCalendar(object item) { var animeItemViewModel = item as AnimeItemViewModel; DayOfWeek day = Utilities.StringToDay(animeItemViewModel.TopLeftInfoBind); var date = GetNextWeekday(DateTime.Today, day); var timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now); var startTime = new DateTimeOffset(date.Year, date.Month, date.Day, 0, 0, 0, timeZoneOffset); var appointment = new Appointment(); appointment.StartTime = startTime; appointment.Subject = "Anime - " + animeItemViewModel.Title; appointment.AllDay = true; var recurrence = new AppointmentRecurrence(); recurrence.Unit = AppointmentRecurrenceUnit.Weekly; recurrence.Interval = 1; recurrence.DaysOfWeek = UWPUtilities.DayToAppointementDay(day); if (animeItemViewModel.EndDate != AnimeItemViewModel.InvalidStartEndDate) { var endDate = DateTime.Parse(animeItemViewModel.EndDate); recurrence.Until = endDate; } else if (animeItemViewModel.StartDate != AnimeItemViewModel.InvalidStartEndDate && animeItemViewModel.AllEpisodes != 0) { var weeksPassed = (DateTime.Today - DateTime.Parse(animeItemViewModel.StartDate)).Days / 7; if (weeksPassed < 0) return; var weeks = (uint)(animeItemViewModel.AllEpisodes - weeksPassed); recurrence.Until = DateTime.Today.Add(TimeSpan.FromDays(weeks * 7)); } else if (animeItemViewModel.AllEpisodes != 0) { var epsLeft = animeItemViewModel.AllEpisodes - animeItemViewModel.MyEpisodes; recurrence.Until = DateTime.Today.Add(TimeSpan.FromDays(epsLeft * 7)); } else { var msg = new MessageDialog("Not enough data to create event."); await msg.ShowAsync(); return; } appointment.Recurrence = recurrence; var rect = new Rect(new Point(Window.Current.Bounds.Width / 2, Window.Current.Bounds.Height / 2), new Size()); try { await AppointmentManager.ShowAddAppointmentAsync(appointment, rect, Placement.Default); } catch (Exception) { //appointpent is already being created } }
public AppointmentSchedule(AppointmentItem appointment) { _appointment = appointment; if (appointment.IsRecurring && appointment.RecurrenceState == OlRecurrenceState.olApptMaster) { try { Recurrence = new AppointmentRecurrence(_appointment.GetRecurrencePattern()); } catch (ArgumentOutOfRangeException ex) { Logger.Warning(ex.Message); } } }
private async Task AddAppointment() { var now = DateTimeOffset.Now; var appointment = new Appointment { Subject = "Appointment", StartTime = now, Duration = TimeSpan.FromMinutes(30), }; await _appointmentCalendar.SaveAppointmentAsync(appointment); if (appointment.LocalId != string.Empty) { _appointments.Add(appointment); } var appointmentRecurrence = new AppointmentRecurrence { Unit = AppointmentRecurrenceUnit.Weekly, Interval = 1, DaysOfWeek = (AppointmentDaysOfWeek)(now.DayOfWeek + 1) }; appointment = new Appointment { Subject = "Appointment with recurrence", StartTime = now.AddHours(1), Duration = TimeSpan.FromMinutes(30), Recurrence = appointmentRecurrence }; await _appointmentCalendar.SaveAppointmentAsync(appointment); if (appointment.LocalId != string.Empty) { _appointments.Add(appointment); } }
/// <summary> /// ExportExDate /// </summary> /// <param name="recur"></param> private void ExportExDate(AppointmentRecurrence recur) { if (recur.SkippedRecurrences != null) { foreach (DateTime date in recur.SkippedRecurrences) ExportLine("EXDATE:" + GetUtcDate(date)); } }
/// <summary> /// AddRRuleRangeInfo /// </summary> /// <param name="sb"></param> /// <param name="recur"></param> private void AddRRuleRangeInfo(StringBuilder sb, AppointmentRecurrence recur) { switch (recur.RangeLimitType) { case eRecurrenceRangeLimitType.RangeNumberOfOccurrences: if (recur.RangeNumberOfOccurrences > 0) sb.Append(";COUNT=" + (recur.RangeNumberOfOccurrences + 1).ToString()); break; case eRecurrenceRangeLimitType.RangeEndDate: sb.Append(";UNTIL=" + GetUtcDate(recur.RangeEndDate)); break; } if (recur.RecurrenceStartDate != DateTime.MinValue && recur.RecurrenceStartDate != recur.Appointment.StartTime) ExportLine("X-DNB-RECSTARTDATE=" + GetUtcDate(recur.RecurrenceStartDate)); }
/// <summary> /// ExportMonthlyRRule /// </summary> /// <param name="recur"></param> private void ExportMonthlyRRule(AppointmentRecurrence recur) { StringBuilder sb = new StringBuilder(); sb.Append("RRULE:FREQ=MONTHLY"); AddRRuleInterval(sb, recur.Monthly.RepeatInterval); if (recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.None) sb.AppendFormat("{0}{1:D}", ";BYMONTHDAY=", recur.Monthly.RepeatOnDayOfMonth); else AddRRuleByDay(sb, recur.Monthly.RepeatOnRelativeDayInMonth, recur.Monthly.RelativeDayOfWeek); AddRRuleRangeInfo(sb, recur); ExportLine(sb.ToString()); }
/// <summary> /// ExportWeeklyRRule /// </summary> /// <param name="recur"></param> private void ExportWeeklyRRule(AppointmentRecurrence recur) { StringBuilder sb = new StringBuilder(); sb.Append("RRULE:FREQ=WEEKLY"); AddRRuleInterval(sb, recur.Weekly.RepeatInterval); if (recur.Weekly.RepeatOnDaysOfWeek != eDayOfWeekRecurrence.None) AddRRuleByDay(sb, recur.Weekly.RepeatOnDaysOfWeek); AddRRuleRangeInfo(sb, recur); ExportLine(sb.ToString()); }
/// <summary> /// ExportDailyRRule /// </summary> /// <param name="recur"></param> private void ExportDailyRRule(AppointmentRecurrence recur) { StringBuilder sb = new StringBuilder(); sb.Append("RRULE:FREQ=DAILY"); AddRRuleInterval(sb, recur.Daily.RepeatInterval); AddRRuleByDay(sb, recur.Daily.RepeatOnDaysOfWeek); AddRRuleRangeInfo(sb, recur); ExportLine(sb.ToString()); }
public ActionResult CreateSchedule(AppointmentRecurrence appointment) { var _calendarUtility = new Calculator(); var r = Request["RecType"]; var errors = new List <string>(); //set daily by default var rType = RecurrenceCalculator.RecurrenceType.Daily; if (appointment.RecType == "weekly") { rType = RecurrenceType.Weekly; } else if (appointment.RecType == "monthly") { rType = RecurrenceType.Monthly; } else if (appointment.RecType == "yearly") { rType = RecurrenceType.Yearly; } else if (appointment.RecType == "daily") { rType = RecurrenceCalculator.RecurrenceType.Daily; } else { errors.Add("You must select a schedule type from the tabs above!"); } if (appointment.Interval < 1) { errors.Add("There must be at least one interval!"); } Appointment a = null; if (rType == RecurrenceType.Yearly) { var dayOfMonth = appointment.StartDate.Day; var monthOfYear = appointment.StartDate.Month; a = new Appointment() { RecurrenceType = rType, Interval = appointment.Interval, StartDate = appointment.StartDate, Occurrences = appointment.Occurrences, DayOfMonth = dayOfMonth, MonthOfYear = monthOfYear }; } else if (rType == RecurrenceType.Monthly) { var dayOfMonth = appointment.StartDate.Day; a = new Appointment() { RecurrenceType = rType, Interval = appointment.Interval, StartDate = appointment.StartDate, Occurrences = appointment.Occurrences, //Sunday = false, //Monday = true, //Tuesday = true, //Wednesday = true, //Thursday = true, //Friday = true, //Saturday = false, DayOfMonth = dayOfMonth //Day = 5 }; } else if (rType == RecurrenceType.Weekly) { a = new Appointment() { RecurrenceType = rType, Interval = appointment.Interval, StartDate = appointment.StartDate, Occurrences = appointment.Occurrences, Sunday = appointment.Sunday, Monday = appointment.Monday, Tuesday = appointment.Tuesday, Wednesday = appointment.Wednesday, Thursday = appointment.Thursday, Friday = appointment.Friday, Saturday = appointment.Saturday }; } else //daily with acceptable days { a = new Appointment() { RecurrenceType = rType, Interval = appointment.Interval, StartDate = appointment.StartDate, Occurrences = appointment.Occurrences, Sunday = appointment.Sunday, Monday = appointment.Monday, Tuesday = appointment.Tuesday, Wednesday = appointment.Wednesday, Thursday = appointment.Thursday, Friday = appointment.Friday, Saturday = appointment.Saturday }; } try { var type = appointment.RecType; if (type == "monthly" || type == "yearly") { type = type + " on " + appointment.StartDate.Day + " of every month"; } var occurences = _calendarUtility.CalculateOccurrences(a); //create schedule record var s = new mc_schedule { date_created = DateTime.Now, date_modified = DateTime.Now, deleted = false, interval = appointment.Interval.ToString(), paused = false, report_id = appointment.ReportId, start_datetime = appointment.StartDate, user_created = "", user_modified = "", sunday = appointment.Sunday, monday = appointment.Monday, tuesday = appointment.Tuesday, wednesday = appointment.Wednesday, thursday = appointment.Thursday, friday = appointment.Friday, saturday = appointment.Saturday, occurences = appointment.Occurrences, schedule_expire_datetime = occurences.Max(x => x), job_type_code = appointment.RecType, job_type = type }; db.mc_schedule.Add(s); db.SaveChanges(); //create jobs foreach (var o in occurences) { var j = new mc_scheduled_jobs { cancel = false, complete = false, date_created = DateTime.Now, deleted = false, in_progress = false, job_type = "scheduled", report_id = appointment.ReportId, schedule_id = s.id, start_datetime = o }; db.mc_scheduled_jobs.Add(j); } db.SaveChanges(); } catch (Exception ex) { errors.Add("You must choose at least one day of the week when you occurence can run!"); foreach (var e in errors) { ModelState.AddModelError(string.Empty, e); } return(View(appointment)); } return(RedirectToAction("Details", "Reports", new { id = appointment.ReportId })); }
private void AddMonthlyByDay(CalendarModel model, Appointment app, DayOfWeek dayOfWeek, int byDay, VEventData evData) { AppointmentRecurrence recur = new AppointmentRecurrence(); recur.RecurrenceType = eRecurrencePatternType.Monthly; recur.Monthly.RepeatInterval = evData.RecurRule.Interval; recur.Monthly.RelativeDayOfWeek = dayOfWeek; recur.Monthly.RepeatOnRelativeDayInMonth = GetRelativeDay(byDay); if (app.Recurrence != null) { app = app.Copy(); app.StartTime = evData.StartTime; app.EndTime = evData.EndTime; evData.UidApps.Add(app); } model.Appointments.Add(app); DateTime oldStartTime = app.StartTime; SetNewByDayAppStartTime(app, dayOfWeek, byDay); if (app.StartTime < oldStartTime) recur.SkippedRecurrences.Add(app.StartTime); ProcessRecurrenceRange(app, recur, evData); app.Recurrence = recur; }
/// <summary> /// Processes Weekly recurrences /// </summary> /// <param name="model"></param> /// <param name="app"></param> /// <param name="evData"></param> private void ProcessWeeklyRecurrence(CalendarModel model, Appointment app, VEventData evData) { AppointmentRecurrence recur = new AppointmentRecurrence(); recur.RecurrenceType = eRecurrencePatternType.Weekly; recur.Weekly.RepeatInterval = evData.RecurRule.Interval; recur.Weekly.RepeatOnDaysOfWeek = (evData.RecurRule.ByDays == eDayOfWeekRecurrence.None) ? GetRecurrenceDay(app.StartTime) : evData.RecurRule.ByDays; ProcessRecurrenceRange(app, recur, evData); app.Recurrence = recur; model.Appointments.Add(app); }
/// <summary> /// Processes Daily recurrences /// </summary> /// <param name="model"></param> /// <param name="app"></param> /// <param name="evData"></param> private void ProcessDailyRecurrence(CalendarModel model, Appointment app, VEventData evData) { AppointmentRecurrence recur = new AppointmentRecurrence(); recur.RecurrenceType = eRecurrencePatternType.Daily; recur.Daily.RepeatInterval = evData.RecurRule.Interval; switch (evData.RecurRule.ByDays) { case eDayOfWeekRecurrence.WeekDays: recur.Daily.RepeatOnDaysOfWeek = eDailyRecurrenceRepeat.WeekDays; break; case eDayOfWeekRecurrence.WeekendDays: recur.Daily.RepeatOnDaysOfWeek = eDailyRecurrenceRepeat.WeekendDays; break; } ProcessRecurrenceRange(app, recur, evData); app.Recurrence = recur; model.Appointments.Add(app); }
/// <summary> /// Processes Recurrence range values /// </summary> /// <param name="app"></param> /// <param name="recur"></param> /// <param name="evData"></param> private void ProcessRecurrenceRange( Appointment app, AppointmentRecurrence recur, VEventData evData) { recur.RecurrenceStartDate = (evData.RecStartDate != DateTime.MinValue) ? evData.RecStartDate : app.StartTime; if (evData.RecurRule.Count > 0) { recur.RangeLimitType = eRecurrenceRangeLimitType.RangeNumberOfOccurrences; recur.RangeNumberOfOccurrences = evData.RecurRule.Count - 1; } if (evData.RecurRule.Until != DateTime.MinValue) { recur.RangeLimitType = eRecurrenceRangeLimitType.RangeEndDate; recur.RangeEndDate = evData.RecurRule.Until; } if (evData.ExDates != null) { foreach (DateTime date in evData.ExDates) { if (date >= app.StartTime) { if (IsSkippableDate(app, date, evData) == true) recur.SkippedRecurrences.Add(date); } } } }
private void AddYearlyByMonthDay(CalendarModel model, Appointment app, int byMonth, int byMonthDay, VEventData evData) { AppointmentRecurrence recur = new AppointmentRecurrence(); recur.RecurrenceType = eRecurrencePatternType.Yearly; recur.Yearly.RepeatOnMonth = byMonth; recur.Yearly.RepeatOnRelativeDayInMonth = eRelativeDayInMonth.None; recur.Yearly.RepeatOnDayOfMonth = byMonthDay; if (app.Recurrence != null) { app = app.Copy(); evData.UidApps.Add(app); } model.Appointments.Add(app); int day = DateTime.DaysInMonth(app.StartTime.Year, byMonth); if (day < byMonthDay) byMonthDay = day; DateTime startTime = new DateTime(app.StartTime.Year, byMonth, byMonthDay, app.StartTime.Hour, app.StartTime.Minute, 0); if (startTime < app.StartTime) recur.SkippedRecurrences.Add(startTime); if (app.StartTime != startTime) app.MoveTo(startTime); ProcessRecurrenceRange(app, recur, evData); app.Recurrence = recur; }