public void Map1To2(TaskItemWrapper source, ITodo target, iCalTimeZone localIcalTimeZone, IEntityMappingLogger logger) { target.Summary = source.Inner.Subject; if (_configuration.MapBody) { target.Description = source.Inner.Body; } if (source.Inner.StartDate != _dateNull) { target.Start = new iCalDateTime(source.Inner.StartDate.Year, source.Inner.StartDate.Month, source.Inner.StartDate.Day, true); target.Start.SetTimeZone(localIcalTimeZone); } if (source.Inner.Complete && source.Inner.DateCompleted != _dateNull) { target.Completed = new iCalDateTime(source.Inner.DateCompleted.ToUniversalTime()) { IsUniversalTime = true, HasTime = true }; } target.PercentComplete = source.Inner.PercentComplete; if (_configuration.MapRecurringTasks) { MapRecurrance1To2(source.Inner, target, localIcalTimeZone); } if (source.Inner.DueDate != _dateNull) { target.Due = new iCalDateTime(source.Inner.DueDate.Year, source.Inner.DueDate.Month, source.Inner.DueDate.Day, 23, 59, 59); target.Due.SetTimeZone(localIcalTimeZone); // Workaround for a bug in DDay.iCal, according to RFC5545 DUE must not occur together with DURATION target.Properties.Remove(new CalendarProperty("DURATION")); } target.Properties.Set("STATUS", MapStatus1To2(source.Inner.Status)); if (_configuration.MapPriority) { target.Priority = CommonEntityMapper.MapPriority1To2(source.Inner.Importance); } target.Class = CommonEntityMapper.MapPrivacy1To2(source.Inner.Sensitivity, false); MapReminder1To2(source, target); MapCategories1To2(source, target); if (_configuration.MapCustomProperties || _configuration.UserDefinedCustomPropertyMappings.Length > 0) { using (var userPropertiesWrapper = GenericComObjectWrapper.Create(source.Inner.UserProperties)) { CommonEntityMapper.MapCustomProperties1To2(userPropertiesWrapper, target.Properties, _configuration.MapCustomProperties, _configuration.UserDefinedCustomPropertyMappings, logger, s_logger); } } }
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)); }
private void MapCategories1To2(ITaskItemWrapper source, ITodo target) { if (!string.IsNullOrEmpty(source.Inner.Categories)) { var useTaskCategoryAsFilter = _configuration.UseTaskCategoryAsFilter; var sourceCategories = CommonEntityMapper.SplitCategoryString(source.Inner.Categories) .Where(c => !useTaskCategoryAsFilter || c != _configuration.TaskCategory); foreach (var sourceCategory in sourceCategories) { target.Categories.Add(sourceCategory); } } }
public Task <vCard> Map1To2(IDistListItemWrapper source, vCard target, IEntityMappingLogger logger, DistributionListSychronizationContext context) { target.Members.Clear(); target.FormattedName = source.Inner.DLName; target.FamilyName = source.Inner.DLName; target.AccessClassification = CommonEntityMapper.MapPrivacy1To2(source.Inner.Sensitivity); target.Categories.Clear(); if (!string.IsNullOrEmpty(source.Inner.Categories)) { Array.ForEach( source.Inner.Categories.Split(new[] { CultureInfo.CurrentCulture.TextInfo.ListSeparator }, StringSplitOptions.RemoveEmptyEntries), c => target.Categories.Add(c.Trim()) ); } target.Notes.Clear(); if (!string.IsNullOrEmpty(source.Inner.Body)) { target.Notes.Add(new vCardNote(source.Inner.Body)); } for (int i = 1; i <= source.Inner.MemberCount; i++) { try { using (var recipientWrapper = GenericComObjectWrapper.Create(source.Inner.GetMember(i))) { var nameWithoutEmail = OutlookUtility.RemoveEmailFromName(recipientWrapper.Inner); var targetMember = CreateVCardMemberOrNull(recipientWrapper, nameWithoutEmail, context, logger, s_logger); if (targetMember != null) { target.Members.Add(targetMember); } } } catch (COMException ex) { s_logger.Warn("Can't access member of Distribution List!", ex); logger.LogMappingWarning("Can't access member of Distribution List!", ex); } } return(Task.FromResult(target)); }
public void Map1To2(TaskItemWrapper source, ITodo target, iCalTimeZone localIcalTimeZone) { target.Summary = source.Inner.Subject; target.Description = source.Inner.Body; if (source.Inner.StartDate != _dateNull) { target.Start = new iCalDateTime(source.Inner.StartDate.Year, source.Inner.StartDate.Month, source.Inner.StartDate.Day, true); target.Start.SetTimeZone(localIcalTimeZone); } if (source.Inner.DueDate != _dateNull) { target.Due = new iCalDateTime(source.Inner.DueDate.Year, source.Inner.DueDate.Month, source.Inner.DueDate.Day, 23, 59, 59); target.Due.SetTimeZone(localIcalTimeZone); // Workaround for a bug in DDay.iCal, according to RFC5545 DUE must not occur together with DURATION target.Properties.Remove(new CalendarProperty("DURATION")); } if (source.Inner.Complete && source.Inner.DateCompleted != _dateNull) { target.Completed = new iCalDateTime(source.Inner.DateCompleted.Year, source.Inner.DateCompleted.Month, source.Inner.DateCompleted.Day, true); target.Completed.SetTimeZone(localIcalTimeZone); } target.PercentComplete = source.Inner.PercentComplete; MapRecurrance1To2(source.Inner, target, localIcalTimeZone); target.Properties.Set("STATUS", MapStatus1To2(source.Inner.Status)); target.Priority = CommonEntityMapper.MapPriority1To2(source.Inner.Importance); target.Class = CommonEntityMapper.MapPrivacy1To2(source.Inner.Sensitivity, false); MapReminder1To2(source, target); MapCategories1To2(source, target); }
public Task <IDistListItemWrapper> Map2To1(DistributionList source, IDistListItemWrapper target, IEntityMappingLogger logger, DistributionListSychronizationContext context) { target.Inner.DLName = source.Name; if (!string.IsNullOrEmpty(source.Description)) { target.Inner.Body = source.Description; } try { using (var userPropertiesWrapper = GenericComObjectWrapper.Create(target.Inner.UserProperties)) { using (var userProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Find("NICKNAME"))) { if (userProperty.Inner != null) { userProperty.Inner.Value = source.Nickname; } else if (!string.IsNullOrEmpty(source.Nickname)) { using (var newUserProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Add("NICKNAME", OlUserPropertyType.olText, true))) { newUserProperty.Inner.Value = source.Nickname; } } } } } catch (COMException ex) { s_logger.Warn("Can't access UserProperty of Distribution List!", ex); logger.LogMappingWarning("Can't access UserProperty of Distribution List!", ex); } CommonEntityMapper.MapDistListMembers2To1(source.Members.Concat(source.NonAddressBookMembers), target, logger, context); return(Task.FromResult(target)); }
public GoogleContactWrapper Map1To2(ContactItemWrapper source, GoogleContactWrapper targetWrapper, IEntityMappingLogger logger) { var target = targetWrapper.Contact; #region Title/FileAs if (!string.IsNullOrEmpty(source.Inner.FileAs)) { target.Title = source.Inner.FileAs; } else if (!string.IsNullOrEmpty(source.Inner.CompanyAndFullName)) { target.Title = source.Inner.CompanyAndFullName; } else if (!string.IsNullOrEmpty(source.Inner.FullName)) { target.Title = source.Inner.FullName; } else if (!string.IsNullOrEmpty(source.Inner.CompanyName)) { target.Title = source.Inner.CompanyName; } else if (!string.IsNullOrEmpty(source.Inner.Email1Address)) { target.Title = source.Inner.Email1Address; } #endregion Title/FileAs #region Name Name name = new Name() { GivenName = source.Inner.FirstName, FamilyName = source.Inner.LastName, AdditionalName = source.Inner.MiddleName, NamePrefix = source.Inner.Title, NameSuffix = source.Inner.Suffix, }; //Use the Google's full name to save a unique identifier. When saving the FullName, it always overwrites the Google Title if (!string.IsNullOrEmpty(source.Inner.FullName)) //Only if source.FullName has a value, i.e. not only a company or email contact { name.FullName = source.Inner.FileAs; } target.Name = name; #endregion Name MapEmailAddresses1To2(source.Inner, target, logger); MapPostalAddresses1To2(source.Inner, target); MapPhoneNumbers1To2(source.Inner, target); target.ContactEntry.Nickname = source.Inner.NickName; target.ContactEntry.Initials = source.Inner.Initials; #region company target.Organizations.Clear(); if (!string.IsNullOrEmpty(source.Inner.Companies)) { //Companies are expected to be in form of "[Company]; [Company]". string[] companiesRaw = source.Inner.Companies.Split(';'); foreach (string companyRaw in companiesRaw) { Organization company = new Organization(); company.Name = (target.Organizations.Count == 0) ? source.Inner.CompanyName : companyRaw; company.Title = (target.Organizations.Count == 0) ? source.Inner.JobTitle : null; company.Department = (target.Organizations.Count == 0) ? source.Inner.Department : null; company.Primary = target.Organizations.Count == 0; company.Rel = ContactsRelationships.IsWork; target.Organizations.Add(company); } } if (target.Organizations.Count == 0 && (!string.IsNullOrEmpty(source.Inner.CompanyName) || !string.IsNullOrEmpty(source.Inner.Department) || !string.IsNullOrEmpty(source.Inner.JobTitle))) { target.Organizations.Add(new Organization() { Name = source.Inner.CompanyName, Department = source.Inner.Department, Title = source.Inner.JobTitle, Rel = ContactsRelationships.IsWork, Primary = true, }); } #endregion company target.ContactEntry.Occupation = source.Inner.Profession; target.Location = source.Inner.OfficeLocation; target.ContactEntry.Websites.Clear(); if (!string.IsNullOrEmpty(source.Inner.WebPage)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.WebPage, Rel = REL_HOMEPAGE, Primary = true, }); } if (!string.IsNullOrEmpty(source.Inner.BusinessHomePage)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.BusinessHomePage, Rel = REL_WORK, Primary = target.ContactEntry.Websites.Count == 0, }); } if (!string.IsNullOrEmpty(source.Inner.PersonalHomePage)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.PersonalHomePage, Rel = REL_HOME, Primary = target.ContactEntry.Websites.Count == 0, }); } if (!string.IsNullOrEmpty(source.Inner.FTPSite)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.FTPSite, Rel = REL_FTP, Primary = target.ContactEntry.Websites.Count == 0, }); } #region birthday if (_configuration.MapBirthday && !source.Inner.Birthday.Equals(OU_OUTLOOK_DATE_NONE)) { target.ContactEntry.Birthday = source.Inner.Birthday.ToString("yyyy-MM-dd"); } else { target.ContactEntry.Birthday = null; } #endregion birthday #region anniversary //Todo: Check, if (_configuration.MapAnniversary) //{ //First remove anniversary foreach (Event ev in target.ContactEntry.Events) { if (ev.Relation != null && ev.Relation.Equals(REL_ANNIVERSARY)) { target.ContactEntry.Events.Remove(ev); break; } } try { //Then add it again if existing if (!source.Inner.Anniversary.Equals(OU_OUTLOOK_DATE_NONE)) //earlier also || source.Inner.Birthday.Year < 1900 { Event ev = new Event(); ev.Relation = REL_ANNIVERSARY; ev.When = new When(); ev.When.AllDay = true; ev.When.StartTime = source.Inner.Anniversary.Date; target.ContactEntry.Events.Add(ev); } } catch (System.Exception ex) { s_logger.Warn("Anniversary couldn't be updated from Outlook to Google for '" + source.Inner.FileAs + "': " + ex.Message, ex); logger.LogMappingWarning("Anniversary couldn't be updated from Outlook to Google for '" + source.Inner.FileAs + "': " + ex.Message, ex); } //} #endregion anniversary #region relations (spouse, child, manager and assistant) //First remove spouse, child, manager and assistant for (int i = target.ContactEntry.Relations.Count - 1; i >= 0; i--) { Relation rel = target.ContactEntry.Relations[i]; if (rel.Rel != null && (rel.Rel.Equals(REL_SPOUSE) || rel.Rel.Equals(REL_CHILD) || rel.Rel.Equals(REL_MANAGER) || rel.Rel.Equals(REL_ASSISTANT))) { target.ContactEntry.Relations.RemoveAt(i); } } //Then add spouse again if existing if (!string.IsNullOrEmpty(source.Inner.Spouse)) { Relation rel = new Relation(); rel.Rel = REL_SPOUSE; rel.Value = source.Inner.Spouse; target.ContactEntry.Relations.Add(rel); } //Then add children again if existing if (!string.IsNullOrEmpty(source.Inner.Children)) { Relation rel = new Relation(); rel.Rel = REL_CHILD; rel.Value = source.Inner.Children; target.ContactEntry.Relations.Add(rel); } //Then add manager again if existing if (!string.IsNullOrEmpty(source.Inner.ManagerName)) { Relation rel = new Relation(); rel.Rel = REL_MANAGER; rel.Value = source.Inner.ManagerName; target.ContactEntry.Relations.Add(rel); } //Then add assistant again if existing if (!string.IsNullOrEmpty(source.Inner.AssistantName)) { Relation rel = new Relation(); rel.Rel = REL_ASSISTANT; rel.Value = source.Inner.AssistantName; target.ContactEntry.Relations.Add(rel); } #endregion relations (spouse, child, manager and assistant) #region IMs target.IMs.Clear(); if (!string.IsNullOrEmpty(source.Inner.IMAddress)) { //IMAddress are expected to be in form of ([Protocol]: [Address]; [Protocol]: [Address]) string[] imsRaw = source.Inner.IMAddress.Split(';'); foreach (string imRaw in imsRaw) { string[] imDetails = imRaw.Trim().Split(':'); IMAddress im = new IMAddress(); if (imDetails.Length == 1) { im.Address = imDetails[0].Trim(); } else { im.Protocol = imDetails[0].Trim(); im.Address = imDetails[1].Trim(); } //Only add the im Address if not empty (to avoid Google exception "address" empty) if (!string.IsNullOrEmpty(im.Address)) { im.Primary = target.IMs.Count == 0; im.Rel = ContactsRelationships.IsHome; target.IMs.Add(im); } } } #endregion IMs target.Content = !string.IsNullOrEmpty(source.Inner.Body) ? System.Security.SecurityElement.Escape(source.Inner.Body) : null; target.ContactEntry.Sensitivity = MapPrivacy1To2(source.Inner.Sensitivity); target.Languages.Clear(); if (!string.IsNullOrEmpty(source.Inner.Language)) { foreach (var lang in source.Inner.Language.Split(';')) { target.Languages.Add(new Language() { Label = lang }); } } target.ContactEntry.Hobbies.Clear(); if (!string.IsNullOrEmpty(source.Inner.Hobby)) { foreach (var hobby in source.Inner.Hobby.Split(';')) { target.ContactEntry.Hobbies.Add(new Hobby(hobby)); } } targetWrapper.Groups.Clear(); targetWrapper.Groups.AddRange(CommonEntityMapper.SplitCategoryString(source.Inner.Categories)); if (_configuration.MapContactPhoto) { MapPhoto1To2(source.Inner, targetWrapper, logger); } return(targetWrapper); }
public Task <vCard> Map1To2(IContactItemWrapper source, vCard target, IEntitySynchronizationLogger logger, ICardDavRepositoryLogger context) { target.RevisionDate = source.Inner.LastModificationTime.ToUniversalTime(); target.GivenName = source.Inner.FirstName; target.FamilyName = source.Inner.LastName; target.NamePrefix = source.Inner.Title; target.NameSuffix = source.Inner.Suffix; target.AdditionalNames = source.Inner.MiddleName; target.Gender = MapGender2To1(source.Inner.Gender); target.Assistant = source.Inner.AssistantName; target.Spouse = source.Inner.Spouse; target.Manager = source.Inner.ManagerName; MapEmailAddresses1To2(source.Inner, target, logger); if (!string.IsNullOrEmpty(source.Inner.FileAs)) { target.FormattedName = source.Inner.FileAs; } else if (!string.IsNullOrEmpty(source.Inner.CompanyAndFullName)) { target.FormattedName = source.Inner.CompanyAndFullName; } else if (target.EmailAddresses.Count >= 1) { target.FormattedName = target.EmailAddresses[0].Address; } else { target.FormattedName = "<Empty>"; } target.Nicknames.Clear(); if (!string.IsNullOrEmpty(source.Inner.NickName)) { Array.ForEach( source.Inner.NickName.Split(new[] { CultureInfo.CurrentCulture.TextInfo.ListSeparator }, StringSplitOptions.RemoveEmptyEntries), c => target.Nicknames.Add(c) ); } target.AccessClassification = CommonEntityMapper.MapPrivacy1To2(source.Inner.Sensitivity); target.Categories.Clear(); if (!string.IsNullOrEmpty(source.Inner.Categories)) { Array.ForEach( source.Inner.Categories.Split(new[] { CultureInfo.CurrentCulture.TextInfo.ListSeparator }, StringSplitOptions.RemoveEmptyEntries), c => target.Categories.Add(c.Trim()) ); } target.IMs.Clear(); if (!string.IsNullOrEmpty(source.Inner.IMAddress)) { //IMAddress are expected to be in form of ([Protocol]: [Address]; [Protocol]: [Address]) var imsRaw = source.Inner.IMAddress.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var imRaw in imsRaw) { var imDetails = imRaw.Trim().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); var im = new vCardIMPP(); if (imDetails.Length == 1) { im.Handle = imDetails[0].Trim(); // Set default ServiceType to the configured DefaultImServiceType (defaults to AIM) im.ServiceType = _configuration.DefaultImServicType; } else if (imDetails.Length > 1) { var serviceType = IMTypeUtils.GetIMServiceType(imDetails[0].Trim()); if (serviceType == null) { im.ServiceType = _configuration.DefaultImServicType; s_logger.Warn($"Unknown IM ServiceType '{imDetails[0]}' not implemented, defaulting to '{_configuration.DefaultImServicType}'"); logger.LogWarning($"Unknown IM ServiceType '{imDetails[0]}' not implemented, defaulting to '{_configuration.DefaultImServicType}'"); } else { im.ServiceType = serviceType.Value; } im.Handle = imRaw.Substring(imRaw.IndexOf(":") + 1).Trim(); } //Only add the im Address if not empty if (!string.IsNullOrEmpty(im.Handle)) { im.IsPreferred = target.IMs.Count == 0; im.ItemType = ItemType.HOME; target.IMs.Add(im); } } } target.DeliveryAddresses.Clear(); if (!string.IsNullOrEmpty(source.Inner.HomeAddress)) { vCardDeliveryAddress homeAddress = new vCardDeliveryAddress(); homeAddress.AddressType.Add(vCardDeliveryAddressTypes.Home); homeAddress.City = source.Inner.HomeAddressCity; homeAddress.Country = source.Inner.HomeAddressCountry; homeAddress.PostalCode = source.Inner.HomeAddressPostalCode; homeAddress.Region = source.Inner.HomeAddressState; homeAddress.Street = source.Inner.HomeAddressStreet; homeAddress.PoBox = source.Inner.HomeAddressPostOfficeBox; if (source.Inner.SelectedMailingAddress == OlMailingAddress.olHome) { homeAddress.AddressType.Add(vCardDeliveryAddressTypes.Preferred); } target.DeliveryAddresses.Add(homeAddress); } if (!string.IsNullOrEmpty(source.Inner.BusinessAddress) || !string.IsNullOrEmpty(source.Inner.OfficeLocation)) { vCardDeliveryAddress businessAddress = new vCardDeliveryAddress(); businessAddress.AddressType.Add(vCardDeliveryAddressTypes.Work); businessAddress.City = source.Inner.BusinessAddressCity; businessAddress.Country = source.Inner.BusinessAddressCountry; businessAddress.PostalCode = source.Inner.BusinessAddressPostalCode; businessAddress.Region = source.Inner.BusinessAddressState; businessAddress.Street = source.Inner.BusinessAddressStreet; businessAddress.PoBox = source.Inner.BusinessAddressPostOfficeBox; if (!string.IsNullOrEmpty(source.Inner.OfficeLocation)) { businessAddress.ExtendedAddress = source.Inner.OfficeLocation; } if (source.Inner.SelectedMailingAddress == OlMailingAddress.olBusiness) { businessAddress.AddressType.Add(vCardDeliveryAddressTypes.Preferred); } target.DeliveryAddresses.Add(businessAddress); } if (!string.IsNullOrEmpty(source.Inner.OtherAddress)) { vCardDeliveryAddress otherAddress = new vCardDeliveryAddress(); otherAddress.City = source.Inner.OtherAddressCity; otherAddress.Country = source.Inner.OtherAddressCountry; otherAddress.PostalCode = source.Inner.OtherAddressPostalCode; otherAddress.Region = source.Inner.OtherAddressState; otherAddress.Street = source.Inner.OtherAddressStreet; otherAddress.PoBox = source.Inner.OtherAddressPostOfficeBox; if (source.Inner.SelectedMailingAddress == OlMailingAddress.olOther) { otherAddress.AddressType.Add(vCardDeliveryAddressTypes.Preferred); } target.DeliveryAddresses.Add(otherAddress); } MapPhoneNumbers1To2(source.Inner, target); if (_configuration.MapAnniversary) { target.Anniversary = source.Inner.Anniversary.Equals(OutlookUtility.OUTLOOK_DATE_NONE) ? default(DateTime?) : source.Inner.Anniversary.Date; } if (_configuration.MapBirthday) { target.BirthDate = source.Inner.Birthday.Equals(OutlookUtility.OUTLOOK_DATE_NONE) ? default(DateTime?) : source.Inner.Birthday.Date; } target.Organization = source.Inner.CompanyName; target.Department = source.Inner.Department; target.Title = source.Inner.JobTitle; target.Role = source.Inner.Profession; target.Websites.Clear(); if (!string.IsNullOrEmpty(source.Inner.PersonalHomePage)) { target.Websites.Add(new vCardWebsite(source.Inner.PersonalHomePage, vCardWebsiteTypes.Personal)); } if (!string.IsNullOrEmpty(source.Inner.BusinessHomePage)) { target.Websites.Add(new vCardWebsite(source.Inner.BusinessHomePage, vCardWebsiteTypes.Work)); } MapCertificate1To2(source.Inner, target, logger); if (_configuration.MapContactPhoto) { MapPhoto1To2(source.Inner, target, logger); } target.Notes.Clear(); if (!string.IsNullOrEmpty(source.Inner.Body)) { target.Notes.Add(new vCardNote(source.Inner.Body)); } 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); }
private void MapRecurrance2To1(ITodo source, TaskItemWrapper targetWrapper, IEntityMappingLogger logger) { if (source.RecurrenceRules.Count > 0) { using (var targetRecurrencePatternWrapper = GenericComObjectWrapper.Create(targetWrapper.Inner.GetRecurrencePattern())) { var targetRecurrencePattern = targetRecurrencePatternWrapper.Inner; if (source.RecurrenceRules.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one recurrence rule. Since outlook supports only one rule, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one recurrence rule. Since outlook supports only one rule, all except the first one will be ignored."); } var sourceRecurrencePattern = source.RecurrenceRules[0]; switch (sourceRecurrencePattern.Frequency) { case FrequencyType.Daily: targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursDaily; break; case FrequencyType.Weekly: if (sourceRecurrencePattern.ByDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursWeekly; targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursWeekly; } break; case FrequencyType.Monthly: if (sourceRecurrencePattern.ByDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursMonthNth; if (sourceRecurrencePattern.ByWeekNo.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one week in a monthly recurrence rule. Since outlook supports only one week, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one week in a monthly recurrence rule. Since outlook supports only one week, all except the first one will be ignored."); } else if (sourceRecurrencePattern.ByWeekNo.Count > 0) { targetRecurrencePattern.Instance = sourceRecurrencePattern.ByWeekNo[0]; } else { targetRecurrencePattern.Instance = (sourceRecurrencePattern.ByDay[0].Offset >= 0) ? sourceRecurrencePattern.ByDay[0].Offset : 5; } if (sourceRecurrencePattern.BySetPosition.Count > 0) { targetRecurrencePattern.Instance = (sourceRecurrencePattern.BySetPosition[0] >= 0) ? sourceRecurrencePattern.BySetPosition[0] : 5; } targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.ByMonthDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursMonthly; if (sourceRecurrencePattern.ByMonthDay.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored."); } try { targetRecurrencePattern.DayOfMonth = sourceRecurrencePattern.ByMonthDay[0]; } catch (COMException ex) { s_logger.Warn($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); logger.LogMappingWarning($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); } } else { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursMonthly; } break; case FrequencyType.Yearly: if (sourceRecurrencePattern.ByMonth.Count > 0 && sourceRecurrencePattern.ByWeekNo.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearNth; if (sourceRecurrencePattern.ByMonth.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored."); } targetRecurrencePattern.MonthOfYear = sourceRecurrencePattern.ByMonth[0]; if (sourceRecurrencePattern.ByWeekNo.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one week in a yearly recurrence rule. Since outlook supports only one week, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one week in a yearly recurrence rule. Since outlook supports only one week, all except the first one will be ignored."); } targetRecurrencePattern.Instance = sourceRecurrencePattern.ByWeekNo[0]; targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.ByMonth.Count > 0 && sourceRecurrencePattern.ByMonthDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearly; if (sourceRecurrencePattern.ByMonth.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored."); } if (sourceRecurrencePattern.ByMonth[0] != targetRecurrencePattern.MonthOfYear) { targetRecurrencePattern.MonthOfYear = sourceRecurrencePattern.ByMonth[0]; } if (sourceRecurrencePattern.ByMonthDay.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored."); } if (sourceRecurrencePattern.ByMonthDay[0] != targetRecurrencePattern.DayOfMonth) { try { targetRecurrencePattern.DayOfMonth = sourceRecurrencePattern.ByMonthDay[0]; } catch (COMException ex) { s_logger.Warn($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); logger.LogMappingWarning($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); } } } else if (sourceRecurrencePattern.ByMonth.Count > 0 && sourceRecurrencePattern.ByDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearNth; if (sourceRecurrencePattern.ByMonth.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored."); } targetRecurrencePattern.MonthOfYear = sourceRecurrencePattern.ByMonth[0]; targetRecurrencePattern.Instance = (sourceRecurrencePattern.ByDay[0].Offset >= 0) ? sourceRecurrencePattern.ByDay[0].Offset : 5; if (sourceRecurrencePattern.BySetPosition.Count > 0) { targetRecurrencePattern.Instance = (sourceRecurrencePattern.BySetPosition[0] >= 0) ? sourceRecurrencePattern.BySetPosition[0] : 5; } targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearly; } break; default: s_logger.WarnFormat("Recurring task '{0}' contains the Frequency '{1}', which is not supported by outlook. Ignoring recurrence rule.", source.UID, sourceRecurrencePattern.Frequency); logger.LogMappingWarning($"Recurring task contains the Frequency '{sourceRecurrencePattern.Frequency}', which is not supported by outlook. Ignoring recurrence rule."); targetWrapper.Inner.ClearRecurrencePattern(); break; } try { targetRecurrencePattern.Interval = (targetRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly || targetRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval * 12 : sourceRecurrencePattern.Interval; } catch (COMException ex) { s_logger.Warn(string.Format("Recurring task '{0}' contains the Interval '{1}', which is not supported by outlook. Ignoring interval.", source.UID, sourceRecurrencePattern.Interval), ex); logger.LogMappingWarning($"Recurring task contains the Interval '{sourceRecurrencePattern.Interval}', which is not supported by outlook. Ignoring interval.", ex); } if (sourceRecurrencePattern.Count >= 0) { targetRecurrencePattern.Occurrences = sourceRecurrencePattern.Count; } if (sourceRecurrencePattern.Until != default(DateTime)) { if (sourceRecurrencePattern.Until.Date >= targetRecurrencePattern.PatternStartDate) { targetRecurrencePattern.PatternEndDate = sourceRecurrencePattern.Until.Date; } else { targetRecurrencePattern.PatternEndDate = targetRecurrencePattern.PatternStartDate; } } } targetWrapper.SaveAndReload(); } }
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); }
private void MapRecurrance1To2(TaskItem source, ITodo target, iCalTimeZone localIcalTimeZone) { if (source.IsRecurring) { using (var sourceRecurrencePatternWrapper = GenericComObjectWrapper.Create(source.GetRecurrencePattern())) { var sourceRecurrencePattern = sourceRecurrencePatternWrapper.Inner; IRecurrencePattern targetRecurrencePattern = new RecurrencePattern(); if (!sourceRecurrencePattern.NoEndDate) { targetRecurrencePattern.Count = sourceRecurrencePattern.Occurrences; //Until must not be set if count is set, since outlook always sets Occurrences //but sogo wants it as utc end time of the last event not only the enddate at 0000 //targetRecurrencePattern.Until = sourceRecurrencePattern.PatternEndDate.Add(sourceRecurrencePattern.EndTime.TimeOfDay).ToUniversalTime(); } targetRecurrencePattern.Interval = (sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly || sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval / 12 : sourceRecurrencePattern.Interval; switch (sourceRecurrencePattern.RecurrenceType) { case OlRecurrenceType.olRecursDaily: targetRecurrencePattern.Frequency = FrequencyType.Daily; break; case OlRecurrenceType.olRecursWeekly: targetRecurrencePattern.Frequency = FrequencyType.Weekly; CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); break; case OlRecurrenceType.olRecursMonthly: targetRecurrencePattern.Frequency = FrequencyType.Monthly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); break; case OlRecurrenceType.olRecursMonthNth: targetRecurrencePattern.Frequency = FrequencyType.Monthly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } break; case OlRecurrenceType.olRecursYearly: targetRecurrencePattern.Frequency = FrequencyType.Yearly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; case OlRecurrenceType.olRecursYearNth: targetRecurrencePattern.Frequency = FrequencyType.Yearly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; } target.RecurrenceRules.Add(targetRecurrencePattern); } } }
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); }
private void MapRecurrance1To2(TaskItem source, ITodo target, iCalTimeZone localIcalTimeZone) { if (source.IsRecurring) { using (var sourceRecurrencePatternWrapper = GenericComObjectWrapper.Create(source.GetRecurrencePattern())) { var sourceRecurrencePattern = sourceRecurrencePatternWrapper.Inner; // Recurring task must have a DTSTART according to the RFC but Outlook may have no task start date set, use PatternStartDate in this case if (source.StartDate == OutlookUtility.OUTLOOK_DATE_NONE) { target.Start = new iCalDateTime(sourceRecurrencePattern.PatternStartDate.Year, sourceRecurrencePattern.PatternStartDate.Month, sourceRecurrencePattern.PatternStartDate.Day, true); if (!_configuration.MapStartAndDueAsFloating) { target.Start.SetTimeZone(localIcalTimeZone); } } IRecurrencePattern targetRecurrencePattern = new RecurrencePattern(); // Don't set Count if pattern has NoEndDate or invalid Occurences for some reason. if (!sourceRecurrencePattern.NoEndDate && sourceRecurrencePattern.Occurrences > 0) { targetRecurrencePattern.Count = sourceRecurrencePattern.Occurrences; //Until must not be set if count is set, since outlook always sets Occurrences //but sogo wants it as utc end time of the last event not only the enddate at 0000 //targetRecurrencePattern.Until = sourceRecurrencePattern.PatternEndDate.Add(sourceRecurrencePattern.EndTime.TimeOfDay).ToUniversalTime(); } targetRecurrencePattern.Interval = (sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly || sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval / 12 : sourceRecurrencePattern.Interval; switch (sourceRecurrencePattern.RecurrenceType) { case OlRecurrenceType.olRecursDaily: targetRecurrencePattern.Frequency = FrequencyType.Daily; break; case OlRecurrenceType.olRecursWeekly: targetRecurrencePattern.Frequency = FrequencyType.Weekly; CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); break; case OlRecurrenceType.olRecursMonthly: targetRecurrencePattern.Frequency = FrequencyType.Monthly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); break; case OlRecurrenceType.olRecursMonthNth: targetRecurrencePattern.Frequency = FrequencyType.Monthly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } break; case OlRecurrenceType.olRecursYearly: targetRecurrencePattern.Frequency = FrequencyType.Yearly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; case OlRecurrenceType.olRecursYearNth: targetRecurrencePattern.Frequency = FrequencyType.Yearly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; } target.RecurrenceRules.Add(targetRecurrencePattern); } } }
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); }