public static byte[] ToRecurrenceBlob(Properties easCalendarItem, ExDateTime start, ExDateTime end, ExTimeZone targetTimeZone) { Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Recurrence recurrence = easCalendarItem.Recurrence; RecurrencePattern pattern = SyncCalendarUtils.CreateRecurrencePattern(recurrence); RecurrenceRange range = SyncCalendarUtils.CreateRecurrenceRange(start, recurrence); ExDateTime dt = targetTimeZone.ConvertDateTime(start); ExDateTime dt2 = targetTimeZone.ConvertDateTime(end); TimeSpan startOffset = dt - dt.Date; TimeSpan endOffset = dt2 - dt2.Date; InternalRecurrence internalRecurrence = new InternalRecurrence(pattern, range, null, targetTimeZone, ExTimeZone.UtcTimeZone, startOffset, endOffset); if (easCalendarItem.Exceptions != null) { foreach (Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Exception ex in easCalendarItem.Exceptions) { ExDateTime originalStartTime = SyncCalendarUtils.ToUtcExDateTime(ex.ExceptionStartTime); ExDateTime date = originalStartTime.Date; if (ex.Deleted) { internalRecurrence.TryDeleteOccurrence(date); } else { ModificationType modificationType = (ModificationType)0; MemoryPropertyBag memoryPropertyBag = new MemoryPropertyBag(); memoryPropertyBag.SetAllPropertiesLoaded(); if (ex.Subject != easCalendarItem.CalendarSubject) { modificationType |= ModificationType.Subject; memoryPropertyBag[ItemSchema.Subject] = ex.Subject; } if (ex.Reminder != easCalendarItem.Reminder) { modificationType |= ModificationType.ReminderDelta; memoryPropertyBag[ItemSchema.ReminderMinutesBeforeStartInternal] = ex.Reminder; } if (ex.Location != easCalendarItem.Location) { modificationType |= ModificationType.Location; memoryPropertyBag[CalendarItemBaseSchema.Location] = ex.Location; } if (ex.BusyStatus != easCalendarItem.BusyStatus) { modificationType |= ModificationType.BusyStatus; memoryPropertyBag[CalendarItemBaseSchema.FreeBusyStatus] = ex.BusyStatus; } if (ex.AllDayEvent != easCalendarItem.AllDayEvent) { modificationType |= ModificationType.SubType; memoryPropertyBag[CalendarItemBaseSchema.MapiIsAllDayEvent] = ex.AllDayEvent; } ExDateTime startTime = targetTimeZone.ConvertDateTime(SyncCalendarUtils.ToUtcExDateTime(ex.StartTime)); ExDateTime endTime = targetTimeZone.ConvertDateTime(SyncCalendarUtils.ToUtcExDateTime(ex.EndTime)); ExceptionInfo exceptionInfo = new ExceptionInfo(null, date, originalStartTime, startTime, endTime, modificationType, memoryPropertyBag); internalRecurrence.ModifyOccurrence(exceptionInfo); } } } return(internalRecurrence.ToByteArray()); }
private static Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception GetExceptionData(Event exceptionalEvent, bool isMeeting, ExDateTime masterStart, UserSmtpAddress userSmtpAddress) { Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception ex = new Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception(); ex.ExceptionStartTime = SyncCalendarUtils.GetExceptionStartDate(exceptionalEvent.Id, masterStart); SyncCalendarUtils.CopyCommonEventData(ex, exceptionalEvent, isMeeting, userSmtpAddress); return(ex); }
public static void CopyCommonEventData(ICalendarData calendarData, Event theEvent, bool isMeeting, UserSmtpAddress userSmtpAddress) { EventSchema schema = theEvent.Schema; int num = (theEvent.PopupReminderSettings != null && theEvent.PopupReminderSettings.Count > 0) ? theEvent.PopupReminderSettings[0].ReminderMinutesBeforeStart : 0; if (theEvent.IsPropertySet(schema.BodyProperty) && theEvent.Body != null && theEvent.Body.Content != null) { calendarData.Body = new Body { Data = theEvent.Body.Content, Type = new byte?((byte)SyncCalendarUtils.GetEasBodyType(theEvent.Body.ContentType)) }; } if (theEvent.IsPropertySet(schema.StartProperty)) { calendarData.StartTime = SyncCalendarUtils.ToStringDateTime(theEvent.Start); } if (theEvent.IsPropertySet(schema.EndProperty)) { calendarData.EndTime = SyncCalendarUtils.ToStringDateTime(theEvent.End); } if (theEvent.IsPropertySet(schema.SubjectProperty)) { calendarData.CalendarSubject = theEvent.Subject; } if (theEvent.IsPropertySet(schema.LocationProperty)) { calendarData.Location = ((theEvent.Location != null) ? ((!string.IsNullOrEmpty(theEvent.Location.DisplayName)) ? theEvent.Location.DisplayName : null) : null); } if (theEvent.IsPropertySet(schema.PopupReminderSettingsProperty)) { calendarData.Reminder = ((num > 0) ? new uint?((uint)num) : null); } if (theEvent.IsPropertySet(schema.IsAllDayProperty)) { calendarData.AllDayEvent = new byte?(Convert.ToByte(theEvent.IsAllDay)); } if (theEvent.IsPropertySet(schema.ShowAsProperty)) { EasBusyStatus?busyStatus = SyncCalendarUtils.GetBusyStatus(theEvent.ShowAs); calendarData.BusyStatus = ((busyStatus != null) ? new byte?((byte)busyStatus.GetValueOrDefault()) : null); } if (theEvent.IsPropertySet(schema.SensitivityProperty)) { calendarData.Sensitivity = new byte?((byte)theEvent.Sensitivity); } if (theEvent.IsPropertySet(schema.LastModifiedTimeProperty)) { calendarData.DtStamp = SyncCalendarUtils.ToStringDateTime(theEvent.LastModifiedTime); } if (theEvent.IsPropertySet(schema.CategoriesProperty)) { calendarData.CalendarCategories = SyncCalendarUtils.GetCategories(theEvent.Categories); } if (isMeeting && theEvent.IsPropertySet(schema.AttendeesProperty)) { calendarData.Attendees = SyncCalendarUtils.GetAttendees(theEvent.Attendees, userSmtpAddress, theEvent.ResponseStatus); } }
private static Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception GetDeletedExceptionData(string deletedOccurrenceId, ExDateTime masterStart) { return(new Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception { ExceptionStartTime = SyncCalendarUtils.GetExceptionStartDate(deletedOccurrenceId, masterStart), Deleted = new byte?(1) }); }
private static ushort GetDayOfWeekValue(ISet <DayOfWeek> daysOfWeek) { ushort num = 0; foreach (DayOfWeek day in daysOfWeek) { num += SyncCalendarUtils.GetEasDayOfWeekValue(day); } return(num); }
private static string GetExceptionStartDate(string exceptionId, ExDateTime masterStart) { StoreObjectId storeObjectId = IdConverter.Instance.ToStoreObjectId(exceptionId); OccurrenceStoreObjectId occurrenceStoreObjectId = storeObjectId as OccurrenceStoreObjectId; if (occurrenceStoreObjectId == null) { throw new EasSyncFailedPermanentException("Exception id is not an occurrence id: " + exceptionId); } return(SyncCalendarUtils.ToStringDateTime(occurrenceStoreObjectId.OccurrenceId.Add(masterStart.UniversalTime.TimeOfDay))); }
private static RecurrenceRange CreateRecurrenceRange(ExDateTime start, Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Recurrence easRecurrence) { if (easRecurrence.Occurrences != 0) { return(new NumberedRecurrenceRange(start, easRecurrence.Occurrences)); } if (!string.IsNullOrEmpty(easRecurrence.Until)) { ExDateTime endDate = SyncCalendarUtils.ToExDateTime(easRecurrence.Until); return(new EndDateRecurrenceRange(start, endDate)); } return(new NoEndRecurrenceRange(start)); }
private static RecurrencePattern CreateRecurrencePattern(Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Recurrence easRecurrence) { try { EasRecurrenceType type = (EasRecurrenceType)easRecurrence.Type; switch (type) { case EasRecurrenceType.Daily: if (easRecurrence.DayOfWeek != 0) { return(new WeeklyRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek)); } return(new DailyRecurrencePattern(easRecurrence.Interval)); case EasRecurrenceType.Weekly: return(new WeeklyRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek, easRecurrence.Interval)); case EasRecurrenceType.Monthly: return(new MonthlyRecurrencePattern(easRecurrence.DayOfMonth, easRecurrence.Interval)); case EasRecurrenceType.MonthlyTh: { RecurrenceOrderType order = SyncCalendarUtils.RecurrenceOrderTypeFromWeekOfMonth(easRecurrence.WeekOfMonth); return(new MonthlyThRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek, order, easRecurrence.Interval)); } case EasRecurrenceType.Yearly: return(new YearlyRecurrencePattern(easRecurrence.DayOfMonth, easRecurrence.MonthOfYear)); case EasRecurrenceType.YearlyTh: { RecurrenceOrderType order2 = SyncCalendarUtils.RecurrenceOrderTypeFromWeekOfMonth(easRecurrence.WeekOfMonth); return(new YearlyThRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek, order2, easRecurrence.MonthOfYear)); } } throw new EasFetchFailedPermanentException("Invalid recurrence type: " + type); } catch (ArgumentOutOfRangeException innerException) { throw new EasFetchFailedPermanentException("Invalid recurrence", innerException); } RecurrencePattern result; return(result); }
public static ApplicationData ConvertEventToAppData(Event theEvent, IList <Event> exceptionalEvents, IList <string> deletedOccurrences, UserSmtpAddress userSmtpAddress) { ExTimeZone utcTimeZone; if (theEvent.IntendedStartTimeZoneId == "tzone://Microsoft/Utc" || theEvent.IntendedStartTimeZoneId == null) { utcTimeZone = ExTimeZone.UtcTimeZone; } else { ExTimeZoneEnumerator.Instance.TryGetTimeZoneByName(theEvent.IntendedStartTimeZoneId, out utcTimeZone); } bool flag = false; byte b = 0; if (theEvent.HasAttendees) { b |= 1; flag = true; } if (theEvent.IsCancelled) { b |= 4; } if (((IEventInternal)theEvent).IsReceived) { b |= 2; } ApplicationData applicationData = new ApplicationData(); SyncCalendarUtils.CopyCommonEventData(applicationData, theEvent, flag, userSmtpAddress); applicationData.TimeZone = ((utcTimeZone != null) ? SyncCalendarUtils.ToTimeZoneString(utcTimeZone) : null); applicationData.MeetingStatus = new byte?(b); applicationData.Uid = (string.IsNullOrEmpty(((IEventInternal)theEvent).GlobalObjectId) ? null : new GlobalObjectId(((IEventInternal)theEvent).GlobalObjectId).Uid); applicationData.Recurrence = SyncCalendarUtils.GetRecurrenceData(theEvent.PatternedRecurrence); applicationData.Exceptions = SyncCalendarUtils.GetExceptionData(exceptionalEvents, deletedOccurrences, flag, theEvent.Start, userSmtpAddress); if (flag) { applicationData.OrganizerEmail = theEvent.Organizer.EmailAddress; applicationData.OrganizerName = theEvent.Organizer.Name; applicationData.ResponseRequested = new byte?(Convert.ToByte(theEvent.ResponseRequested)); } return(applicationData); }
internal static SyncRequest CreateSyncRequestForUpdateCalendarEvent(string syncKey, string itemId, string folderId, Event theEvent, IList <Event> exceptionalEvents, IList <string> deletedOccurrences, UserSmtpAddress userSmtpAddress) { Microsoft.Exchange.Connections.Eas.Model.Request.AirSync.Collection collection = new Microsoft.Exchange.Connections.Eas.Model.Request.AirSync.Collection(); ChangeCommand changeCommand = new ChangeCommand(); changeCommand.ServerId = itemId; changeCommand.ApplicationData = SyncCalendarUtils.ConvertEventToAppData(theEvent, exceptionalEvents, deletedOccurrences, userSmtpAddress); collection.Commands.Add(changeCommand); collection.SyncKey = syncKey; collection.CollectionId = folderId; collection.GetChanges = new bool?(false); return(new SyncRequest { Collections = { collection } }); }
private static FxPropertyBag CreatePropertyBag(Properties calendarItemProperties) { FxPropertyBag fxPropertyBag = new FxPropertyBag(new FxSession(SyncCalendarUtils.CalendarItemPropertyTagsToNamedProperties)); ExDateTime exDateTime = SyncCalendarUtils.ToUtcExDateTime(calendarItemProperties.StartTime); ExDateTime exDateTime2 = SyncCalendarUtils.ToUtcExDateTime(calendarItemProperties.EndTime); if (exDateTime > exDateTime2) { throw new EasFetchFailedPermanentException(new LocalizedString(string.Format("Start {0} is greater than end {1}.", exDateTime, exDateTime2))); } fxPropertyBag[SyncCalendarUtils.Start] = exDateTime; fxPropertyBag[SyncCalendarUtils.End] = exDateTime2; fxPropertyBag[SyncCalendarUtils.GlobalObjectId] = new GlobalObjectId(calendarItemProperties.Uid).Bytes; ExTimeZone exTimeZone = SyncCalendarUtils.ToExTimeZone(calendarItemProperties.TimeZone); fxPropertyBag[SyncCalendarUtils.TimeZoneBlob] = O11TimeZoneFormatter.GetTimeZoneBlob(exTimeZone); int busyStatus = calendarItemProperties.BusyStatus; EasFxCalendarMessage.SetOrThrowIfInvalid <BusyType>(fxPropertyBag, SyncCalendarUtils.BusyStatus, (BusyType)busyStatus, busyStatus); int sensitivity = calendarItemProperties.Sensitivity; EasFxCalendarMessage.SetOrThrowIfInvalid <Sensitivity>(fxPropertyBag, SyncCalendarUtils.Sensitivity, (Sensitivity)sensitivity, sensitivity); int meetingStatus = calendarItemProperties.MeetingStatus; EasFxCalendarMessage.SetOrThrowIfInvalid <AppointmentStateFlags>(fxPropertyBag, SyncCalendarUtils.MeetingStatus, (AppointmentStateFlags)meetingStatus, meetingStatus); fxPropertyBag[PropertyTag.MessageClass] = "IPM.Appointment"; fxPropertyBag[PropertyTag.Subject] = calendarItemProperties.CalendarSubject; fxPropertyBag[SyncCalendarUtils.AllDayEvent] = calendarItemProperties.AllDayEvent; fxPropertyBag[SyncCalendarUtils.Location] = calendarItemProperties.Location; fxPropertyBag[SyncCalendarUtils.Reminder] = calendarItemProperties.Reminder; fxPropertyBag[PropertyTag.Body] = calendarItemProperties.Body.Data; fxPropertyBag[SyncCalendarUtils.SentRepresentingName] = calendarItemProperties.OrganizerName; fxPropertyBag[SyncCalendarUtils.SentRepresentingEmailAddress] = calendarItemProperties.OrganizerEmail; fxPropertyBag[SyncCalendarUtils.ResponseType] = calendarItemProperties.ResponseType; Recurrence recurrence = calendarItemProperties.Recurrence; if (recurrence != null) { fxPropertyBag[SyncCalendarUtils.AppointmentRecurrenceBlob] = SyncCalendarUtils.ToRecurrenceBlob(calendarItemProperties, exDateTime, exDateTime2, exTimeZone); } return(fxPropertyBag); }
public static List <Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception> GetExceptionData(IList <Event> exceptionalEvents, IList <string> deletedOccurrences, bool isMeeting, ExDateTime masterStart, UserSmtpAddress userSmtpAddress) { if (exceptionalEvents == null && deletedOccurrences == null) { return(null); } List <Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception> list = new List <Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Exception>(); if (exceptionalEvents != null) { foreach (Event exceptionalEvent in exceptionalEvents) { list.Add(SyncCalendarUtils.GetExceptionData(exceptionalEvent, isMeeting, masterStart, userSmtpAddress)); } } if (deletedOccurrences != null) { foreach (string deletedOccurrenceId in deletedOccurrences) { list.Add(SyncCalendarUtils.GetDeletedExceptionData(deletedOccurrenceId, masterStart)); } } return(list); }
public static Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Recurrence GetRecurrenceData(PatternedRecurrence recurrence) { if (recurrence == null) { return(null); } Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Recurrence recurrence2 = new Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Recurrence(); recurrence2.Interval = new ushort?((ushort)recurrence.Pattern.Interval); RecurrencePatternType type = recurrence.Pattern.Type; switch (type) { case RecurrencePatternType.Daily: { DailyRecurrencePattern dailyRecurrencePattern = (DailyRecurrencePattern)recurrence.Pattern; recurrence2.Type = 0; break; } case RecurrencePatternType.Weekly: { WeeklyRecurrencePattern weeklyRecurrencePattern = (WeeklyRecurrencePattern)recurrence.Pattern; recurrence2.Type = 1; recurrence2.DayOfWeek = new ushort?(SyncCalendarUtils.GetDayOfWeekValue(weeklyRecurrencePattern.DaysOfWeek)); break; } case RecurrencePatternType.AbsoluteMonthly: { AbsoluteMonthlyRecurrencePattern absoluteMonthlyRecurrencePattern = (AbsoluteMonthlyRecurrencePattern)recurrence.Pattern; recurrence2.Type = 2; recurrence2.DayOfMonth = new byte?((byte)absoluteMonthlyRecurrencePattern.DayOfMonth); break; } case RecurrencePatternType.RelativeMonthly: { RelativeMonthlyRecurrencePattern relativeMonthlyRecurrencePattern = (RelativeMonthlyRecurrencePattern)recurrence.Pattern; recurrence2.Type = 3; recurrence2.DayOfWeek = new ushort?(SyncCalendarUtils.GetDayOfWeekValue(relativeMonthlyRecurrencePattern.DaysOfWeek)); recurrence2.WeekOfMonth = new byte?((byte)relativeMonthlyRecurrencePattern.Index); break; } case RecurrencePatternType.AbsoluteYearly: { AbsoluteYearlyRecurrencePattern absoluteYearlyRecurrencePattern = (AbsoluteYearlyRecurrencePattern)recurrence.Pattern; recurrence2.Type = 5; recurrence2.DayOfMonth = new byte?((byte)absoluteYearlyRecurrencePattern.DayOfMonth); recurrence2.MonthOfYear = new byte?((byte)absoluteYearlyRecurrencePattern.Month); break; } case RecurrencePatternType.RelativeYearly: { RelativeYearlyRecurrencePattern relativeYearlyRecurrencePattern = (RelativeYearlyRecurrencePattern)recurrence.Pattern; recurrence2.Type = 6; recurrence2.DayOfWeek = new ushort?(SyncCalendarUtils.GetDayOfWeekValue(relativeYearlyRecurrencePattern.DaysOfWeek)); recurrence2.WeekOfMonth = new byte?((byte)relativeYearlyRecurrencePattern.Index); recurrence2.MonthOfYear = new byte?((byte)relativeYearlyRecurrencePattern.Month); break; } default: throw new EasSyncFailedPermanentException("Invalid recurrence type: " + type); } RecurrenceRangeType type2 = recurrence.Range.Type; switch (type2) { case RecurrenceRangeType.EndDate: { EndDateRecurrenceRange endDateRecurrenceRange = (EndDateRecurrenceRange)recurrence.Range; recurrence2.Until = SyncCalendarUtils.ToStringDateTime(endDateRecurrenceRange.EndDate); break; } case RecurrenceRangeType.NoEnd: break; case RecurrenceRangeType.Numbered: { NumberedRecurrenceRange numberedRecurrenceRange = (NumberedRecurrenceRange)recurrence.Range; recurrence2.Occurrences = new ushort?((ushort)numberedRecurrenceRange.NumberOfOccurrences); break; } default: throw new EasSyncFailedPermanentException("Invalid recurrence range type: {0}" + type2); } return(recurrence2); }
internal static ExDateTime ToUtcExDateTime(string value) { return(ExTimeZone.UtcTimeZone.ConvertDateTime(SyncCalendarUtils.ToExDateTime(value))); }