public IEnumerable <GroupMailbox> GetJoinedGroups(UserMailboxLocator user, bool loadAllDetails = false)
 {
     using (IAssociationStore storeProvider = this.storeProviderBuilder.Create(user, this.PerformanceTracker))
     {
         GroupAssociationAdaptor          adaptor          = new GroupAssociationAdaptor(storeProvider, this.adSession, user);
         GetMembershipAssociations        command          = new GetMembershipAssociations(adaptor);
         IEnumerable <MailboxAssociation> joinAssociations = command.Execute(null);
         IEnumerable <GroupMailbox>       mailboxes        = this.mailboxCollectionBuilder.BuildGroupMailboxes(joinAssociations, loadAllDetails);
         foreach (GroupMailbox mailbox in mailboxes)
         {
             yield return(mailbox);
         }
     }
     yield break;
 }
        public IEnumerable <UserMailbox> GetUnseenMembers(GroupMailboxLocator group, IEnumerable <UserMailboxLocator> users)
        {
            IEnumerable <UserMailbox> result;

            using (IAssociationStore associationStore = this.storeProviderBuilder.Create(group, this.PerformanceTracker))
            {
                UnseenDataUserAssociationAdaptor        adaptor = new UnseenDataUserAssociationAdaptor(associationStore, this.adSession, group);
                GetMembershipAssociations               getMembershipAssociations = new GetMembershipAssociations(adaptor);
                IEnumerable <MailboxAssociation>        enumerable = getMembershipAssociations.Execute(null);
                Dictionary <string, MailboxAssociation> dictionary = new Dictionary <string, MailboxAssociation>(enumerable.Count <MailboxAssociation>());
                foreach (MailboxAssociation mailboxAssociation in enumerable)
                {
                    if (string.IsNullOrEmpty(mailboxAssociation.User.ExternalId))
                    {
                        GroupMailboxAccessLayer.LogWarning(this.Logger, "GetUnseenMembers", string.Format("External Id is null or empty. LegacyDn - {0}", mailboxAssociation.User.LegacyDn));
                    }
                    else if (dictionary.ContainsKey(mailboxAssociation.User.ExternalId))
                    {
                        GroupMailboxAccessLayer.LogWarning(this.Logger, "GetUnseenMembers", string.Format("Duplicate External Id. ExternalId - {0}. LegacyDn - {1}", mailboxAssociation.User.ExternalId, mailboxAssociation.User.LegacyDn));
                    }
                    else
                    {
                        dictionary.Add(mailboxAssociation.User.ExternalId, mailboxAssociation);
                    }
                }
                List <UserMailbox> list = new List <UserMailbox>();
                foreach (UserMailboxLocator userMailboxLocator in users)
                {
                    MailboxAssociation association = null;
                    if (!dictionary.TryGetValue(userMailboxLocator.ExternalId, out association))
                    {
                        association = this.CreateMailboxAssociationWithDefaultValues(userMailboxLocator, group);
                    }
                    UserMailboxBuilder userMailboxBuilder = new UserMailboxBuilder(userMailboxLocator, null);
                    list.Add(userMailboxBuilder.BuildFromAssociation(association).Mailbox);
                }
                result = list;
            }
            return(result);
        }
 public IEnumerable <UserMailbox> GetMembers(GroupMailboxLocator group, bool loadAllDetails = false, int?maxItems = null)
 {
     using (IAssociationStore storeProvider = this.storeProviderBuilder.Create(group, this.PerformanceTracker))
     {
         UserAssociationAdaptor                 adaptor       = new UserAssociationAdaptor(storeProvider, this.adSession, group);
         GetAssociationCommand                  command       = new GetMembershipAssociations(adaptor);
         IEnumerable <MailboxAssociation>       members       = command.Execute(maxItems);
         RpcAssociationReplicator               rpcReplicator = new RpcAssociationReplicator(this.Logger, storeProvider.ServerFullyQualifiedDomainName);
         ReplicatorEnabledAssociationEnumerator eventualConsistencyEnumerator = new ReplicatorEnabledAssociationEnumerator(rpcReplicator, members, storeProvider);
         try
         {
             IEnumerable <UserMailbox> mailboxes = this.mailboxCollectionBuilder.BuildUserMailboxes(group, eventualConsistencyEnumerator, loadAllDetails);
             foreach (UserMailbox mailbox in mailboxes)
             {
                 yield return(mailbox);
             }
         }
         finally
         {
             eventualConsistencyEnumerator.TriggerReplication(adaptor);
         }
     }
     yield break;
 }