public void CommandGenerateMessages(CommandModel cmd, IChatView chat) { Trace.Call(cmd, chat); var count = 0; Int32.TryParse(cmd.Parameter, out count); var builder = new MessageBuilder(); var sender = new ContactModel("msg-tester", "msg-tester", "test", "test"); builder.AppendMessage(sender, "time for a messsage generator command so I can test speed and memory usage"); var text = builder.CreateText(" *formatted text* "); text.Bold = true; builder.Append(text); builder.AppendUrl("https://www.smuxi.org/"); var msgs = new List <MessageModel>(count); for (var i = 0; i < count; i++) { var msg = builder.ToMessage(); msgs.Add(msg); } DateTime start, stop; start = DateTime.UtcNow; foreach (var msg in msgs) { chat.AddMessage(msg); } stop = DateTime.UtcNow; builder = new MessageBuilder(); builder.AppendText( "IChatView.AddMessage(): count: {0} took: {1:0} ms avg: {2:0.00} ms", count, (stop - start).TotalMilliseconds, (stop - start).TotalMilliseconds / count ); chat.AddMessage(builder.ToMessage()); }
public void CommandGenerateMessages(CommandModel cmd, IChatView chat) { Trace.Call(cmd, chat); var count = 0; Int32.TryParse(cmd.Parameter, out count); var builder = new MessageBuilder(); var sender = new ContactModel("msg-tester", "msg-tester", "test", "test"); builder.AppendMessage(sender, "time for a messsage generator command so I can test speed and memory usage"); var text = builder.CreateText(" *formatted text* "); text.Bold = true; builder.Append(text); builder.AppendUrl("https://www.smuxi.org/"); var msgs = new List<MessageModel>(count); for (var i = 0; i < count; i++) { var msg = builder.ToMessage(); msgs.Add(msg); } DateTime start, stop; start = DateTime.UtcNow; foreach (var msg in msgs) { chat.AddMessage(msg); } stop = DateTime.UtcNow; builder = new MessageBuilder(); builder.AppendText( "IChatView.AddMessage(): count: {0} took: {1:0} ms avg: {2:0.00} ms", count, (stop - start).TotalMilliseconds, (stop - start).TotalMilliseconds / count ); chat.AddMessage(builder.ToMessage()); }
public void OnMessageReceived(string message) { chatView?.AddMessage(message); }
public override void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView) { // isolate the nick to complete int matchPosition; bool appendSpace, leadingAt; string matchMe = IsolateNickToComplete(entryLine, cursorPosition, out matchPosition, out appendSpace, out leadingAt); bool appendCompletionChar = (matchPosition == 0); int additionalSteps = 0; // find the matching nicknames var nicks = NicksMatchingPrefix(currentChatView.Participants, matchMe); if (nicks.Count == 0) { // no matches; do nothing return; } else if (nicks.Count == 1) { // bingo! string nick = nicks [0]; // suppress the completion character if we had an @ if (leadingAt) { appendCompletionChar = false; } // find the beginning and end of the string string prefix = entryLine.Substring(0, matchPosition); string suffix = entryLine.Substring(matchPosition + matchMe.Length); // append the completion character and a space, if requested if (appendSpace) { suffix = ' ' + suffix; ++additionalSteps; } if (appendCompletionChar) { suffix = CompletionChar + suffix; ++additionalSteps; } // assemble the line and move the cursor entryLine = prefix + nick + suffix; cursorPosition = matchPosition + nick.Length + additionalSteps; } else { // find the longest common prefix string lcp = LongestCommonPrefix(nicks); // assemble nickname string string nickString = string.Join(" ", nicks.ToArray()); // output the matched prefixes currentChatView.AddMessage( new MessageModel(String.Format("-!- {0}", nickString)) ); // extend to the longest match string prefix = entryLine.Substring(0, matchPosition); string suffix = entryLine.Substring(matchPosition + matchMe.Length); // assemble the line and move the cursor entryLine = prefix + lcp + suffix; cursorPosition = matchPosition + lcp.Length; } }