Example #1
0
        internal override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason)
        {
            notFoundReason = null;
            if (typeof(T) != typeof(ADUser))
            {
                throw new ArgumentException(Strings.ErrorInvalidType(typeof(T).Name), "type");
            }
            List <ADUser> list   = new List <ADUser>();
            ADUser        aduser = null;
            Guid          exchangeGuid;
            WindowsLiveId windowsLiveId;

            if (Guid.TryParse(base.RawIdentity, out exchangeGuid))
            {
                aduser = ((IRecipientSession)session).FindByExchangeGuidIncludingAlternate <ADUser>(exchangeGuid);
            }
            else if (ConsumerMailboxIdParameter.TryParseWindowsLiveId(base.RawIdentity, out windowsLiveId))
            {
                if (windowsLiveId.NetId != null)
                {
                    aduser = ((IRecipientSession)session).FindByExchangeGuidIncludingAlternate <ADUser>(ConsumerIdentityHelper.GetExchangeGuidFromPuid(windowsLiveId.NetId.ToUInt64()));
                }
                else
                {
                    aduser = ((IRecipientSession)session).FindByProxyAddress <ADUser>(new SmtpProxyAddress(windowsLiveId.SmtpAddress.ToString(), true));
                }
            }
            else if (base.InternalADObjectId != null)
            {
                aduser = ((IRecipientSession)session).FindADUserByObjectId(base.InternalADObjectId);
            }
            if (aduser != null)
            {
                list.Add(aduser);
            }
            return(list as IEnumerable <T>);
        }
        internal override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason)
        {
            TaskLogger.LogEnter();
            if (!typeof(ADRecipient).IsAssignableFrom(typeof(T)) && !typeof(ReducedRecipient).IsAssignableFrom(typeof(T)))
            {
                throw new ArgumentException(Strings.ErrorInvalidType(typeof(T).Name), "type");
            }
            if (Globals.IsConsumerOrganization(session.SessionSettings.CurrentOrganizationId) && ADSessionFactory.UseAggregateSession(session.SessionSettings))
            {
                return(ConsumerMailboxIdParameter.Parse(base.RawIdentity).GetObjects <T>(rootId, session, subTreeSession, optionalData, out notFoundReason));
            }
            EnumerableWrapper <T> enumerableWrapper = EnumerableWrapper <T> .GetWrapper(base.GetObjects <T>(rootId, session, subTreeSession, optionalData, out notFoundReason));

            if (!enumerableWrapper.HasElements() && session is IRecipientSession)
            {
                enumerableWrapper = base.GetEnumerableWrapper <T>(enumerableWrapper, this.GetObjectsByAccountName <T>(base.RawIdentity, rootId, (IRecipientSession)session, optionalData));
            }
            if (enumerableWrapper.HasUnfilteredElements() && !enumerableWrapper.HasElements())
            {
                notFoundReason = new LocalizedString?(this.GetErrorMessageForWrongType(this.ToString()));
            }
            TaskLogger.LogExit();
            return(enumerableWrapper);
        }
        internal override IEnumerable <T> GetObjectsInOrganization <T>(string identityString, ADObjectId rootId, IDirectorySession session, OptionalIdentityData optionalData)
        {
            if (Globals.IsConsumerOrganization(session.SessionSettings.CurrentOrganizationId) && ADSessionFactory.UseAggregateSession(session.SessionSettings))
            {
                LocalizedString?localizedString;
                return(ConsumerMailboxIdParameter.Parse(base.RawIdentity).GetObjects <T>(rootId, session, session, optionalData, out localizedString));
            }
            List <QueryFilter> list = new List <QueryFilter>();
            QueryFilter        item = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.ExternalDirectoryObjectId, identityString);

            list.Add(item);
            SmtpAddress smtpAddress = new SmtpAddress(identityString);

            if (smtpAddress.IsValidAddress)
            {
                QueryFilter item2 = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.EmailAddresses, "SMTP:" + smtpAddress.ToString());
                list.Add(item2);
                QueryFilter item3 = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.ExternalEmailAddress, "SMTP:" + smtpAddress.ToString());
                list.Add(item3);
                QueryFilter item4 = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.WindowsLiveID, smtpAddress.ToString());
                list.Add(item4);
            }
            QueryFilter item5 = base.CreateWildcardOrEqualFilter(ADUserSchema.UserPrincipalName, identityString);

            list.Add(item5);
            QueryFilter item6 = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.LegacyExchangeDN, identityString);

            list.Add(item6);
            QueryFilter item7 = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.EmailAddresses, "X500:" + identityString);

            list.Add(item7);
            QueryFilter queryFilter = base.CreateWildcardOrEqualFilter(ADRecipientSchema.Alias, identityString);

            if (queryFilter != null)
            {
                list.Add(queryFilter);
            }
            if (this.SearchWithDisplayName)
            {
                QueryFilter queryFilter2 = base.CreateWildcardOrEqualFilter(ADRecipientSchema.DisplayName, identityString);
                if (queryFilter2 != null)
                {
                    list.Add(queryFilter2);
                }
            }
            NetID propertyValue;

            if (NetID.TryParse(identityString, out propertyValue))
            {
                QueryFilter item8 = new ComparisonFilter(ComparisonOperator.Equal, ADUserSchema.NetID, propertyValue);
                list.Add(item8);
            }
            Guid guid = Guid.Empty;

            if (base.InternalADObjectId != null)
            {
                guid = base.InternalADObjectId.ObjectGuid;
            }
            if (Guid.Empty != guid || GuidHelper.TryParseGuid(identityString, out guid))
            {
                list.Add(new ComparisonFilter(ComparisonOperator.Equal, ADMailboxRecipientSchema.ExchangeGuid, guid));
                list.Add(new ComparisonFilter(ComparisonOperator.Equal, ADUserSchema.ArchiveGuid, guid));
                list.Add(new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ExchangeObjectId, guid));
                list.Add(new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.MailboxGuidsRaw, guid.ToString()));
                this.rawMailboxGuidInvolvedInSearch = guid;
            }
            QueryFilter queryFilter3        = QueryFilter.OrTogether(list.ToArray());
            QueryFilter recipientTypeFilter = RecipientIdParameter.GetRecipientTypeFilter(this.RecipientTypes);

            queryFilter3 = QueryFilter.AndTogether(new QueryFilter[]
            {
                queryFilter3,
                recipientTypeFilter
            });
            EnumerableWrapper <T> enumerableWrapper = EnumerableWrapper <T> .GetWrapper(base.PerformPrimarySearch <T>(queryFilter3, rootId, session, true, optionalData));

            if (!enumerableWrapper.HasElements())
            {
                this.rawMailboxGuidInvolvedInSearch = Guid.Empty;
                OptionalIdentityData optionalIdentityData;
                if (optionalData == null)
                {
                    optionalIdentityData = new OptionalIdentityData();
                    optionalIdentityData.AdditionalFilter = recipientTypeFilter;
                }
                else
                {
                    optionalIdentityData = optionalData.Clone();
                    optionalIdentityData.AdditionalFilter = QueryFilter.AndTogether(new QueryFilter[]
                    {
                        optionalIdentityData.AdditionalFilter,
                        recipientTypeFilter
                    });
                }
                enumerableWrapper = base.GetEnumerableWrapper <T>(enumerableWrapper, base.GetObjectsInOrganization <T>(identityString, rootId, session, optionalIdentityData));
            }
            return(enumerableWrapper);
        }