Exemplo n.º 1
0
        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);
                        }
                    }
                }
            }
        }