コード例 #1
0
        private ISearchResult SearchUpdatesUtil(CancellationToken cancellationToken)
        {
            try
            {
                IUpdateSearcher         uSearcher = this._uSession.CreateUpdateSearcher();
                SearchCompletedCallback searchCompletedCallback = new SearchCompletedCallback();

                string     searchQuery = this._serviceSettings.WUQuery;
                ISearchJob searchJob   = uSearcher.BeginSearch(searchQuery, searchCompletedCallback, null);

                TimeSpan operationTimeOut = TimeSpan.FromMinutes(this._serviceSettings.WUOperationTimeOutInMinutes);
                if (
                    !this._helper.WaitOnTask(searchCompletedCallback.Task, (int)operationTimeOut.TotalMilliseconds,
                                             cancellationToken))
                {
                    _eventSource.Message("searchJob : Requested Abort");
                    searchJob.RequestAbort();
                }

                ISearchResult uResult = uSearcher.EndSearch(searchJob);
                return(uResult);
            }
            catch (Exception e)
            {
                _eventSource.InfoMessage("Exception while searching for Windows-Updates: {0}", e);
                return(null);
            }
        }
コード例 #2
0
        public WuStateSearching(IUpdateSearcher searcher, SearchCompletedCallback completedCallback, TimeoutCallback timeoutCallback, int timeoutSec) : base(WuStateId.Searching, "Searching Updates", timeoutSec, timeoutCallback, null)
        {
            if (searcher == null)
            {
                throw new ArgumentNullException(nameof(searcher));
            }
            if (completedCallback == null)
            {
                throw new ArgumentNullException(nameof(completedCallback));
            }

            _completedCallback = completedCallback;
            _searcher          = searcher;
        }
コード例 #3
0
 public void Execute(SearchCompletedCallback searchCallback)
 {
     if (searchCallback == null)
     {
         throw new ArgumentNullException("searchCallback");
     }
     this.InvokeMethodAndHandleExceptions(delegate
     {
         this.attempts++;
         this.callback = searchCallback;
         AggregatedSearchTaskResult result = null;
         this.InitRpcSearchClient();
         Factory.Current.LocalTaskTracer.TraceInformation(this.GetHashCode(), 0L, "Correlation Id:{0}. Executing {1} search for the queryFilter:{2} on {3} mailboxes in database:{4}", new object[]
         {
             this.ExecutingUserIdentity.QueryCorrelationId,
             (this.RpcClient.Criteria.SearchType == SearchType.Preview) ? "preview" : "keyword stats",
             this.RpcClient.Criteria.QueryString,
             this.MailboxInfoList.Count,
             this.RpcClient.MailboxDatabaseGuid
         });
         if ((this.type & SearchType.Preview) == SearchType.Preview)
         {
             result = this.RpcClient.Search(Factory.Current.GetMaxRefinerResults(this.SearchCriteria.RecipientSession));
         }
         else if ((this.type & SearchType.Statistics) == SearchType.Statistics)
         {
             List <IKeywordHit> keywordHits = this.RpcClient.GetKeywordHits(this.keywordList);
             IKeywordHit keywordHit;
             if (keywordHits == null)
             {
                 keywordHit = null;
             }
             else
             {
                 keywordHit = keywordHits.Find((IKeywordHit x) => x.Phrase.Equals(this.SearchCriteria.QueryString, StringComparison.OrdinalIgnoreCase));
             }
             IKeywordHit keywordHit2 = keywordHit;
             result = new AggregatedSearchTaskResult(this.MailboxInfoList, keywordHits, (keywordHit2 != null) ? keywordHit2.Count : 0UL, (keywordHit2 != null) ? keywordHit2.Size : ByteQuantifiedSize.Zero);
         }
         this.UpdateSearchStatistics();
         this.callback(this, result);
     });
 }
コード例 #4
0
        public async Task <ISearchResult> SearchAsync(string criteria, CancellationToken cancellationToken)
        {
            var searcher = GetUpdateSearcher();

            var callback = new SearchCompletedCallback();
            var job      = searcher.BeginSearch(criteria, callback, null);

            if (await callback.WaitAsync() == false)
            {
                job.RequestAbort();
            }

            if (cancellationToken.IsCancellationRequested)
            {
                job.RequestAbort();
            }

            return(searcher.EndSearch(job));
        }
コード例 #5
0
        public static SearchSession BeginSearch(this PSCmdlet cmdlet, bool force, string criterea)
        {
            IUpdateService2 service = cmdlet.GetService(force);


            UpdateSession    updateSession = new UpdateSession();
            IUpdateSearcher2 searcher      = updateSession.CreateSearcher();

            searcher.ServerSelection = ServerSelection.ssOthers;
            searcher.ServiceID       = service.ServiceID;


            SearchCompletedCallback callback = new SearchCompletedCallback(searcher);

            object state = new object();

            searcher.BeginSearch(criterea, callback, state);


            return(new SearchSession(callback));
        }
