private static void BuildResultNumbers(StringBuilder sbLogMailBody, MailboxDiscoverySearch searchObject, KeywordHit unsearchableHit) { if (searchObject.IsFeatureFlighted("SearchStatsFlighted")) { Util.BuildResultNumbersEx(sbLogMailBody, searchObject); return; } Util.ReplaceLogFieldTags(sbLogMailBody, Globals.LogFields.ResultNumberEstimate, searchObject.ResultItemCountEstimate); if (searchObject.ExcludeDuplicateMessages) { Util.ReplaceLogFieldTags(sbLogMailBody, Globals.LogFields.EstimateNotExcludeDuplicates, Strings.LogFieldsEstimateNotExcludeDuplicates); } else { Util.ReplaceLogFieldTags(sbLogMailBody, Globals.LogFields.EstimateNotExcludeDuplicates, string.Empty); } string value = searchObject.ResultItemCountCopied.ToString(); if (unsearchableHit != null) { value = string.Format(Strings.MailboxSeachCountIncludeUnsearchable, searchObject.ResultItemCountCopied, unsearchableHit.Count); } Util.ReplaceLogFieldTags(sbLogMailBody, Globals.LogFields.ResultNumber, value); }
private static string CreateMailBody(string templateName, MailboxDiscoverySearch searchObject, string[] statusMailRecipients, List <string> successfulMailboxes, List <string> unsuccessfulMailboxes, IList <ISource> srcMailboxes) { Util.ThrowIfNullOrEmpty(templateName, "templateName"); Util.ThrowIfNull(searchObject, "searchObject"); StringBuilder stringBuilder = new StringBuilder(); using (StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(templateName))) { stringBuilder.Append(streamReader.ReadToEnd()); } Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.Identity, searchObject.Identity.ToString()); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.LastStartTime, searchObject.LastStartTime); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.LastEndTime, searchObject.LastEndTime); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.CreatedBy, searchObject.CreatedBy); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.Name, searchObject.Name); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SearchQuery, searchObject.Query); string text = searchObject.Senders.AggregateOfDefault((string s, string x) => s + ", " + x); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.Senders, text.ValueOrDefault(Strings.LogMailAll)); text = searchObject.Recipients.AggregateOfDefault((string s, string x) => s + ", " + x); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.Recipients, text.ValueOrDefault(Strings.LogMailAll)); text = ((searchObject.StartDate != null) ? string.Format("{0}, {0:%z}", searchObject.StartDate.Value) : Strings.LogMailBlank); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.StartDate, text); text = ((searchObject.EndDate != null) ? string.Format("{0}, {0:%z}", searchObject.EndDate.Value) : Strings.LogMailBlank); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.EndDate, text); text = (from x in searchObject.MessageTypes select x.ToString()).AggregateOfDefault((string s, string x) => s + ", " + x); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.MessageTypes, text.ValueOrDefault(Strings.LogMailAll)); if (searchObject.StatisticsOnly) { Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.TargetMailbox, Strings.LogMailNone); } else { Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.TargetMailbox, searchObject.Target); } Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.LogLevel, searchObject.LogLevel); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ExcludeDuplicateMessages, searchObject.ExcludeDuplicateMessages); StringBuilder sb = stringBuilder; Globals.LogFields logField = Globals.LogFields.SourceRecipients; object value; if (srcMailboxes != null) { value = string.Join(", ", (from src in srcMailboxes select src.Id).ToArray <string>()); } else { value = null; } Util.ReplaceLogFieldTags(sb, logField, value); text = statusMailRecipients.AggregateOfDefault((string s, string x) => s + ", " + x); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.StatusMailRecipients, text.ValueOrDefault(Strings.LogMailNone)); text = (from x in searchObject.ManagedBy select x.ToString()).AggregateOfDefault((string s, string x) => s + ", " + x); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ManagedBy, text.ValueOrDefault(Strings.LogMailNone)); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.LastRunBy, searchObject.LastModifiedBy); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.NumberMailboxesToSearch, searchObject.NumberOfMailboxes); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.NumberSuccessfulMailboxes, (successfulMailboxes == null) ? 0 : successfulMailboxes.Count); text = null; if (successfulMailboxes != null && successfulMailboxes.Count > 0) { text = (from x in successfulMailboxes select x).AggregateOfDefault((string s, string x) => s + ", " + x); } Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SuccessfulMailboxes, string.IsNullOrEmpty(text) ? Strings.LogMailNone : text); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.NumberUnsuccessfulMailboxes, (unsuccessfulMailboxes == null) ? 0 : unsuccessfulMailboxes.Count); text = null; if (unsuccessfulMailboxes != null && unsuccessfulMailboxes.Count > 0) { text = (from x in unsuccessfulMailboxes select x).AggregateOfDefault((string s, string x) => s + ", " + x); } Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.UnsuccessfulMailboxes, string.IsNullOrEmpty(text) ? Strings.LogMailNone : text); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.Resume, searchObject.Resume); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.IncludeKeywordStatistics, searchObject.IncludeKeywordStatistics); if (searchObject.Status == SearchState.Stopped || searchObject.Status == SearchState.EstimateStopped) { Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.StoppedBy, searchObject.LastModifiedBy); } else { Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.StoppedBy, Strings.LogMailNotApplicable); } Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.PercentComplete, string.Format("{0}%", searchObject.PercentComplete)); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ResultSize, new ByteQuantifiedSize((ulong)searchObject.ResultSizeCopied)); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ResultSizeEstimate, searchObject.ResultSizeEstimate); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ResultSizeCopied, new ByteQuantifiedSize((ulong)searchObject.ResultSizeCopied)); if (searchObject.StatisticsOnly) { Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ResultsLink, string.Empty); } else { Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ResultsLink, searchObject.ResultsLink); } int num = Math.Min(Util.MaxNumberOfErrorsInStatusMessage, searchObject.Errors.Count); StringBuilder stringBuilder2 = new StringBuilder(); for (int i = 0; i < num; i++) { stringBuilder2.Append(searchObject.Errors[i]); } text = stringBuilder2.ToString(); Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.Errors, text.ValueOrDefault(Strings.LogMailNone)); KeywordHit unsearchableHit = null; StringBuilder stringBuilder3 = new StringBuilder(); if (searchObject.KeywordHits != null && searchObject.KeywordHits.Count > 0) { stringBuilder3.AppendLine("<table style=\"width: 100%\" cellspacing=\"0\">"); stringBuilder3.AppendFormat("<tr> <td class=\"lefttd\"><strong>{0}</strong> </td><td class=\"lefttd\"><strong>{1}</strong> </td><td class=\"rightttd\"><strong>{2}</strong></td></tr>", Strings.LogFieldsKeywordKeyword, Strings.LogFieldsKeywordHitCount, Strings.LogFieldsKeywordMbxs); foreach (KeywordHit keywordHit in searchObject.KeywordHits) { if (keywordHit.Phrase != "652beee2-75f7-4ca0-8a02-0698a3919cb9") { stringBuilder3.AppendFormat("<tr><td class=\"lefttd\">{0} </td><td class=\"lefttd\">{1} </td><td class=\"rightttd\">{2}</td></tr>", keywordHit.Phrase, keywordHit.Count, keywordHit.MailboxCount); } else { unsearchableHit = keywordHit; } } stringBuilder3.Append("</table>"); } else if (!searchObject.StatisticsOnly) { stringBuilder3.Append(Strings.NoKeywordStatsForCopySearch); } else if (string.IsNullOrEmpty(searchObject.Query)) { stringBuilder3.Append(Strings.KeywordHitEmptyQuery); } else { stringBuilder3.Append(Strings.KeywordStatsNotRequested); } Util.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.KeywordHits, stringBuilder3.ToString()); Util.BuildResultNumbers(stringBuilder, searchObject, unsearchableHit); stringBuilder = stringBuilder.Replace(Globals.LogFields.LogMailHeader.ToLabelTag(), Strings.LogMailHeader(searchObject.Name, LocalizedDescriptionAttribute.FromEnum(typeof(SearchState), searchObject.Status))); if (!searchObject.StatisticsOnly) { stringBuilder = stringBuilder.Replace(Globals.LogFields.LogMailHeaderInstructions.ToLabelTag(), Strings.LogMailHeaderInstructions(searchObject.Name)); } else { stringBuilder.Replace(Globals.LogFields.LogMailHeaderInstructions.ToLabelTag(), string.Empty); } stringBuilder = stringBuilder.Replace(Globals.LogFields.LogMailSeeAttachment.ToLabelTag(), Strings.LogMailSeeAttachment); stringBuilder = stringBuilder.Replace(Globals.LogFields.LogMailFooter.ToLabelTag(), Strings.LogMailFooter); return(stringBuilder.ToString()); }
public void Start() { ExWatson.SendReportOnUnhandledException(delegate() { int mailboxesSearchedCount = 0; long itemCount = 0L; long totalSize = 0L; long unsearchableItemCount = 0L; long unsearchableTotalSize = 0L; List <ErrorRecord> unsearchableFailedMailboxes = null; List <ErrorRecord> failedMailboxes = null; List <KeywordHit> keywordHits = null; SearchState searchState = SearchState.NotStarted; Exception exception = null; try { GrayException.MapAndReportGrayExceptions(delegate() { try { if (this.searchObject != null) { this.searchObject.ScenarioId = ScenarioData.Current["SID"]; } if (this.isStatisticsOnlySearch) { if (string.IsNullOrEmpty(this.keywordStatisticsQuery)) { ScenarioData.Current["S"] = "ES"; if (this.searchObject != null && !string.IsNullOrEmpty(this.searchObject.CalculatedQuery)) { ScenarioData.Current["QL"] = this.searchObject.CalculatedQuery.Length.ToString(); } } else { ScenarioData.Current["S"] = "KS"; ScenarioData.Current["QL"] = this.keywordStatisticsQuery.Length.ToString(); } string text = (this.searchObject == null) ? string.Empty : this.searchObject.CalculatedQuery; List <string> list = null; if (this.ExportContext.Sources != null && this.ExportContext.Sources.Count > 0) { ScenarioData.Current["M"] = this.ExportContext.Sources.Count.ToString(); ISource source = this.ExportContext.Sources[0]; if (string.IsNullOrEmpty(text)) { text = source.SourceFilter; } list = new List <string>(this.ExportContext.Sources.Count); foreach (ISource source2 in this.ExportContext.Sources) { list.Add(source2.LegacyExchangeDN); } } if (list != null || this.isPFSearchFlightingEnabled) { bool flag = false; this.GetSearchResultEstimation(text, list, out mailboxesSearchedCount, false, ref flag, out itemCount, out totalSize, out failedMailboxes); } if (!string.IsNullOrEmpty(this.keywordStatisticsQuery) && !this.isTaskAborted) { List <ErrorRecord> list2 = null; List <KeywordStatisticsSearchResultType> keywordStatistics = this.ewsClient.GetKeywordStatistics(this.executingUserPrimarySmtpAddress, this.keywordStatisticsQuery, this.ExportContext.ExportMetadata.Language, (list != null) ? list : new List <string>(1), out list2, (this.searchObject == null || !this.isPFSearchFlightingEnabled) ? null : this.searchObject.Name); keywordHits = Util.ConvertToKeywordHitList(keywordStatistics, this.userKeywordsMap); if (list2 != null) { if (failedMailboxes == null) { failedMailboxes = list2; } else { failedMailboxes.AddRange(list2); } } } if (Util.IncludeUnsearchableItems(this.ExportContext) && !this.isTaskAborted && (list != null || (this.searchObject != null && this.searchObject.IsFeatureFlighted("PublicFolderSearchFlighted")))) { KeywordHit keywordHit = null; if (keywordHits != null) { keywordHit = new KeywordHit { Phrase = "652beee2-75f7-4ca0-8a02-0698a3919cb9" }; keywordHits.Add(keywordHit); } bool flag2 = false; if (this.searchObject != null && this.searchObject.IsFeatureFlighted("PublicFolderSearchFlighted")) { this.GetSearchResultEstimation(text, list, out mailboxesSearchedCount, true, ref flag2, out unsearchableItemCount, out unsearchableTotalSize, out unsearchableFailedMailboxes); if (flag2 && keywordHit != null) { keywordHit.Count += (int)unsearchableItemCount; } } else { foreach (string mailboxId in list) { if (this.isTaskAborted) { break; } long unsearchableItemStatistics = this.ewsClient.GetUnsearchableItemStatistics(this.executingUserPrimarySmtpAddress, mailboxId); unsearchableItemCount += unsearchableItemStatistics; if (keywordHit != null) { keywordHit.Count += (int)unsearchableItemStatistics; keywordHit.MailboxCount += ((unsearchableItemStatistics == 0L) ? 0 : 1); } } } } searchState = (this.isTaskAborted ? SearchState.EstimateStopped : SearchState.EstimateSucceeded); } else { ScenarioData.Current["S"] = "CS"; this.exportHandler.Prepare(); this.exportHandler.Export(); this.PrepareCompleted(this.exportHandler.SearchResults); searchState = (this.isTaskAborted ? SearchState.Stopped : SearchState.Succeeded); } } catch (ExportException exception) { ExportException exception = exception; } catch (StorageTransientException exception2) { ExportException exception = exception2; } catch (StoragePermanentException exception3) { ExportException exception = exception3; } catch (DataSourceOperationException exception4) { ExportException exception = exception4; } }); } catch (GrayException ex) { exception = ex; ExTraceGlobals.SearchTracer.TraceError <GrayException>((long)this.GetHashCode(), "GrayException {0} is thrown", ex); } finally { if (exception != null) { string message = exception.Message; if (string.IsNullOrEmpty(message) && exception.InnerException != null) { message = exception.InnerException.Message; } SearchEventLogger.Instance.LogDiscoverySearchTaskErrorEvent(this.ExportContext.ExportMetadata.ExportName, this.DiscoverySearchTaskErrorHint, exception); this.Errors.Add(message); mailboxesSearchedCount = 0; itemCount = 0L; totalSize = 0L; unsearchableItemCount = 0L; keywordHits = null; searchState = (this.isStatisticsOnlySearch ? SearchState.EstimateFailed : SearchState.Failed); } if (failedMailboxes != null && failedMailboxes.Count > 0) { foreach (ErrorRecord errorRecord in failedMailboxes) { this.Errors.Add(Util.GenerateErrorMessageFromErrorRecord(errorRecord)); } this.Errors.Insert(0, "Number of failed mailboxes: " + failedMailboxes.Count); } try { if (this.isStatisticsOnlySearch) { this.EstimateCompleted(mailboxesSearchedCount, itemCount, totalSize, unsearchableItemCount, keywordHits, searchState); } else { this.ExportCompleted(searchState); } } catch (ExportException ex2) { SearchEventLogger.Instance.LogDiscoverySearchTaskErrorEvent(this.ExportContext.ExportMetadata.ExportName, this.DiscoverySearchTaskErrorHint, ex2); this.Errors.Add(ex2.Message); searchState = (this.isStatisticsOnlySearch ? SearchState.EstimateFailed : SearchState.Failed); } } }, delegate(object exception) { ExTraceGlobals.SearchTracer.TraceError((long)this.GetHashCode(), "InternalStart: Unhandled exception {0}", new object[] { exception }); SearchEventLogger.Instance.LogDiscoverySearchTaskErrorEvent(this.ExportContext.ExportMetadata.ExportName, this.DiscoverySearchTaskErrorHint, exception.ToString()); return(!(exception is GrayException)); }); }
// Token: 0x06000E89 RID: 3721 RVA: 0x00045E24 File Offset: 0x00044024 private static MultiValuedProperty <KeywordHit> ConvertStringArrayToMvpKeywordHit(object keywordHits) { MultiValuedProperty <KeywordHit> result = new MultiValuedProperty <KeywordHit>(); if (keywordHits is string) { keywordHits = new string[] { (string)keywordHits }; } if (keywordHits is string[]) { try { result = new MultiValuedProperty <KeywordHit>(Array.ConvertAll <string, KeywordHit>((string[])keywordHits, (string keywordHit) => KeywordHit.Parse(keywordHit))); } catch (ArgumentNullException) { ExTraceGlobals.StorageTracer.TraceDebug(0L, "KeywordHit.Parse() throws ArgumentNullException"); } catch (FormatException) { ExTraceGlobals.StorageTracer.TraceDebug(0L, "KeywordHit.Parse() throws FormatException"); } catch (OverflowException) { ExTraceGlobals.StorageTracer.TraceDebug(0L, "KeywordHit.Parse() throws OverflowException"); } } return(result); }
public KeywordHitRow(KeywordHit kwh) { this.KeywordHit = kwh; }