public void TestDisplayMultiMessage() { AddStep("Display multi message", () => { messageContainer.AddSuccessParagraph("Success message"); messageContainer.AddWarningParagraph("Warning message"); messageContainer.AddAlertParagraph("Alert message"); messageContainer.AddHighlightText("I'm highlighting."); }); }
public override bool SetContent(object content) { if (!(content is LyricCheckReport report)) { return(false); } // clear exist warning. invalidMessage.Clear(); // Print time invalid message foreach (var invalid in report.TimeInvalid.EmptyIfNull()) { createTimeInvalidMessage(invalid); } // Print time-tag invalid message foreach (var invalidTimeTags in report.InvalidTimeTags.EmptyIfNull()) { createTimeTagInvalidMessage(invalidTimeTags.Key, invalidTimeTags.Value); } // Print ruby invalid message foreach (var invalidRubyTags in report.InvalidRubyTags.EmptyIfNull()) { createRubyInvalidMessage(invalidRubyTags.Key, invalidRubyTags.Value); } // Print romaji invalid message foreach (var invalidRomajiTags in report.InvalidRomajiTags.EmptyIfNull()) { createRomajiInvalidMessage(invalidRomajiTags.Key, invalidRomajiTags.Value); } // show no problem message if (report.IsValid) { invalidMessage.AddSuccessParagraph("Seems no issue in this lyric."); } return(true); void createTimeInvalidMessage(TimeInvalid timeInvalid) { switch (timeInvalid) { case TimeInvalid.Overlapping: invalidMessage.AddAlertParagraph("Start time larger then end time in lyric."); break; case TimeInvalid.StartTimeInvalid: invalidMessage.AddAlertParagraph("Start time is larger than minimux time tag's time."); break; case TimeInvalid.EndTimeInvalid: invalidMessage.AddAlertParagraph("End time is smaller than maximum time tag's time."); break; } } void createTimeTagInvalidMessage(TimeTagInvalid invalid, TimeTag[] timeTags) { switch (invalid) { case TimeTagInvalid.OutOfRange: invalidMessage.AddAlertParagraph("Time tag(s) is out of lyric text size at position "); break; case TimeTagInvalid.Overlapping: invalidMessage.AddAlertParagraph("Time tag(s) is invalid at position "); break; default: throw new ArgumentOutOfRangeException(nameof(invalid)); } displayInvalidTag(timeTags, tag => invalidMessage.AddHighlightText(TextIndexUtils.PositionFormattedString(tag.Index))); } void createRubyInvalidMessage(RubyTagInvalid invalid, RubyTag[] rubyTags) { switch (invalid) { case RubyTagInvalid.OutOfRange: invalidMessage.AddAlertParagraph("Ruby tag(s) is out of lyric text size at position "); break; case RubyTagInvalid.Overlapping: invalidMessage.AddAlertParagraph("Ruby tag(s) is overlapping to others at position "); break; default: throw new ArgumentOutOfRangeException(nameof(invalid)); } displayInvalidTag(rubyTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag))); } void createRomajiInvalidMessage(RomajiTagInvalid invalid, RomajiTag[] romajiTags) { switch (invalid) { case RomajiTagInvalid.OutOfRange: invalidMessage.AddAlertParagraph("Romaji tag(s) is out of lyric text size at position "); break; case RomajiTagInvalid.Overlapping: invalidMessage.AddAlertParagraph("Romaji tag(s) is overlapping to others at position "); break; default: throw new ArgumentOutOfRangeException(nameof(invalid)); } displayInvalidTag(romajiTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag))); } void displayInvalidTag <T>(T[] tags, Action <T> action) { if (tags == null) { throw new ArgumentNullException(nameof(tags)); } // e.g: ka(-2~-1), ra(4~6), and ke(6~7) for (int i = 0; i < tags.Length; i++) { action?.Invoke(tags[i]); if (i == tags.Length - 2 && tags.Length > 1) { invalidMessage.AddText(" and "); } else if (i >= 0 && tags.Length > 1) { invalidMessage.AddText(", "); } else { invalidMessage.AddText("."); } } } }
public override bool SetContent(object content) { if (!(content is Issue[] issues)) { return(false); } // clear exist warning. invalidMessage.Clear(); foreach (var issue in issues) { switch (issue) { // Print time invalid message case LyricTimeIssue lyricTimeIssue: lyricTimeIssue.InvalidLyricTime?.ForEach(createTimeInvalidMessage); break; // Print time-tag invalid message case TimeTagIssue timeTagIssue: if (timeTagIssue.MissingStartTimeTag) { invalidMessage.AddAlertParagraph("Missing start time tag at the start of lyric."); } if (timeTagIssue.MissingEndTimeTag) { invalidMessage.AddAlertParagraph("Missing end time tag at the end of lyric."); } timeTagIssue.InvalidTimeTags?.ForEach(x => createTimeTagInvalidMessage(x.Key, x.Value)); break; // Print ruby invalid message case RubyTagIssue rubyTagIssue: rubyTagIssue.InvalidRubyTags?.ForEach(x => createRubyInvalidMessage(x.Key, x.Value)); break; // Print romaji invalid message case RomajiTagIssue romajiTagIssue: romajiTagIssue.InvalidRomajiTags?.ForEach(x => createRomajiInvalidMessage(x.Key, x.Value)); break; // print normal message case Issue _: invalidMessage.AddAlertParagraph(issue.Template.GetMessage()); break; // Should throw exception because every issue message should be printed. default: throw new ArgumentOutOfRangeException(nameof(issue)); } } // show no problem message if (issues.Length == 0) { invalidMessage.AddSuccessParagraph("Seems no issue in this lyric."); } return(true); void createTimeInvalidMessage(TimeInvalid timeInvalid) { switch (timeInvalid) { case TimeInvalid.Overlapping: invalidMessage.AddAlertParagraph("Start time larger then end time in lyric."); break; case TimeInvalid.StartTimeInvalid: invalidMessage.AddAlertParagraph("Start time is larger than minimum time tag's time."); break; case TimeInvalid.EndTimeInvalid: invalidMessage.AddAlertParagraph("End time is smaller than maximum time tag's time."); break; } } void createTimeTagInvalidMessage(TimeTagInvalid invalid, TimeTag[] timeTags) { switch (invalid) { case TimeTagInvalid.OutOfRange: invalidMessage.AddAlertParagraph("Time tag(s) is out of lyric text size at position "); break; case TimeTagInvalid.Overlapping: invalidMessage.AddAlertParagraph("Time tag(s) is invalid at position "); break; case TimeTagInvalid.EmptyTime: invalidMessage.AddAlertParagraph("Time tag(s) is missing time at position "); break; default: throw new ArgumentOutOfRangeException(nameof(invalid)); } displayInvalidTag(timeTags, tag => invalidMessage.AddHighlightText(TextIndexUtils.PositionFormattedString(tag.Index))); } void createRubyInvalidMessage(RubyTagInvalid invalid, RubyTag[] rubyTags) { switch (invalid) { case RubyTagInvalid.OutOfRange: invalidMessage.AddAlertParagraph("Ruby tag(s) is out of lyric text size at position "); break; case RubyTagInvalid.Overlapping: invalidMessage.AddAlertParagraph("Ruby tag(s) is overlapping to others at position "); break; default: throw new ArgumentOutOfRangeException(nameof(invalid)); } displayInvalidTag(rubyTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag))); } void createRomajiInvalidMessage(RomajiTagInvalid invalid, RomajiTag[] romajiTags) { switch (invalid) { case RomajiTagInvalid.OutOfRange: invalidMessage.AddAlertParagraph("Romaji tag(s) is out of lyric text size at position "); break; case RomajiTagInvalid.Overlapping: invalidMessage.AddAlertParagraph("Romaji tag(s) is overlapping to others at position "); break; default: throw new ArgumentOutOfRangeException(nameof(invalid)); } displayInvalidTag(romajiTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag))); } void displayInvalidTag <T>(T[] tags, Action <T> action) { if (tags == null) { throw new ArgumentNullException(nameof(tags)); } // e.g: ka(-2~-1), ra(4~6), and ke(6~7) for (int i = 0; i < tags.Length; i++) { action?.Invoke(tags[i]); if (i == tags.Length - 2 && tags.Length > 1) { invalidMessage.AddText(" and "); } else if (i >= 0 && tags.Length > 1) { invalidMessage.AddText(", "); } else { invalidMessage.AddText("."); } } } }