コード例 #6
0
        public SearchMailboxesResults Search(ISearchPolicy policy, SearchMailboxesInputs input)
        {
            Guid databaseGuid = Guid.Empty;
            List <SearchSource>          list       = new List <SearchSource>(input.Sources);
            ResultAggregator             aggregator = new ResultAggregator();
            IEnumerable <List <string> > enumerable = null;

            Recorder.Record record = policy.Recorder.Start("SearchResultProvider", TraceType.InfoTrace, true);
            Recorder.Trace(5L, TraceType.InfoTrace, new object[]
            {
                "LocalSearchResultsProvider.Search Input:",
                input,
                "Type:",
                input.SearchType
            });
            try
            {
                if (input.SearchType == SearchType.Statistics)
                {
                    enumerable = this.GenerateKeywordStatsQueryBatches(policy, aggregator, input.Criteria);
                }
                SearchCompletedCallback searchCallback = delegate(ISearchMailboxTask task, ISearchTaskResult result)
                {
                    aggregator.MergeSearchResult(result);
                };
                record.Attributes["MBXCNT"] = list.Count;
                while (list.Count > 0)
                {
                    Recorder.Trace(5L, TraceType.InfoTrace, "LocalSearchResultsProvider.Search UnsearchedSources:", list.Count);
                    HashSet <Guid>  hashSet         = new HashSet <Guid>();
                    MailboxInfoList mailboxInfoList = new MailboxInfoList();
                    int             i = 0;
                    while (i < list.Count)
                    {
                        SearchSource searchSource = list[i];
                        Guid         item         = searchSource.MailboxInfo.IsArchive ? searchSource.MailboxInfo.ArchiveGuid : searchSource.MailboxInfo.MailboxGuid;
                        if (!hashSet.Contains(item))
                        {
                            mailboxInfoList.Add(searchSource.MailboxInfo);
                            list.RemoveAt(i);
                            hashSet.Add(item);
                            databaseGuid = (searchSource.MailboxInfo.IsArchive ? searchSource.MailboxInfo.ArchiveDatabase : searchSource.MailboxInfo.MdbGuid);
                        }
                        else
                        {
                            i++;
                        }
                    }
                    Recorder.Trace(5L, TraceType.InfoTrace, "LocalSearchResultsProvider.Search NonDuplicateSourcesToSearch:", mailboxInfoList.Count);
                    AggregatedMailboxSearchTask aggregatedMailboxSearchTask;
                    if (input.SearchType == SearchType.Statistics)
                    {
                        Recorder.Trace(5L, TraceType.InfoTrace, "LocalSearchResultsProvider.Search Statistics:", enumerable);
                        using (IEnumerator <List <string> > enumerator = enumerable.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                List <string> keywordList = enumerator.Current;
                                AggregatedMailboxSearchTask aggregatedMailboxSearchTask2;
                                aggregatedMailboxSearchTask = (aggregatedMailboxSearchTask2 = new AggregatedMailboxSearchTask(databaseGuid, mailboxInfoList, input.Criteria, input.PagingInfo, keywordList, input.CallerInfo));
                                try
                                {
                                    aggregatedMailboxSearchTask.Execute(searchCallback);
                                    this.UpdateSearchStatistics(policy, record, aggregatedMailboxSearchTask);
                                }
                                finally
                                {
                                    if (aggregatedMailboxSearchTask2 != null)
                                    {
                                        ((IDisposable)aggregatedMailboxSearchTask2).Dispose();
                                    }
                                }
                            }
                            continue;
                        }
                    }
                    Recorder.Trace(5L, TraceType.InfoTrace, "LocalSearchResultsProvider.Search Regular");
                    AggregatedMailboxSearchTask aggregatedMailboxSearchTask3;
                    aggregatedMailboxSearchTask = (aggregatedMailboxSearchTask3 = new AggregatedMailboxSearchTask(databaseGuid, mailboxInfoList, input.SearchType, input.Criteria, input.PagingInfo, input.CallerInfo));
                    try
                    {
                        aggregatedMailboxSearchTask.Execute(searchCallback);
                        this.UpdateSearchStatistics(policy, record, aggregatedMailboxSearchTask);
                    }
                    finally
                    {
                        if (aggregatedMailboxSearchTask3 != null)
                        {
                            ((IDisposable)aggregatedMailboxSearchTask3).Dispose();
                        }
                    }
                }
            }
            finally
            {
                policy.Recorder.End(record);
            }
            return(new SearchMailboxesResults(input.Sources)
            {
                SearchResult = aggregator
            });
        }
コード例 #7
0
 internal SearchSession(SearchCompletedCallback completedCallback)
 {
     _completedCallback = completedCallback;
 }