/// <summary> /// Transform collection of inlines /// </summary> public List<Inline> Decorate(IConferenceMessage msg, List<Inline> inlines) { const string pattern = @"((https?|ftp|dchub|magnet|mailto|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"; for (int i = 0; i < inlines.Count; i++) { // splite one Inline element (text (Run)) into several inlines (Runs and Hyperlinks) var inline = inlines[i] as Run; if (inline == null) continue; var matches = Regex.Matches(inline.Text, pattern).OfType<Match>().Select(item => item.Value).ToArray(); if (matches.Length < 1) continue; inlines.RemoveAt(i); var parts = inline.Text.SplitAndIncludeDelimiters(matches).ToArray(); for (int j = i; j < parts.Length + i; j++) { var part = parts[j]; if (matches.Contains(part)) inlines.Insert(j, DecorateAsHyperlink(part)); else inlines.Insert(j, CommonMessageDecorator.Decorate(msg, part)); } } return inlines; }
public void SendConferenceMessage(IConferenceMessage message) { using (var ctx = new DataContext()) { ctx.Conferences.Single(x=>x.Id == message.ConferenceId).Messages.Add(new ConferenceMessage(message)); ctx.SaveChanges(); } }
/// <summary> /// Transform collection of inlines /// </summary> public List<Inline> Decorate(IConferenceMessage msg, List<Inline> inlines) { string style = "timestampStyle"; var timestampInline = new Run(msg.Timestamp.ToString("[hh:mm:ss] ")); timestampInline.SetResourceReference(FrameworkContentElement.StyleProperty, style); inlines.Insert(0, timestampInline); return inlines; }
public static Inline Decorate(IConferenceMessage msg, string message) { string style = "commonMessageStyle"; if (msg is SystemConferenceMessage) style = "systemMessageStyle"; if (msg is SystemConferenceMessage && ((SystemConferenceMessage)msg).IsErrorMessage) style = "errorMessageStyle"; Run messageInline = new Run(message); messageInline.SetResourceReference(FrameworkContentElement.StyleProperty, style); return messageInline; }
public static Paragraph Present(IConferenceMessage message) { Paragraph paragraph = new Paragraph(); paragraph.SetResourceReference(Paragraph.StyleProperty, "parentRowStyle"); // at first, textInlines will contains only one inline - raw text List<Inline> textInlines = new List<Inline>(); // applying custom decorators DecoratorsRegistry.GetDecorators().ForEach(i => textInlines = i.Decorate(message, textInlines)); paragraph.Inlines.AddRange(textInlines); return paragraph; }
/// <summary> /// Transform collection of inlines /// </summary> public List<Inline> Decorate(IConferenceMessage msg, List<Inline> inlines) { string style = "nickStyle"; string nick = msg.Author; if (string.IsNullOrEmpty(msg.Author)) { style = "systemNickStyle"; nick = "System"; } Run nickInline = new Run(string.Format("{0}: ", nick)); nickInline.SetResourceReference(FrameworkContentElement.StyleProperty, style); inlines.Insert(0, nickInline); return inlines; }
public ConferenceMessage(IConferenceMessage source) : base(source) { ConferenceId = source.ConferenceId; }
/// <summary> /// Transform collection of inlines /// </summary> public List<Inline> Decorate(IConferenceMessage msg, List<Inline> inlines) { //TODO: return inlines; }
/// <summary> /// Transform collection of inlines /// </summary> public List<Inline> Decorate(IConferenceMessage msg, List<Inline> inlines) { inlines.Add(Decorate(msg, msg.Text)); return inlines; }
public MessageViewModel(IConferenceMessage msg) { RawMessage = msg; Paragraph = MessagePresenter.Present(msg); }