/// <summary> /// Updates the specified appointment. /// </summary> /// <param name="owner">The owner RadScheduler instance.</param> /// <param name="appointmentToUpdate">The appointment to update.</param> public override void Update(RadScheduler owner, Appointment appointmentToUpdate) { if (owner.ProviderContext is RemoveRecurrenceExceptionsContext) { RemoveRecurrenceExceptions(appointmentToUpdate); return; } if (owner.ProviderContext is UpdateAppointmentContext) { // When removing recurrences through the UI, // one Update operation is used to both update the appointment // and remove the recurrence exceptions. RecurrenceRule updatedRule; RecurrenceRule.TryParse(appointmentToUpdate.RecurrenceRule, out updatedRule); if (updatedRule != null && updatedRule.Exceptions.Count == 0) { RemoveRecurrenceExceptions(appointmentToUpdate); } } CreateRecurrenceExceptionContext createExceptionContext = owner.ProviderContext as CreateRecurrenceExceptionContext; if (createExceptionContext == null) { // We are not creating a recurrence exceptions - synchronize deleted occurrences. SynchronizeDeletedOccurrences(appointmentToUpdate); } ItemChangeType[] changes = new ItemChangeType[] { GetAppointmentChanges(appointmentToUpdate) }; UpdateCalendarItem(changes); }
private void UpdateNextOccurences() { if (RecurrenceRule.TryParse(TbxRecurrenceRule.Text, out var rule, out var error)) { var occurences = rule.GetNextOccurrences(DateTime.Now).Select(date => date.ToString("F", CultureInfo.CurrentCulture)).Take(50).ToList(); NextOccurences.ItemsSource = occurences; }
public override bool IsValid(object value) { if (value == null) { return(true); } return(value as string != null && RecurrenceRule.TryParse(value as string, out _)); }
private void UpdateResetExceptionsVisibility() { // Render the reset exceptions checkbox when using web service binding if (string.IsNullOrEmpty(Owner.WebServiceSettings.Path)) { ResetExceptions.Visible = false; RecurrenceRule rrule; if (RecurrenceRule.TryParse(Appointment.RecurrenceRule, out rrule)) { ResetExceptions.Visible = rrule.Exceptions.Count > 0; } } }
/// <summary> /// Writes the the entry for an event. /// </summary> /// <param name="description">The event's description.</param> /// <param name="location">The event's location.</param> /// <param name="output">The <see cref="StringBuilder"/> into which the output should be appended.</param> /// <param name="app">The appointment to export.</param> /// <param name="outlookCompatibleMode">if set to <c>true</c> make the output compatible with Outlook.</param> /// <exception cref="InvalidOperationException">Invalid recurrence rule.</exception> private static void WriteTask(string description, string location, StringBuilder output, Appointment app, bool outlookCompatibleMode) { output.AppendLine("BEGIN:VEVENT"); output.AppendLine("DESCRIPTION:" + description.Replace("\n", "\\n").Replace("\r", "\\r")); output.AppendLine("LOCATION:" + location); if (!string.IsNullOrEmpty(app.RecurrenceRule)) { RecurrenceRule rrule; if (!RecurrenceRule.TryParse(app.RecurrenceRule, out rrule)) { throw new InvalidOperationException("Invalid recurrence rule."); } if (outlookCompatibleMode) { foreach (DateTime occ in rrule.Occurrences) { // Outlook requires that the start date is the same as the first occurrence. rrule.Range.Start = occ; break; } if ((rrule.Pattern.Frequency == RecurrenceFrequency.Daily || rrule.Pattern.Frequency == RecurrenceFrequency.Monthly) && rrule.Pattern.DaysOfWeekMask == RecurrenceDay.EveryDay) { rrule.Pattern.DaysOfWeekMask = RecurrenceDay.None; } } output.Append(rrule.ToString()); } else { output.AppendFormat("DTSTART:{0}\r\n", FormatDate(app.Start)); output.AppendFormat("DTEND:{0}\r\n", FormatDate(app.End)); } if (outlookCompatibleMode) { output.AppendFormat("UID:{0}-{1}\r\n", FormatDate(DateTime.UtcNow), app.ID); output.AppendFormat("DTSTAMP:{0}\r\n", FormatDate(DateTime.UtcNow)); } string summary = app.Subject.Replace("\r\n", "\\n"); summary = summary.Replace("\n", "\\n"); output.AppendFormat("SUMMARY:{0}\r\n", summary); output.AppendLine("END:VEVENT"); }
public override bool IsValid(ITypeDescriptorContext context, object value) { string rruleString = value as string; if (!string.IsNullOrEmpty(rruleString)) { RecurrenceRule rrule; RecurrenceRule.TryParse(rruleString, out rrule); return(rrule != null); } return(base.IsValid(context, value)); }
private void SynchronizeDeletedOccurrences(Appointment apt) { RecurrenceRule rrule; if (!RecurrenceRule.TryParse(apt.RecurrenceRule, out rrule)) { return; } ItemIdType itemId = new ItemIdType(); itemId.Id = apt.Attributes[ExchangeIdAttribute]; itemId.ChangeKey = apt.Attributes[ExchangeChangeKeyAttribute]; CalendarItemType calendarItem = GetCalendarItems(new ItemIdType[] { itemId })[0]; List <DateTime> existingExceptions = new List <DateTime>(); if (calendarItem.ModifiedOccurrences != null) { foreach (CalendarItemType modifiedOccurrence in GetModifiedOccurrences(calendarItem)) { existingExceptions.Add(modifiedOccurrence.OriginalStart); } } if (calendarItem.DeletedOccurrences != null) { foreach (DeletedOccurrenceInfoType deletedOccurrence in calendarItem.DeletedOccurrences) { existingExceptions.Add(deletedOccurrence.Start); } } foreach (DateTime recurrenceException in rrule.Exceptions) { // Search in ModifiedOccurrences and DeletedOccurrences for this exception. if (existingExceptions.Contains(recurrenceException)) { continue; } // If it is not found in either, delete the occurrence. int occurrenceIndex = GetOccurrenceIndex(recurrenceException, apt); CalendarItemType occurrenceItem = GetOccurrenceItem(apt, occurrenceIndex); DeleteItem(occurrenceItem.ItemId); } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { throw new InvalidOperationException("Cannot convert from null value."); } string rruleString = value as string; if (!string.IsNullOrEmpty(rruleString)) { RecurrenceRule rrule; RecurrenceRule.TryParse(rruleString, out rrule); return(rrule); } return(base.ConvertFrom(context, culture, value)); }
private static SetItemFieldType GetRecurrenceUpdate(Appointment apt) { SetItemFieldType recurrenceUpdate = new SetItemFieldType(); PathToUnindexedFieldType recurrencePath = new PathToUnindexedFieldType(); recurrencePath.FieldURI = UnindexedFieldURIType.calendarRecurrence; CalendarItemType recurrenceData = new CalendarItemType(); RecurrenceRule rrule; RecurrenceRule.TryParse(apt.RecurrenceRule, out rrule); if (rrule != null && rrule.Pattern.Frequency != RecurrenceFrequency.Hourly) { recurrenceData.Recurrence = CreateRecurrence(rrule, apt.Owner); } recurrenceUpdate.Item = recurrencePath; recurrenceUpdate.Item1 = recurrenceData; return(recurrenceUpdate); }
private static int GetOccurrenceIndex(DateTime occurrenceStart, Appointment master) { RecurrenceRule rrule; RecurrenceRule.TryParse(master.RecurrenceRule, out rrule); // Exceptions must be counted too rrule.Exceptions.Clear(); int index = 1; foreach (DateTime occ in rrule.Occurrences) { if (occ == occurrenceStart) { break; } index++; } return(index); }
protected virtual CalendarItemType CreateCalendarItem(RadScheduler owner, Appointment apt) { CalendarItemType calendarItem = new CalendarItemType(); calendarItem.Subject = apt.Subject; calendarItem.Start = apt.Start; calendarItem.StartSpecified = true; calendarItem.End = apt.End; calendarItem.EndSpecified = true; calendarItem.MeetingTimeZone = GetTimeZone(owner.TimeZoneOffset); RecurrenceRule rrule; RecurrenceRule.TryParse(apt.RecurrenceRule, out rrule); if (rrule != null && rrule.Pattern.Frequency != RecurrenceFrequency.Hourly) { calendarItem.Recurrence = CreateRecurrence(rrule, owner); } return(calendarItem); }