public static void GetOrganizationMailboxesByCapability(IRecipientSession session, OrganizationCapability capability, ADObjectId siteId, out List <ADUser> filteredList, out List <ADUser> completeList)
 {
     ExAssert.RetailAssert(!OrganizationMailbox.IsMultiTenantEnvironment(), "GetOrganizationMailboxesByCapability (site-based) should not be used in Datacenter Multitenant environment");
     ExTraceGlobals.StorageTracer.TraceDebug <OrganizationCapability>(0L, "Entering GetOrganizationMailboxByCapability capability='{0}'", capability);
     if (siteId == null)
     {
         throw new ArgumentNullException("siteId");
     }
     completeList = OrganizationMailbox.GetOrganizationMailboxesByCapability(session, capability);
     ExTraceGlobals.StorageTracer.TraceDebug <int, OrganizationCapability>(0L, "GetOrganizationMailboxByCapability -completeList of mailbox, count='{0}', capability='{1}'", completeList.Count, capability);
     filteredList = new List <ADUser>();
     if (completeList.Count > 0)
     {
         ExTraceGlobals.StorageTracer.TraceDebug <OrganizationCapability>(0L, "GetOrganizationMailboxByCapability -GetCurrentServiceTopology capability='{0}'", capability);
         ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\OrganizationMailbox\\OrganizationMailbox.cs", "GetOrganizationMailboxesByCapability", 137);
         foreach (ADUser aduser in completeList)
         {
             ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(session.SessionSettings, aduser, RemotingOptions.AllowCrossSite);
             string            serverFqdn        = exchangePrincipal.MailboxInfo.Location.ServerFqdn;
             ExTraceGlobals.StorageTracer.TraceDebug <string, OrganizationCapability>(0L, "GetOrganizationMailboxByCapability calling GetSite with Prinicipal.ServerFQDN='{0}', capability='{1}'", serverFqdn, capability);
             Site site       = currentServiceTopology.GetSite(serverFqdn, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\OrganizationMailbox\\OrganizationMailbox.cs", "GetOrganizationMailboxesByCapability", 151);
             Guid objectGuid = site.Id.ObjectGuid;
             ExTraceGlobals.StorageTracer.TraceDebug <string, Guid, OrganizationCapability>(0L, "GetOrganizationMailboxByCapability  GetSite called with Prinicipal.ServerFQDN='{0}', Site='{1}'capability='{2}'", serverFqdn, objectGuid, capability);
             if (siteId.ObjectGuid.Equals(objectGuid))
             {
                 filteredList.Add(aduser);
             }
         }
     }
 }
 public static ADUser[] FindByDatabaseId(OrganizationCapability capability, ADObjectId databaseId)
 {
     EnumValidator.ThrowIfInvalid <OrganizationCapability>(capability, "capability");
     if (!OrganizationMailbox.IsMultiTenantEnvironment())
     {
         return(OrganizationMailbox.InternalFindEnterprise(capability, databaseId));
     }
     return(OrganizationMailbox.InternalFindMultiTenant(capability, databaseId));
 }
        private static void GetQueryParameters(IRecipientSession session, out ADObjectId rootId, out QueryScope queryScope)
        {
            rootId     = null;
            queryScope = QueryScope.SubTree;
            OrganizationId currentOrganizationId = session.SessionSettings.CurrentOrganizationId;
            ConfigScopes   configScopes          = session.SessionSettings.ConfigScopes;

            if (currentOrganizationId == OrganizationId.ForestWideOrgId && OrganizationMailbox.IsScopeLimitedToFirstOrg(configScopes) && OrganizationMailbox.IsMultiTenantEnvironment())
            {
                ExTraceGlobals.StorageTracer.TraceDebug(0L, "Scoping search to First Org Users container in datacenter");
                rootId     = ADSystemConfigurationSession.GetFirstOrgUsersContainerId();
                queryScope = QueryScope.OneLevel;
                return;
            }
            ExTraceGlobals.StorageTracer.TraceDebug(0L, "Scoping search to rootId null");
        }
 public static bool TryFindByOrganizationId(OrganizationId organizationId, ADObjectId siteId, OrganizationCapability capability, out List <ADUser> siteUsers, out List <ADUser> allUsers)
 {
     ExAssert.RetailAssert(!OrganizationMailbox.IsMultiTenantEnvironment(), "TryFindByOrganizationId (site-based) should not be used in Datacenter Multitenant environment");
     OrganizationMailbox.GetOrganizationMailboxesByCapability(OrganizationMailbox.GetSession(organizationId, true), capability, siteId, out siteUsers, out allUsers);
     return(allUsers.Count > 0);
 }