Пример #1
0
 private static void ReplaceLogFieldTags(StringBuilder sb, Globals.LogFields logField, object value)
 {
     sb = sb.Replace(logField.ToLabelTag(), LocalizedDescriptionAttribute.FromEnum(typeof(Globals.LogFields), logField) + ":");
     sb = sb.Replace(logField.ToValueTag(), string.Format("{0}", value));
 }
Пример #2
0
 public static string ToValueTag(this Globals.LogFields logField)
 {
     return("{" + logField.ToString() + "}");
 }
Пример #3
0
        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>&nbsp;</td><td class=\"lefttd\"><strong>{1}</strong>&nbsp;</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}&nbsp;</td><td class=\"lefttd\">{1}&nbsp;</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());
        }
Пример #4
0
 public static string ToLabelTag(this Globals.LogFields logField)
 {
     return("{Label" + logField.ToString() + "}");
 }