public IEnumerable <T> EndAuditLogQuery <T>(IAsyncResult asyncResult, IAuditQueryStrategy <T> queryStrategy) { SearchFolder searchFolder = this.folder as SearchFolder; if (searchFolder != null) { SearchFolderCriteria searchCriteria = searchFolder.GetSearchCriteria(); if ((searchCriteria.SearchState & SearchState.FailNonContentIndexedSearch) == SearchState.FailNonContentIndexedSearch && (searchCriteria.SearchState & SearchState.Failed) == SearchState.Failed) { throw queryStrategy.GetQueryFailedException(); } } AuditLog.AuditLogQueryContext.QueryRecordStrategy <T> strategy = new AuditLog.AuditLogQueryContext.QueryRecordStrategy <T>(queryStrategy); return(AuditLog.InternalFindAuditRecords <T>(this.folder, strategy)); }
public IEnumerable <T> EndAuditLogQuery <T>(IAsyncResult asyncResult, IAuditQueryStrategy <T> queryStrategy) { foreach (ItemType item in this.FindItemsPaged()) { EwsAuditLog.EwsItemPropertyBag itemAsPropertyBag = new EwsAuditLog.EwsItemPropertyBag(item); bool stopNow; bool match = queryStrategy.RecordFilter(itemAsPropertyBag, out stopNow); if (stopNow) { break; } if (match) { yield return(queryStrategy.Convert(itemAsPropertyBag)); } } yield break; }
public QueryRecordStrategy(IAuditQueryStrategy <T> queryStrategy) { this.queryStrategy = queryStrategy; }
public static IEnumerable <T> SearchAuditLogs <T, TFilter>(IAuditLogCollection logCollection, TFilter queryFilter, int maximumResultsCount, TimeSpan timeout, IAuditQueryStrategy <T> strategy, Trace tracer) { if (maximumResultsCount <= 0) { if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug <int>((long)logCollection.GetHashCode(), "SearchAuditLogs: Maximum number of records requested is {0}. No records returned.", maximumResultsCount); } } else { int totalCount = 0; foreach (IAuditLog auditLog in logCollection.GetAuditLogs()) { using (IAuditQueryContext <TFilter> queryContext = auditLog.CreateAuditQueryContext <TFilter>()) { if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug <DateTime, DateTime, string>((long)logCollection.GetHashCode(), "SearchAuditLogs: Begin async query. Log=[{0},{1}], query=[{2}]", auditLog.EstimatedLogStartTime, auditLog.EstimatedLogEndTime, (queryFilter != null) ? queryFilter.ToString() : string.Empty); } IAsyncResult asyncResult = queryContext.BeginAuditLogQuery(queryFilter, maximumResultsCount); bool queryCompleted = asyncResult.IsCompleted; if (!queryCompleted) { if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug <TimeSpan>((long)logCollection.GetHashCode(), "SearchAuditLogs: waiting for async query to complete. Timeout=[{0}]", timeout); } queryCompleted = asyncResult.AsyncWaitHandle.WaitOne(timeout, false); } else if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug((long)logCollection.GetHashCode(), "SearchAuditLogs: query completed synchronously"); } if (!queryCompleted) { if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug((long)logCollection.GetHashCode(), "SearchAuditLogs: query execution has timed out"); } Exception timeoutException = strategy.GetTimeoutException(timeout); if (timeoutException != null) { throw timeoutException; } } else { if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug((long)logCollection.GetHashCode(), "SearchAuditLogs: query execution complete"); } int count = 0; foreach (T result in queryContext.EndAuditLogQuery <T>(asyncResult, strategy)) { totalCount++; count++; yield return(result); if (totalCount >= maximumResultsCount) { if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug <int>((long)logCollection.GetHashCode(), "SearchAuditLogs: maximum total number of records reached. Total records returned={0}", totalCount); } yield break; } } if (AuditLogSearchQuery.IsTraceEnabled(tracer)) { tracer.TraceDebug <int>((long)logCollection.GetHashCode(), "SearchAuditLogs: query result set has {0} rows", count); } } } } } yield break; }