public Task <IDistListItemWrapper> Map2To1(vCard source, IDistListItemWrapper target, IEntityMappingLogger logger, DistributionListSychronizationContext context) { if (string.IsNullOrEmpty(source.FormattedName)) { var name = new StringBuilder(); name.Append(source.FamilyName); if (!string.IsNullOrEmpty(source.GivenName)) { if (name.Length > 0) { name.Append(","); } name.Append(source.GivenName); } if (!string.IsNullOrEmpty(source.AdditionalNames)) { if (name.Length > 0) { name.Append(","); } name.Append(source.AdditionalNames); } if (name.Length > 0) { target.Inner.DLName = name.ToString(); } } else { target.Inner.DLName = source.FormattedName; } target.Inner.Sensitivity = CommonEntityMapper.MapPrivacy2To1(source.AccessClassification); if (source.Categories.Count > 0) { string[] categories = new string[source.Categories.Count]; source.Categories.CopyTo(categories, 0); target.Inner.Categories = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, categories); } else { target.Inner.Categories = string.Empty; } if (source.Notes.Count > 0) { target.Inner.Body = source.Notes[0].Text; } else { target.Inner.Body = string.Empty; } CommonEntityMapper.MapDistListMembers2To1(GetMembers(source, context, logger, s_logger), target, logger, context); return(Task.FromResult(target)); }
public async Task <IContactItemWrapper> Map2To1(vCard source, IContactItemWrapper target, IEntitySynchronizationLogger logger, ICardDavRepositoryLogger context) { target.Inner.FirstName = source.GivenName; target.Inner.LastName = source.FamilyName; target.Inner.Title = source.NamePrefix; target.Inner.Suffix = source.NameSuffix; target.Inner.MiddleName = source.AdditionalNames; target.Inner.Gender = MapGender1To2(source.Gender); target.Inner.AssistantName = source.Assistant; target.Inner.Spouse = source.Spouse; target.Inner.ManagerName = source.Manager; if (string.IsNullOrEmpty(target.Inner.FullName)) { target.Inner.FullName = source.FormattedName; } if (!_configuration.KeepOutlookFileAs) { target.Inner.FileAs = source.FormattedName; } if (source.Nicknames.Count > 0) { string[] nickNames = new string[source.Nicknames.Count]; source.Nicknames.CopyTo(nickNames, 0); target.Inner.NickName = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, nickNames); } else { target.Inner.NickName = string.Empty; } target.Inner.Sensitivity = CommonEntityMapper.MapPrivacy2To1(source.AccessClassification); if (source.Categories.Count > 0) { string[] categories = new string[source.Categories.Count]; source.Categories.CopyTo(categories, 0); target.Inner.Categories = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, categories); } else { target.Inner.Categories = string.Empty; } MapIMs2To1(source, target.Inner); target.Inner.Email1Address = string.Empty; target.Inner.Email1DisplayName = string.Empty; target.Inner.Email2Address = string.Empty; target.Inner.Email2DisplayName = string.Empty; target.Inner.Email3Address = string.Empty; target.Inner.Email3DisplayName = string.Empty; if (source.EmailAddresses.Count >= 1) { Func <vCardEmailAddress, bool> firstPredicate = e => _configuration.MapOutlookEmail1ToWork ? e.ItemType == ItemType.WORK : e.ItemType == ItemType.HOME; var first = source.EmailAddresses.FirstOrDefault(firstPredicate) ?? source.EmailAddresses.First(); target.Inner.Email1Address = first.Address; var second = source.EmailAddresses.FirstOrDefault(e => _configuration.MapOutlookEmail1ToWork ? e.ItemType == ItemType.HOME : e.ItemType == ItemType.WORK && e != first) ?? source.EmailAddresses.FirstOrDefault(e => e != first); if (second != null) { target.Inner.Email2Address = second.Address; var other = source.EmailAddresses.FirstOrDefault(e => e != first && e != second); if (other != null) { target.Inner.Email3Address = other.Address; } } } MapPostalAdresses2To1(source, target.Inner); MapTelephoneNumber2To1(source, target.Inner); if (_configuration.MapAnniversary) { if (source.Anniversary.HasValue) { if (!source.Anniversary.Value.Date.Equals(target.Inner.Anniversary)) { try { target.Inner.Anniversary = source.Anniversary.Value; } catch (COMException ex) { s_logger.Warn("Could not update contact anniversary.", ex); logger.LogWarning("Could not update contact anniversary.", ex); } catch (OverflowException ex) { s_logger.Warn("Contact anniversary has invalid value.", ex); logger.LogWarning("Contact anniversary has invalid value.", ex); } } } else { target.Inner.Anniversary = OutlookUtility.OUTLOOK_DATE_NONE; } } if (_configuration.MapBirthday) { if (source.BirthDate.HasValue) { if (!source.BirthDate.Value.Date.Equals(target.Inner.Birthday)) { try { target.Inner.Birthday = source.BirthDate.Value; } catch (COMException ex) { s_logger.Warn("Could not update contact birthday.", ex); logger.LogWarning("Could not update contact birthday.", ex); } catch (OverflowException ex) { s_logger.Warn("Contact birthday has invalid value.", ex); logger.LogWarning("Contact birthday has invalid value.", ex); } } } else { target.Inner.Birthday = OutlookUtility.OUTLOOK_DATE_NONE; } } target.Inner.CompanyName = source.Organization; target.Inner.Department = source.Department; target.Inner.JobTitle = source.Title; target.Inner.Profession = source.Role; MapHomePage2To1(source, target.Inner); MapCertificate2To1(source, target.Inner, logger); if (_configuration.MapContactPhoto) { await MapPhoto2To1(source, target.Inner, logger); } if (source.Notes.Count > 0) { target.Inner.Body = source.Notes[0].Text; } else { target.Inner.Body = string.Empty; } return(target); }
public ITaskItemWrapper Map2To1(ITodo source, ITaskItemWrapper target, IEntitySynchronizationLogger logger) { target.Inner.Subject = source.Summary; target.Inner.Body = _configuration.MapBody ? source.Description : string.Empty; DateTimeZone localZone = DateTimeZoneProviders.Bcl.GetSystemDefault(); if (source.Start != null) { if (source.Start.IsUniversalTime) { target.Inner.StartDate = Instant.FromDateTimeUtc(source.Start.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.StartDate = source.Start.Date; } } else { target.Inner.StartDate = OutlookUtility.OUTLOOK_DATE_NONE; } if (source.Due != null) { if (source.Start == null || source.Start.Value <= source.Due.Value) { if (source.Due.IsUniversalTime) { target.Inner.DueDate = Instant.FromDateTimeUtc(source.Due.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.DueDate = source.Due.Date; } } } else { target.Inner.DueDate = OutlookUtility.OUTLOOK_DATE_NONE; } if (source.Completed != null) { if (source.Completed.IsUniversalTime) { target.Inner.DateCompleted = Instant.FromDateTimeUtc(source.Completed.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.DateCompleted = source.Completed.Date; } target.Inner.Complete = true; } else { target.Inner.Complete = false; } target.Inner.Status = (target.Inner.Complete && target.Inner.PercentComplete == 100) ? OlTaskStatus.olTaskComplete : MapStatus2To1(source.Status); // Only set PercentComplete if source is actually set and status is not already completed to avoid overwriting the status again if (source.PercentComplete != 0 && target.Inner.Status != OlTaskStatus.olTaskComplete) { target.Inner.PercentComplete = source.PercentComplete; } if (_configuration.MapPriority) { target.Inner.Importance = CommonEntityMapper.MapPriority2To1(source.Priority); } target.Inner.Sensitivity = CommonEntityMapper.MapPrivacy2To1(source.Class, false, false); MapCategories2To1(source, target); MapReminder2To1(source, target, logger); if (_configuration.MapCustomProperties || _configuration.UserDefinedCustomPropertyMappings.Length > 0) { using (var userPropertiesWrapper = GenericComObjectWrapper.Create(target.Inner.UserProperties)) { CommonEntityMapper.MapCustomProperties2To1(source.Properties, userPropertiesWrapper, _configuration.MapCustomProperties, _configuration.UserDefinedCustomPropertyMappings, logger, s_logger); } } if (_configuration.MapRecurringTasks) { MapRecurrance2To1(source, target, logger); } return(target); }
public TaskItemWrapper Map2To1(ITodo source, TaskItemWrapper target, IEntityMappingLogger logger) { target.Inner.Subject = source.Summary; target.Inner.Body = _configuration.MapBody ? source.Description : string.Empty; NodaTime.DateTimeZone localZone = NodaTime.DateTimeZoneProviders.Bcl.GetSystemDefault(); if (source.Start != null) { if (source.Start.IsUniversalTime) { target.Inner.StartDate = NodaTime.Instant.FromDateTimeUtc(source.Start.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.StartDate = source.Start.Date; } } if (source.Due != null) { if (source.Start == null || source.Start.Value <= source.Due.Value) { if (source.Due.IsUniversalTime) { target.Inner.DueDate = NodaTime.Instant.FromDateTimeUtc(source.Due.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.DueDate = source.Due.Date; } } } if (source.Completed != null) { if (source.Completed.IsUniversalTime) { target.Inner.DateCompleted = NodaTime.Instant.FromDateTimeUtc(source.Completed.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.DateCompleted = source.Completed.Date; } target.Inner.Complete = true; } else { target.Inner.Complete = false; } target.Inner.PercentComplete = source.PercentComplete; if (_configuration.MapPriority) { target.Inner.Importance = CommonEntityMapper.MapPriority2To1(source.Priority); } target.Inner.Sensitivity = CommonEntityMapper.MapPrivacy2To1(source.Class, false); target.Inner.Status = MapStatus2To1(source.Status); MapCategories2To1(source, target); MapReminder2To1(source, target, logger); if (_configuration.MapRecurringTasks) { MapRecurrance2To1(source, target, logger); } return(target); }
public async Task <IContactItemWrapper> Map2To1(vCard source, IContactItemWrapper target, IEntityMappingLogger logger, ICardDavRepositoryLogger context) { target.Inner.FirstName = source.GivenName; target.Inner.LastName = source.FamilyName; target.Inner.Title = source.NamePrefix; target.Inner.Suffix = source.NameSuffix; target.Inner.MiddleName = source.AdditionalNames; target.Inner.Gender = MapGender1To2(source.Gender); if (string.IsNullOrEmpty(target.Inner.FullName)) { target.Inner.FullName = source.FormattedName; } if (!_configuration.KeepOutlookFileAs) { target.Inner.FileAs = source.FormattedName; } if (source.Nicknames.Count > 0) { string[] nickNames = new string[source.Nicknames.Count]; source.Nicknames.CopyTo(nickNames, 0); target.Inner.NickName = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, nickNames); } else { target.Inner.NickName = string.Empty; } target.Inner.Sensitivity = CommonEntityMapper.MapPrivacy2To1(source.AccessClassification); if (source.Categories.Count > 0) { string[] categories = new string[source.Categories.Count]; source.Categories.CopyTo(categories, 0); target.Inner.Categories = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, categories); } else { target.Inner.Categories = string.Empty; } target.Inner.IMAddress = string.Empty; foreach (var im in source.IMs) { if (!string.IsNullOrEmpty(target.Inner.IMAddress)) { target.Inner.IMAddress += "; "; } if (im.ServiceType != IMServiceType.Unspecified && im.ServiceType != _configuration.DefaultImServicType) { target.Inner.IMAddress += im.ServiceType + ": " + im.Handle; } else { target.Inner.IMAddress += im.Handle; } } target.Inner.Email1Address = string.Empty; target.Inner.Email1DisplayName = string.Empty; target.Inner.Email2Address = string.Empty; target.Inner.Email2DisplayName = string.Empty; target.Inner.Email3Address = string.Empty; target.Inner.Email3DisplayName = string.Empty; if (source.EmailAddresses.Count >= 1) { Func <vCardEmailAddress, bool> firstPredicate = e => _configuration.MapOutlookEmail1ToWork ? e.ItemType == ItemType.WORK : e.ItemType == ItemType.HOME; var first = source.EmailAddresses.FirstOrDefault(firstPredicate) ?? source.EmailAddresses.First(); target.Inner.Email1Address = first.Address; var second = source.EmailAddresses.FirstOrDefault(e => _configuration.MapOutlookEmail1ToWork ? e.ItemType == ItemType.HOME : e.ItemType == ItemType.WORK && e != first) ?? source.EmailAddresses.FirstOrDefault(e => e != first); if (second != null) { target.Inner.Email2Address = second.Address; var other = source.EmailAddresses.FirstOrDefault(e => e != first && e != second); if (other != null) { target.Inner.Email3Address = other.Address; } } } MapPostalAdresses2To1(source, target.Inner); MapTelephoneNumber2To1(source, target.Inner); if (_configuration.MapBirthday) { if (source.BirthDate.HasValue) { if (!source.BirthDate.Value.Date.Equals(target.Inner.Birthday)) { try { target.Inner.Birthday = source.BirthDate.Value; } catch (COMException ex) { s_logger.Warn("Could not update contact birthday.", ex); logger.LogMappingWarning("Could not update contact birthday.", ex); } catch (OverflowException ex) { s_logger.Warn("Contact birthday has invalid value.", ex); logger.LogMappingWarning("Contact birthday has invalid value.", ex); } } } else { target.Inner.Birthday = new DateTime(4501, 1, 1); } } if (!string.IsNullOrEmpty(source.Organization)) { string[] organizationAndDepartments = source.Organization.Split(new[] { ';' }, 2); target.Inner.CompanyName = organizationAndDepartments[0]; target.Inner.Department = (organizationAndDepartments.Length > 1) ? organizationAndDepartments[1]: null; } else { target.Inner.CompanyName = target.Inner.Department = null; } target.Inner.JobTitle = source.Title; target.Inner.OfficeLocation = source.Office; target.Inner.Profession = source.Role; MapHomePage2To1(source, target.Inner); MapCertificate2To1(source, target.Inner, logger); if (_configuration.MapContactPhoto) { await MapPhoto2To1(source, target.Inner, logger); } if (source.Notes.Count > 0) { target.Inner.Body = source.Notes[0].Text; } else { target.Inner.Body = string.Empty; } return(target); }