private void EnqueueMatches(SearchRecipient recipient, Dictionary <SearchSource, bool> matchMap, List <SearchSource> publicFolders) { bool flag = false; Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryLookup.EnqueueMatches Recipient:", recipient); if (recipient.Parent == null) { foreach (SearchSource searchSource in this.Match(recipient.ADEntry, matchMap, false)) { flag = true; searchSource.Recipient = recipient; this.EnqueueSource(searchSource, publicFolders); } } if (!flag) { Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryLookup.EnqueueMatches Match to Parent Recipient:", recipient); foreach (SearchSource originalSource in this.Match(recipient.Parent, matchMap, true)) { flag = true; SearchSource source = this.CreateDefaultSource(originalSource, recipient); this.EnqueueSource(source, publicFolders); if (flag) { break; } } } if (!flag) { Recorder.Trace(4L, TraceType.WarningTrace, "DirectoryLookup.EnqueueMatches Orphaned AD Entry Entry:", recipient); } }
private SearchSource CreateDefaultSource(SearchSource originalSource, SearchRecipient recipient) { SearchSource searchSource = (originalSource != null) ? originalSource.Clone() : new SearchSource(); searchSource.ReferenceId = (string)recipient.ADEntry[ADRecipientSchema.LegacyExchangeDN]; searchSource.SourceType = SourceType.LegacyExchangeDN; searchSource.Recipient = recipient; return(searchSource); }
private void EnqueueSource(SearchSource source, List <SearchSource> publicFolders) { if (source != null) { Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryLookup.EnqueueSource Source:", source); if (SearchRecipient.IsPublicFolder(source.Recipient.ADEntry)) { Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryLookup.EnqueueSource PublicFolder:", source); if (publicFolders != null) { publicFolders.Add(source); } return; } base.Executor.EnqueueNext(source); } }
public override void Process(DirectoryQueryParameters item) { Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "DirectoryLookup.Process Query:", item.Query, "ExpandPublicFolders:", item.ExpandPublicFolders, "ExpandGroups:", item.ExpandGroups, "MatchRecipientsToSources:", item.MatchRecipientsToSources }); List <SearchSource> list = null; if (item.ExpandPublicFolders) { Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryLookup.Process ExpandPublicFolders"); list = new List <SearchSource>(); } Dictionary <SearchSource, bool> matchMap = null; if (item.MatchRecipientsToSources) { Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryLookup.Process MatchRecipients"); matchMap = new Dictionary <SearchSource, bool>(); item.Sources.ForEach(delegate(SearchSource t) { matchMap[t] = false; }); } IDirectoryProvider directoryProvider = SearchFactory.Current.GetDirectoryProvider(base.Executor.Policy); foreach (SearchRecipient recipient in directoryProvider.Query(base.Executor.Policy, item)) { if (item.MatchRecipientsToSources) { this.EnqueueMatches(recipient, matchMap, list); } else { SearchSource source = this.CreateDefaultSource(null, recipient); this.EnqueueSource(source, list); } } if (item.MatchRecipientsToSources) { foreach (SearchSource searchSource in from t in matchMap where !t.Value select t.Key) { Recorder.Trace(4L, TraceType.WarningTrace, new object[] { "DirectoryLookup.Process FailedSource:", searchSource.ReferenceId, "FailedSourceType:", searchSource.SourceType }); base.Executor.Fail(new SearchException(KnownError.ErrorSearchableObjectNotFound) { ErrorSource = searchSource }); } } if (item.ExpandPublicFolders && list.Count > 0) { Recorder.Trace(4L, TraceType.WarningTrace, "DirectoryLookup.Process ExapndPublicFolders Count:", list.Count); ISourceConverter sourceConverter = SearchFactory.Current.GetSourceConverter(base.Policy, SourceType.PublicFolder); foreach (SearchSource searchSource2 in sourceConverter.Convert(base.Policy, this.GetPublicFolderSources(list))) { QueryFilter sourceFilter = SearchRecipient.GetSourceFilter(searchSource2); item.Query = sourceFilter; item.PageSize = 1; using (IEnumerator <SearchRecipient> enumerator4 = directoryProvider.Query(base.Policy, item).GetEnumerator()) { if (enumerator4.MoveNext()) { SearchRecipient searchRecipient = enumerator4.Current; searchSource2.Recipient.ADEntry = searchRecipient.ADEntry; this.EnqueueSource(searchSource2, null); } } } } }
public IEnumerable <SearchRecipient> Query(ISearchPolicy policy, DirectoryQueryParameters request) { Recorder.Trace(5L, TraceType.InfoTrace, new object[] { "ActiveDirectoryProvider.Query Query:", request.Query, "PageSize:", request.PageSize, "Properties:", request.Properties, "ExpandGroups:", request.ExpandGroups }); ADPagedReader <ADRawEntry> pagedReader = policy.RecipientSession.FindPagedADRawEntry(null, QueryScope.SubTree, request.Query, null, request.PageSize, request.Properties); new List <SearchRecipient>(); foreach (ADRawEntry entry in pagedReader) { if (request.ExpandGroups && SearchRecipient.IsMembershipGroup(entry)) { Recorder.Trace(5L, TraceType.InfoTrace, "ActiveDirectoryProvider.Query Expanding:", entry); List <ADRawEntry> groupEntries = new List <ADRawEntry>(); ADRecipientExpansion expansion = new ADRecipientExpansion(policy.RecipientSession, false, request.Properties); ADRecipientExpansion.HandleRecipientDelegate handleDelegate = delegate(ADRawEntry recipient, ExpansionType recipientExpansionType, ADRawEntry parent, ExpansionType parentExpansionType) { if (recipientExpansionType == ExpansionType.GroupMembership) { return(ExpansionControl.Continue); } groupEntries.Add(recipient); return(ExpansionControl.Skip); }; ADRecipientExpansion.HandleFailureDelegate failureDelegate = delegate(ExpansionFailure expansionFailure, ADRawEntry recipient, ExpansionType recipientExpansionType, ADRawEntry parent, ExpansionType parentExpansionType) { Recorder.Trace(5L, TraceType.ErrorTrace, new object[] { "ActiveDirectoryProvider.Query Expansion Failed:", recipient, "Error:", expansionFailure, "ExpansionType:", recipientExpansionType, "Parent:", parent, "ParentyExpansionType:", parentExpansionType }); return(ExpansionControl.Skip); }; expansion.Expand(entry, handleDelegate, failureDelegate); foreach (ADRawEntry groupEntry in groupEntries) { yield return(new SearchRecipient(groupEntry, entry)); } } else { yield return(new SearchRecipient(entry, null)); } } yield break; }
private void Enqueue(DirectoryQueryParameters parameters, IEnumerable <SearchSource> sources, IEnumerable <QueryFilter> filters) { this.Enqueue(parameters, sources, SearchRecipient.CombineFilters(filters)); }
public async Task <ActionResult> Get([FromQuery] SearchRecipient searchRecipient) { var list = await _recipientService.GetRecipients(searchRecipient); return(Ok(list)); }
private void ProcessPublicFolders(DirectoryQueryParameters item, SearchSource allPublicFolders, List <SearchSource> publicFolders) { Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "DirectoryQueryFormatting.ProcessPublicFolders AllPublicFolders:", allPublicFolders, "MailboxFilterPairs:", publicFolders }); List <QueryFilter> list = new List <QueryFilter>(); List <string> list2 = new List <string>(); ISourceConverter sourceConverter = SearchFactory.Current.GetSourceConverter(base.Policy, SourceType.PublicFolder); if (allPublicFolders != null || publicFolders.Count > 0) { List <SearchSource> list3 = new List <SearchSource>(); IEnumerable <SearchSource> enumerable = (allPublicFolders == null) ? publicFolders : ((IEnumerable <SearchSource>) new SearchSource[] { allPublicFolders }); Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryQueryFormatting.ProcessPublicFolders PublicFolderList:", enumerable); foreach (SearchSource searchSource in sourceConverter.Convert(base.Policy, enumerable)) { Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "DirectoryQueryFormatting.ProcessPublicFolders Source:", searchSource.ReferenceId, "SourceType:", searchSource.SourceType }); if (searchSource.SourceType != SourceType.PublicFolder) { QueryFilter sourceFilter = SearchRecipient.GetSourceFilter(searchSource); if (sourceFilter != null) { Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "DirectoryQueryFormatting.ProcessPublicFolders Source:", searchSource.ReferenceId, "SourceType:", searchSource.SourceType, "Filter:", sourceFilter }); list3.Add(searchSource); if (list2.Contains(searchSource.ReferenceId)) { continue; } list.Add(sourceFilter); list2.Add(searchSource.ReferenceId); if (list.Count >= item.PageSize) { this.Enqueue(item, list3, list); list3.Clear(); list2.Clear(); list.Clear(); continue; } continue; } } Recorder.Trace(4L, TraceType.ErrorTrace, "DirectoryQueryFormatting.ProcessPublicFolders FailedSource:", searchSource.ReferenceId); base.Executor.Fail(new SearchException(KnownError.ErrorSearchableObjectNotFound) { ErrorSource = searchSource }); } this.Enqueue(item, list3, list); } }
public override void Process(DirectoryQueryParameters item) { Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryQueryFormatting.Process Item:", item); SearchSource searchSource = null; SearchSource searchSource2 = null; List <SearchSource> list = new List <SearchSource>(); List <DirectoryQueryFormatting.SourceFilterPair> list2 = new List <DirectoryQueryFormatting.SourceFilterPair>(); foreach (SearchSource searchSource3 in item.Sources) { bool flag = true; if (searchSource3.SourceType == SourceType.AutoDetect) { searchSource3.SourceType = SearchSource.GetSourceType(searchSource3); } Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "DirectoryQueryFormatting.Process Source:", searchSource3.ReferenceId, "Type:", searchSource3.SourceType }); switch (searchSource3.SourceType) { case SourceType.LegacyExchangeDN: case SourceType.Recipient: case SourceType.MailboxGuid: if (searchSource == null) { if (!string.IsNullOrEmpty(searchSource3.ReferenceId)) { QueryFilter sourceFilter = SearchRecipient.GetSourceFilter(searchSource3); if (sourceFilter != null) { list2.Add(new DirectoryQueryFormatting.SourceFilterPair { Source = searchSource3, Filter = sourceFilter }); flag = false; } } } else { flag = false; } break; case SourceType.PublicFolder: if (searchSource2 == null) { if (!string.IsNullOrEmpty(searchSource3.ReferenceId)) { list.Add(searchSource3); flag = false; } } else { flag = false; } break; case SourceType.AllPublicFolders: searchSource2 = searchSource3; flag = false; break; case SourceType.AllMailboxes: searchSource = searchSource3; flag = false; break; } if (flag) { Recorder.Trace(4L, TraceType.ErrorTrace, new object[] { "DirectoryQueryFormatting.Process FailedSource:", searchSource3.ReferenceId, "FailedType:", searchSource3.SourceType }); base.Executor.Fail(new SearchException(KnownError.ErrorSearchableObjectNotFound) { ErrorSource = searchSource3 }); } if (searchSource != null && searchSource2 != null) { break; } } this.ProcessMailboxes(item, searchSource, list2); this.ProcessPublicFolders(item, searchSource2, list); }
private void ProcessMailboxes(DirectoryQueryParameters item, SearchSource allMailboxes, List <DirectoryQueryFormatting.SourceFilterPair> mailboxFilterPairs) { Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "DirectoryQueryFormatting.ProcessMailboxes AllMailboxes:", allMailboxes, "MailboxFilterPairs:", mailboxFilterPairs }); if (allMailboxes == null) { if (mailboxFilterPairs.Count > 0) { Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryQueryFormatting.ProcessMailboxes Mailboxes Count:", mailboxFilterPairs.Count); int num; for (int i = 0; i < mailboxFilterPairs.Count; i += num) { num = Math.Min(mailboxFilterPairs.Count - i, item.PageSize); IEnumerable <DirectoryQueryFormatting.SourceFilterPair> source = mailboxFilterPairs.Skip(i).Take(num); this.Enqueue(item, from t in source select t.Source, source.Select((DirectoryQueryFormatting.SourceFilterPair t) => t.Filter)); } } return; } Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryQueryFormatting.ProcessMailboxes AllMailboxes"); if (string.IsNullOrWhiteSpace(allMailboxes.ReferenceId)) { this.Enqueue(item, new SearchSource[] { allMailboxes }, SearchRecipient.GetRecipientTypeFilter(item.RequestGroups)); return; } Recorder.Trace(4L, TraceType.InfoTrace, "DirectoryQueryFormatting.ProcessMailboxes AllMailboxes Filter:", allMailboxes.ReferenceId); if (SearchRecipient.IsWildcard(allMailboxes.ReferenceId) && item.ExpandGroups) { Recorder.Trace(4L, TraceType.ErrorTrace, new object[] { "DirectoryQueryFormatting.ProcessMailboxes Failed AllMailboxes Filter:", allMailboxes.ReferenceId, "ExpandGroups:", item.ExpandGroups, "Wildcard with Group Expansion not Allowed" }); throw new SearchException(KnownError.ErrorWildcardAndGroupExpansionNotAllowed); } if (SearchRecipient.IsSuffixSearchWildcard(allMailboxes.ReferenceId)) { Recorder.Trace(4L, TraceType.ErrorTrace, new object[] { "DirectoryQueryFormatting.ProcessMailboxes Failed AllMailboxes Filter:", allMailboxes.ReferenceId, "ExpandGroups:", item.ExpandGroups, "Wildcard with Suffix not Allowed" }); throw new SearchException(KnownError.ErrorSuffixSearchNotAllowed); } this.Enqueue(item, new SearchSource[] { allMailboxes }, SearchRecipient.GetRecipientTypeSearchFilter(allMailboxes.ReferenceId, item.RequestGroups)); }
public async Task <IEnumerable <RecipientDerivedModel> > GetRecipients(SearchRecipient searchRecipient) { return(await _recipientRepository.GetRecipients(searchRecipient)); }
public async Task <IEnumerable <RecipientDerivedModel> > GetRecipients(SearchRecipient searchRecipient) { return(await Query <RecipientDerivedModel>("Crm.GetRecipients", searchRecipient)); }