protected override vCardMember CreateVCardMemberOrNull(GenericComObjectWrapper <Recipient> recipientWrapper, string nameWithoutEmail, DistributionListSychronizationContext context, IEntitySynchronizationLogger synchronizationLogger, ILog logger) { var targetMember = new vCardMember(); targetMember.EmailAddress = recipientWrapper.Inner.Address; targetMember.DisplayName = nameWithoutEmail; return(targetMember); }
protected override vCardMember CreateVCardMemberOrNull(GenericComObjectWrapper <Recipient> recipientWrapper, string nameWithoutEmail, DistributionListSychronizationContext context, IEntityMappingLogger mappingLogger, ILog logger) { var uid = context.GetUidByEmailAddress(recipientWrapper.Inner.Address); if (uid == null) { var logMessage = $"Did not find Uid of EmailAddress '{recipientWrapper.Inner.Address}'. Member won't be added to contact group"; logger.WarnFormat(logMessage); mappingLogger.LogMappingWarning(logMessage); } var targetMember = new vCardMember(); targetMember.Uid = uid; return(targetMember); }
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 = Regex.Replace(recipientWrapper.Inner.Name, " \\([^()]*\\)$", string.Empty); var targetMember = new vCardMember(); targetMember.EmailAddress = recipientWrapper.Inner.Address; targetMember.DisplayName = nameWithoutEmail; 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 async Task Synchronize_AnyCase_SyncsVCardGroupWithUidDistLists(bool useWebDavCollectionSync) { var options = TestComponentContainer.GetOptions("IntegrationTests/Contacts/Sogo"); options.UseWebDavCollectionSync = useWebDavCollectionSync; ((Contracts.ContactMappingConfiguration)options.MappingConfiguration).DistributionListType = Contracts.DistributionListType.VCardGroupWithUid; var synchronizer = await CreateSynchronizer(options); await synchronizer.ClearEventRepositoriesAndCache(); string nihilUid = null; await synchronizer.Server.CreateEntity( c => { c.EmailAddresses.Add(new vCardEmailAddress("*****@*****.**")); c.GivenName = "Nihil"; c.FamilyName = "Baxter"; nihilUid = c.UniqueId; }); string masonUid = null; var masonId = await synchronizer.Server.CreateEntity( c => { c.EmailAddresses.Add(new vCardEmailAddress("*****@*****.**")); c.GivenName = "Agent"; c.FamilyName = "Mason"; masonUid = c.UniqueId; }); string steinbergUid = null; var steinbergId = await synchronizer.Server.CreateEntity( c => { c.EmailAddresses.Add(new vCardEmailAddress("*****@*****.**")); c.GivenName = "Agent"; c.FamilyName = "Steinberg"; steinbergUid = c.UniqueId; }); await synchronizer.ServerVCardGroupsOrNull.CreateEntity( l => { l.FormattedName = "Agents"; l.FamilyName = "Agents"; var member = new vCardMember(); member.Uid = masonUid; l.Members.Add(member); member = new vCardMember(); member.Uid = steinbergUid; l.Members.Add(member); }); await synchronizer.SynchronizeAndAssertNoErrors(); var outlookNames = (await synchronizer.Outlook.GetAllEntities()).Select(c => c.Entity.Inner.LastName).ToArray(); CollectionAssert.AreEquivalent( new[] { "Baxter", "Mason", "Steinberg" }, outlookNames); using (var outlookDistList = (await synchronizer.OutlookDistListsOrNull.GetAllEntities()).SingleOrDefault()?.Entity) { Assert.That(outlookDistList, Is.Not.Null); Assert.That(outlookDistList.Inner.DLName, Is.EqualTo("Agents")); var outlookMembers = Enumerable .Range(1, outlookDistList.Inner.MemberCount) .Select(i => outlookDistList.Inner.GetMember(i)) .ToSafeEnumerable() .Select(d => d.Address) .ToArray(); CollectionAssert.AreEquivalent( new[] { "*****@*****.**", "*****@*****.**" }, outlookMembers); outlookDistList.Inner.DLName = "All"; var recipient = _testComponentContainer.Application.Session.CreateRecipient("Baxter"); Assert.That(recipient.Resolve(), Is.True); outlookDistList.Inner.AddMember(recipient); outlookDistList.Inner.Save(); } await synchronizer.SynchronizeAndAssertNoErrors(); var serverDistList = (await synchronizer.ServerVCardGroupsOrNull.GetAllEntities()).SingleOrDefault()?.Entity; Assert.That(serverDistList, Is.Not.Null); Assert.That(serverDistList.FormattedName, Is.EqualTo("All")); CollectionAssert.AreEquivalent( new[] { masonUid, nihilUid, steinbergUid }, serverDistList.Members.Select(m => m.Uid)); }