/// <summary> /// converts an outlook appointment element to a StdCalendarItem /// </summary> /// <param name="outlookItem"> /// The outlook item to be converted. /// </param> /// <param name="appointmentList"> /// list of std calendar entries to suppress duplicates /// </param> /// <returns> /// the newly created StdCalendarItem /// </returns> /// <exception cref="ArgumentNullException"> /// in case of outlookItem being null /// </exception> internal static StdCalendarItem ConvertToStandardCalendarItem( AppointmentItem outlookItem, IEnumerable <StdCalendarItem> appointmentList) { if (outlookItem == null) { throw new ArgumentNullException("outlookItem"); } // generate the new id this contact will get in case there is no contact id in outlook var newId = GetStandardAppointmentId(outlookItem, appointmentList); var result = new StdCalendarItem { Id = newId, Title = outlookItem.Subject, Description = outlookItem.Body, Start = outlookItem.Start.ToUniversalTime(), End = outlookItem.End.ToUniversalTime(), BusyStatus = outlookItem.BusyStatus.ToBusyStatus(), InternalSyncData = new SyncData { DateOfLastChange = outlookItem.LastModificationTime }, Location = outlookItem.Location, ExternalIdentifier = new ProfileIdentifierDictionary(ProfileIdentifierType.MicrosoftOutlookId, outlookItem.EntryID), RecurrenceState = outlookItem.RecurrenceState.ToRecurrenceState(), ReminderBeforeStart = TimeSpan.FromMinutes(outlookItem.ReminderMinutesBeforeStart), ResponseRequested = outlookItem.ResponseRequested, ResponseStatus = outlookItem.ResponseStatus.ToResponseStatus(), }; return(result); }
/// <summary> /// Converts a <see cref="StdCalendarItem"/> to an Outlook-Appointment. /// </summary> /// <param name="stdNewAppointment"> /// The <see cref="StdCalendarItem"/> to be converted. /// </param> /// <param name="appointment"> /// The appointment to be updated. /// </param> /// <returns> /// True if there have been updates in the target /// </returns> /// <exception cref="ArgumentNullException"> /// in case of the <paramref name="stdNewAppointment"/> or <paramref name="appointment"/> being null. /// </exception> private static bool ConvertToNativeAppointment(StdCalendarItem stdNewAppointment, AppointmentItem appointment) { if (stdNewAppointment == null) { throw new ArgumentNullException("stdNewAppointment"); } if (appointment == null) { throw new ArgumentNullException("appointment"); } var stdOldAppointment = ConvertToStandardCalendarItem(appointment, null); stdNewAppointment.NormalizeContent(); stdOldAppointment.NormalizeContent(); var dirty = false; MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.Title, x => appointment.Subject = x); MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.Description, x => appointment.Body = x); MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.Start, x => appointment.StartUTC = x); MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.End, x => appointment.EndUTC = x); MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.BusyStatus.ToOutlook(), x => appointment.BusyStatus = x); MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.Location, x => appointment.Location = x); MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.ReminderBeforeStart.Minutes, x => appointment.ReminderMinutesBeforeStart = x); MappingHelper.MapIfDiffers(ref dirty, stdNewAppointment, stdOldAppointment, x => x.ResponseRequested, x => appointment.ResponseRequested = x); // todo: how can se set the RecurrenceState property? // todo: how to set the ResponseStatus property return(dirty); }
public void PropertyPathWithNoNullToPropertyWithTransformation() { // register the property mapping of a source and a destination // type with trasformations (in this case we do add a string to // the name to generate a calendar title of "Birthday: Riddle, Tom") var mapper = new Mapper(); mapper.Register <StdContact, StdCalendarItem>( contact => contact.PersonalAddressPrimary.Phone, (calendar, entity) => calendar.Title = entity == null ? "NULL detected" : "Call to " + entity); // setup a source and a destination object var source = new StdContact { PersonalAddressPrimary = new AddressDetail { Phone = "0123-456789" } }; var target = new StdCalendarItem(); // perform the mapping mapper.Map(source, target); // test it Assert.AreEqual("Call to (123) 456789", target.Title); }
/// <summary> /// Converts a list of standard contacts to a list of standard elements /// </summary> /// <param name="list"> /// a list of standard contacts to cast /// </param> /// <returns> /// a list of casted elements /// </returns> public static List <StdCalendarItem> ToStdCalendarItems(this IEnumerable <StdElement> list) { var result = new List <StdCalendarItem>(); foreach (var element in list) { var e = element as StdCalendarItem; if (e == null) { var m = element as MatchingEntry; if (m != null) { e = new StdCalendarItem { Id = element.Id, ExternalIdentifier = m.ProfileId }; } } if (e != null) { result.Add(e); } } return(result); }
public void FunctionCallToPropertyWithTransformation() { // register the property mapping of a source and a destination // type with trasformations (in this case we do add a string to // the name to generate a calendar title of "Birthday: Riddle, Tom") var mapper = new Mapper(); mapper.Register <StdContact, StdCalendarItem>(contact => contact.Id, (calendar, entity) => calendar.Id = (Guid)entity); mapper.Register <StdContact, StdCalendarItem>(contact => contact.GetFullName(), (calendar, entity) => calendar.Title = "Birthday: " + entity); // setup a source and a destination object var source = new StdContact { Name = new PersonName("Tom Riddle") }; var target = new StdCalendarItem(); // perform the mapping mapper.Map(source, target); // test it Assert.AreEqual(source.Id, target.Id); Assert.AreEqual("Birthday: " + source.GetFullName(), target.Title); }
/// <summary> /// this method is still not implemented /// </summary> /// <param name="appointmentEnum"> /// The appointment enum. /// </param> /// <param name="stdCalendarItem"> /// The std calendar item. /// </param> /// <param name="appointmentList"> /// The appointment List. /// </param> /// <returns> /// a value indicating whether the element has been written to outlook /// </returns> /// <exception cref="ArgumentNullException"> /// in case of contactsEnum being null /// </exception> internal static SaveAction WriteCalendarItemToOutlook( Items appointmentEnum, StdCalendarItem stdCalendarItem, IEnumerable <AppointmentItemContainer> appointmentList) { var actionDone = SaveAction.None; if (appointmentEnum == null) { throw new ArgumentNullException("appointmentEnum"); } if (stdCalendarItem == null) { throw new ArgumentNullException("stdCalendarItem"); } var outlookAppointment = (from x in appointmentList where x.Id == stdCalendarItem.Id.ToString() select x.Item).FirstOrDefault(); if (outlookAppointment == null) { outlookAppointment = (AppointmentItem)appointmentEnum.Add(OlItemType.olAppointmentItem); actionDone = SaveAction.Create; } // convert StdContact to Outlook contact if (ConvertToNativeAppointment(stdCalendarItem, outlookAppointment)) { actionDone = actionDone == SaveAction.None ? SaveAction.Update : actionDone; outlookAppointment.Save(); } GCRelevantCall(); return(actionDone); }