示例#1
0
        public async Task <EntityVersion <string, DateTime> > TryUpdate(
            string entityId,
            DateTime entityVersion,
            IDistListItemWrapper entityToUpdate,
            Func <IDistListItemWrapper, Task <IDistListItemWrapper> > entityModifier,
            Tcontext context)
        {
            entityToUpdate = await entityModifier(entityToUpdate);

            entityToUpdate.Inner.Save();
            return(new EntityVersion <string, DateTime> (entityToUpdate.Inner.EntryID, entityToUpdate.Inner.LastModificationTime));
        }
        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();
                }
            }
        }
 public TestDistListItemWrapper(Action <TestDistListItemWrapper> onDisposed, IDistListItemWrapper inner) : base(onDisposed)
 {
     _inner = inner ?? throw new ArgumentNullException(nameof(inner));
 }
示例#4
0
 public string ACreateOrNull(IDistListItemWrapper entity)
 {
     return(entity.Inner.DLName);
 }
 public void Cleanup(IDistListItemWrapper entity)
 {
     entity.Dispose();
 }
示例#6
0
 public string GetADisplayNameOrNull(IDistListItemWrapper entity)
 {
     return(entity.Inner.DLName);
 }