private static void SetOrThrowIfInvalid <T>(FxPropertyBag propertyBag, PropertyTag propertyTag, T typedValue, int valueToSet) where T : struct { if (!EnumValidator <T> .IsValidValue(typedValue)) { throw new EasFetchFailedPermanentException(new LocalizedString(propertyTag + ": " + typedValue)); } propertyBag[propertyTag] = valueToSet; }
private static FxPropertyBag CreatePropertyBag(MessageRec messageRec) { FxPropertyBag result = new FxPropertyBag(new FxSession(SyncContactSchema.PropertyTagToNamedProperties)); foreach (PropertyTag propertyTag in SyncContactSchema.AllContactPropertyTags) { EasFxContactMessage.SetIfValid(result, propertyTag, messageRec[(PropTag)propertyTag]); } return(result); }
private static void SetIfValid(FxPropertyBag propertyBag, PropertyTag propertyTag, object valueToSet) { if (valueToSet != null) { if (propertyTag.PropertyType == PropertyType.SysTime) { DateTime dateTime; if (DateTime.TryParse(valueToSet.ToString(), out dateTime)) { propertyBag[propertyTag] = new ExDateTime(ExTimeZone.UtcTimeZone, dateTime); return; } } else { propertyBag[propertyTag] = valueToSet; } } }
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); }
private static IEnumerable <IRecipient> CreateRecipientsCollection(List <Attendee> attendees) { List <IRecipient> list = new List <IRecipient>(); for (int i = 0; i < attendees.Count; i++) { Attendee attendee = attendees[i]; FxPropertyBag fxPropertyBag = new FxPropertyBag(new FxSession(SyncCalendarUtils.AttendeePropertyTagsToNamedProperties)); fxPropertyBag[SyncCalendarUtils.RowId] = i; int attendeeStatus = attendee.AttendeeStatus; EasFxCalendarMessage.SetOrThrowIfInvalid <ResponseType>(fxPropertyBag, SyncCalendarUtils.RecipientTrackStatus, (ResponseType)attendeeStatus, attendeeStatus); int attendeeType = attendee.AttendeeType; EasFxCalendarMessage.SetOrThrowIfInvalid <AttendeeType>(fxPropertyBag, SyncCalendarUtils.RecipientType, (AttendeeType)attendeeType, attendeeType); fxPropertyBag[SyncCalendarUtils.EmailAddress] = attendee.Email; fxPropertyBag[SyncCalendarUtils.DisplayName] = attendee.Name; EasFxCalendarRecipient item = new EasFxCalendarRecipient(fxPropertyBag); list.Add(item); } return(list); }