Esempio n. 1
0
        protected override async Task <IOutlookSynchronizer> InitializeOverride()
        {
            var synchronizerWithComponents = await TestComponentContainer.SynchronizerFactory.CreateSynchronizerWithComponents(Options, TestComponentContainer.GeneralOptions);

            var components = (AvailableContactSynchronizerComponents)synchronizerWithComponents.Item2;

            var synchronizer = synchronizerWithComponents.Item1;

            Components = components;
            Outlook    = EasyAccessRepositoryAdapter.Create(components.OutlookContactRepository, new SynchronizationContextFactory <ICardDavRepositoryLogger>(() => NullCardDavRepositoryLogger.Instance));
            Server     = EasyAccessRepositoryAdapter.Create(components.CardDavEntityRepository, new SynchronizationContextFactory <ICardDavRepositoryLogger> (() => NullCardDavRepositoryLogger.Instance));

            var distributionListSychronizationContextDummy = new DistributionListSychronizationContext(new CacheItem[0], new OutlookSession(TestComponentContainer.Application.Session), components.EntityRelationDataAccess, (Options.OutlookFolderEntryId, Options.OutlookFolderStoreId));

            if (components.OutlookDistListRepositoryOrNull != null)
            {
                OutlookDistListsOrNull = EasyAccessRepositoryAdapter.Create(components.OutlookDistListRepositoryOrNull, new SynchronizationContextFactory <DistributionListSychronizationContext> (() => distributionListSychronizationContextDummy));
            }
            if (components.SogoDistListRepositoryOrNull != null)
            {
                ServerSogoDistListsOrNull = EasyAccessRepositoryAdapter.Create(components.SogoDistListRepositoryOrNull, new SynchronizationContextFactory <DistributionListSychronizationContext> (() => distributionListSychronizationContextDummy));
            }
            if (components.VCardGroupRepositoryOrNull != null)
            {
                ServerVCardGroupsOrNull = EasyAccessRepositoryAdapter.Create(components.VCardGroupRepositoryOrNull, new SynchronizationContextFactory <DistributionListSychronizationContext> (() => distributionListSychronizationContextDummy));
            }

            return(synchronizer);
        }
        public async Task Synchronize(ISynchronizationLogger logger)
        {
            var emailAddressCache = new EmailAddressCache();

            emailAddressCache.Items = _emailAddressCacheDataAccess.Load();

            using (var subLogger = logger.CreateSubLogger("Contacts"))
            {
                await _contactSynchronizer.Synchronize(subLogger, emailAddressCache);
            }

            var idsToQuery = emailAddressCache.GetIdsOfEntriesWithEmptyEmailAddress();

            if (idsToQuery.Length > 0)
            {
                await _loggingCardDavRepositoryDecorator.Get(idsToQuery, NullLoadEntityLogger.Instance, emailAddressCache);
            }
            var cacheItems = emailAddressCache.Items;

            _emailAddressCacheDataAccess.Save(cacheItems);

            var distListContext = new DistributionListSychronizationContext(cacheItems, _outlookSession);

            using (var subLogger = logger.CreateSubLogger("DistLists"))
            {
                await _distributionListSynchronizer.Synchronize(subLogger, distListContext);
            }
        }
        public static void MapDistListMembers2To1(
            IEnumerable <DistributionListMember> sourceMembers,
            IDistListItemWrapper target,
            IEntityMappingLogger logger,
            DistributionListSychronizationContext context)
        {
            var outlookMembersByAddress = new Dictionary <string, GenericComObjectWrapper <Recipient> >(StringComparer.InvariantCultureIgnoreCase);

            try
            {
                for (int i = 1; i <= target.Inner.MemberCount; i++)
                {
                    var recipientWrapper = GenericComObjectWrapper.Create(target.Inner.GetMember(i));
                    if (!string.IsNullOrEmpty(recipientWrapper.Inner?.Address) &&
                        !outlookMembersByAddress.ContainsKey(recipientWrapper.Inner.Address))
                    {
                        outlookMembersByAddress.Add(recipientWrapper.Inner.Address, recipientWrapper);
                    }
                    else
                    {
                        recipientWrapper.Dispose();
                    }
                }

                foreach (var sourceMember in sourceMembers)
                {
                    GenericComObjectWrapper <Recipient> existingRecipient;
                    if (!string.IsNullOrEmpty(sourceMember.EmailAddress) &&
                        outlookMembersByAddress.TryGetValue(sourceMember.EmailAddress, out existingRecipient))
                    {
                        outlookMembersByAddress.Remove(sourceMember.EmailAddress);
                        existingRecipient.Dispose();
                    }
                    else
                    {
                        var recipientString = !string.IsNullOrEmpty(sourceMember.DisplayName) ? sourceMember.DisplayName : sourceMember.EmailAddress;

                        if (!string.IsNullOrEmpty(recipientString))
                        {
                            using (var recipientWrapper = GenericComObjectWrapper.Create(context.OutlookSession.CreateRecipient(recipientString)))
                            {
                                if (recipientWrapper.Inner.Resolve())
                                {
                                    target.Inner.AddMember(recipientWrapper.Inner);
                                }
                                else
                                {
                                    // Add a member which is not in the Addressbook
                                    var builder = new StringBuilder();
                                    if (!string.IsNullOrEmpty(sourceMember.DisplayName))
                                    {
                                        builder.Append(sourceMember.DisplayName);
                                        builder.Append(" <");
                                        builder.Append(sourceMember.EmailAddress);
                                        builder.Append(">");
                                    }
                                    else
                                    {
                                        builder.Append(sourceMember.EmailAddress);
                                    }
                                    using (var tempRecipientMember = GenericComObjectWrapper.Create(context.OutlookSession.CreateRecipient(builder.ToString())))
                                    {
                                        tempRecipientMember.Inner.Resolve();
                                        target.Inner.AddMember(tempRecipientMember.Inner);
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (var existingRecipient in outlookMembersByAddress.ToArray())
                {
                    target.Inner.RemoveMember(existingRecipient.Value.Inner);
                    outlookMembersByAddress.Remove(existingRecipient.Key);
                }
            }
            catch (COMException ex)
            {
                s_logger.Warn("Can't access member of Distribution List!", ex);
                logger.LogMappingWarning("Can't access member of Distribution List!", ex);
            }
            finally
            {
                foreach (var existingRecipient in outlookMembersByAddress.Values)
                {
                    existingRecipient.Dispose();
                }
            }
        }
Esempio n. 4
0
 protected override IEnumerable <DistributionListMember> GetMembers(vCard source, DistributionListSychronizationContext context, IEntitySynchronizationLogger synchronizationLogger, ILog logger)
 {
     foreach (var member in source.Members)
     {
         DistributionListMember distributionListMember;
         if (!string.IsNullOrEmpty(member.Uid))
         {
             (var contactWrapper, var emailAddress) = context.GetContactByUidOrNull(member.Uid, synchronizationLogger, logger);
             if (contactWrapper != null)
             {
                 using (contactWrapper)
                 {
                     distributionListMember = new DistributionListMember(emailAddress, contactWrapper.Inner.FullName);
                     yield return(distributionListMember);
                 }
             }
         }
         else
         {
             distributionListMember = new DistributionListMember(member.EmailAddress, member.DisplayName);
             yield return(distributionListMember);
         }
     }
 }
Esempio n. 5
0
        protected override vCardMember CreateVCardMemberOrNull(GenericComObjectWrapper <Recipient> recipientWrapper, string nameWithoutEmail, DistributionListSychronizationContext context, IEntitySynchronizationLogger synchronizationLogger, ILog logger)
        {
            var uid          = context.GetUidByEmailAddress(recipientWrapper.Inner.Address);
            var targetMember = new vCardMember();

            if (uid != null)
            {
                targetMember.Uid = uid;
            }
            else
            {
                targetMember.EmailAddress = recipientWrapper.Inner.Address;
                targetMember.DisplayName  = nameWithoutEmail;
            }
            return(targetMember);
        }
Esempio n. 6
0
 protected override IEnumerable <DistributionListMember> GetMembers(vCard source, DistributionListSychronizationContext context, IEntitySynchronizationLogger synchronizationLogger, ILog logger)
 {
     return(source.Members.Select(v => new DistributionListMember(v.EmailAddress, v.DisplayName)));
 }
 protected override IEnumerable <DistributionListMember> GetMembers(vCard source, DistributionListSychronizationContext context, IEntityMappingLogger mappingLogger, ILog logger)
 {
     foreach (var member in source.Members)
     {
         (var contactWrapper, var emailAddress) = context.GetContactByUidOrNull(member.Uid, mappingLogger, logger);
         if (contactWrapper != null)
         {
             DistributionListMember distributionListMember;
             using (contactWrapper)
             {
                 distributionListMember = new DistributionListMember(emailAddress, contactWrapper.Inner.FullName);
             }
             yield return(distributionListMember);
         }
     }
 }
        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);
        }
Esempio n. 9
0
        protected override vCardMember CreateVCardMemberOrNull(GenericComObjectWrapper <Recipient> recipientWrapper, string nameWithoutEmail, DistributionListSychronizationContext context, IEntityMappingLogger mappingLogger, ILog logger)
        {
            var targetMember = new vCardMember();

            targetMember.EmailAddress = recipientWrapper.Inner.Address;
            targetMember.DisplayName  = nameWithoutEmail;
            return(targetMember);
        }