AppendMessage() public method

public AppendMessage ( Smuxi.Engine.ContactModel sender, string msg ) : MessageBuilder
sender Smuxi.Engine.ContactModel
msg string
return MessageBuilder
Beispiel #1
0
        void TestMessage(string message, MessageModel expectedMsg,
                         MessageBuilderSettings settings = null,
                         string assertFailMessage        = null)
        {
            var builder = new MessageBuilder();

            if (settings != null)
            {
                builder.Settings = settings;
            }
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendMessage(message);
            var actualMsg = builder.ToMessage();

            string assertFailMessagePrefix = String.Empty;

            if (assertFailMessage != null)
            {
                assertFailMessagePrefix = assertFailMessage + ": ";
            }

            Assert.AreEqual(expectedMsg.GetType(), actualMsg.GetType(),
                            assertFailMessagePrefix + "The message type does not match");
            Assert.AreEqual(expectedMsg.MessageParts.Count, actualMsg.MessageParts.Count,
                            assertFailMessagePrefix + "The number of message parts do not match");
            for (int i = 0; i < expectedMsg.MessageParts.Count; i++)
            {
                Assert.AreEqual(expectedMsg.MessageParts[i].GetType(),
                                actualMsg.MessageParts[i].GetType(),
                                assertFailMessagePrefix + "The type of the message part does not match");
            }
            Assert.AreEqual(expectedMsg, actualMsg,
                            assertFailMessagePrefix + "The message objects are not equal");
        }
Beispiel #2
0
 void TestMessage(string message, MessageModel expectedMsg)
 {
     var builder = new MessageBuilder();
     builder.TimeStamp = DateTime.MinValue;
     builder.AppendMessage(message);
     var actualMsg = builder.ToMessage();
     Assert.AreEqual(expectedMsg, actualMsg);
 }
Beispiel #3
0
 public void BenchmarkWithUrl()
 {
     int howOften = 5000;
     var nonurl = @"is this up to date? --> ";
     var url = @"http://www.stack.nl/~jilles/irc/atheme-help/";
     var withUrl = nonurl + url;
     var withoutUrl = @"Generated Sat Dec 11 21:29:16 CET 2010 -- old";
     var builder = new MessageBuilder();
     for (int i = 0; i < howOften; ++i) {
         builder.AppendMessage(withUrl);
     }
 }
Beispiel #4
0
        public void BenchmarkWithoutUrl()
        {
            int howOften   = 5000;
            var nonurl     = @"is this up to date? --> ";
            var url        = @"http://www.stack.nl/~jilles/irc/atheme-help/";
            var withUrl    = nonurl + url;
            var withoutUrl = @"Generated Sat Dec 11 21:29:16 CET 2010 -- old";
            var builder    = new MessageBuilder();

            for (int i = 0; i < howOften; ++i)
            {
                builder.AppendMessage(withoutUrl);
            }
        }
Beispiel #5
0
        public void ParseUrlsSimple()
        {
            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.AppendUrl("http://example.com");
            var expectedMsg = builder.ToMessage();

            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendMessage("http://example.com");
            var actualMsg = builder.ToMessage();

            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #6
0
        void TestMessage(string message, MessageModel expectedMsg)
        {
            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.AppendMessage(message);
            var actualMsg = builder.ToMessage();

            Assert.AreEqual(expectedMsg.GetType(), actualMsg.GetType(), "The message type does not match");
            Assert.AreEqual(expectedMsg.MessageParts.Count, actualMsg.MessageParts.Count, "The number of message parts do not match");
            for (int i = 0; i < expectedMsg.MessageParts.Count; i++)
            {
                Assert.AreEqual(expectedMsg.MessageParts[i].GetType(), actualMsg.MessageParts[i].GetType(), "The type of the message part does not match");
            }
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #7
0
        public void SetUp()
        {
            var builder = new MessageBuilder();

            builder.AppendIdendityName(
                new ContactModel("meeebey", "meebey", "netid", "netprot")
                );
            builder.AppendSpace();
            builder.AppendText("solange eine message aber keine url hat ist der vorteil nur gering (wenn ueberhaupt)");
            SimpleMessage = builder.ToMessage();

            var topic = "Smuxi the IRC client for sophisticated users: http://smuxi.org/ | Smuxi 0.7.2.2 'Lovegood' released (2010-07-27) http://bit.ly/9nvsZF | FAQ: http://smuxi.org/faq/ | Deutsch? -> #smuxi.de | Español? -> #smuxi.es | Smuxi @ FOSDEM 2010 talk: http://bit.ly/anHJfm";

            builder = new MessageBuilder();
            builder.AppendMessage(topic);
            ComplexMessage = builder.ToMessage();
        }
        public void SetUp()
        {
            JsConfig <MessagePartModel> .ExcludeTypeInfo = true;

            var builder = new MessageBuilder();

            builder.AppendSenderPrefix(
                new ContactModel("meeebey", "meebey", "netid", "netprot")
                );
            builder.AppendText("solange eine message aber keine url hat ist der vorteil nur gering (wenn ueberhaupt)");
            SimpleMessage      = builder.ToMessage();
            SimpleMessageJson  = JsonSerializer.SerializeToString(SimpleMessage);
            SimpleMessageDtoV1 = JsonSerializer.DeserializeFromString <MessageDtoModelV1>(SimpleMessageJson);

            var topic = "Smuxi the IRC client for sophisticated users: http://smuxi.org/ | Smuxi 0.7.2.2 'Lovegood' released (2010-07-27) http://bit.ly/9nvsZF | FAQ: http://smuxi.org/faq/ | Deutsch? -> #smuxi.de | Español? -> #smuxi.es | Smuxi @ FOSDEM 2010 talk: http://bit.ly/anHJfm";

            builder = new MessageBuilder();
            builder.AppendMessage(topic);
            builder.AppendText(" ");
            builder.AppendUrl("https://www.smuxi.org/issues/show/428", "smuxi#428");
            ComplexMessage      = builder.ToMessage();
            ComplexMessageJson  = JsonSerializer.SerializeToString(ComplexMessage);
            ComplexMessageDtoV1 = JsonSerializer.DeserializeFromString <MessageDtoModelV1>(ComplexMessageJson);
        }
Beispiel #9
0
        public void ParseUrlsParentheses()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("foo (");
            builder.AppendUrl("http://example.com");
            builder.AppendText(") bar");
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendMessage("foo (http://example.com) bar");
            var actualMsg = builder.ToMessage();

            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #10
0
        public virtual void Populate()
        {
            Trace.Call();

            Name = SyncedName;

            // sync messages
            // cleanup, be sure the output is empty
            _OutputMessageTextView.Clear();

            if (!Frontend.IsLocalEngine && Frontend.UseLowBandwidthMode) {
                var msg = new MessageBuilder();
                msg.AppendEventPrefix();
                msg.AppendMessage(_("Low Bandwidth Mode is active: no messages synced."));
                AddMessage(msg.ToMessage());
            } else {
                if (SyncedMessages != null) {
                    // TODO: push messages in batches and give back control to
                    // GTK+ in between for blocking the GUI thread less
                    foreach (MessageModel msg in SyncedMessages) {
                        AddMessage(msg);
                        if (msg.TimeStamp <= SyncedLastSeenMessage) {
                            // let the user know at which position new messages start
                            _OutputMessageTextView.UpdateMarkerline();
                        }
                    }
                }
            }

            // as we don't track which events have already been seen it would
            // show all chats with unseen events after the frontend connect
            if (!HasHighlight) {
                HasEvent = false;
                // Smuxi protocol < 0.13 does not support remembering seen
                // messages thus we mark all message as seen as we can't tell
                // which ones are new
                if (Frontend.EngineProtocolVersion < new Version(0, 13)) {
                    HasActivity = false;
                }
            }

            // reset tab icon to normal
            TabImage.Pixbuf = DefaultTabImage.Pixbuf;
            OnStatusChanged(EventArgs.Empty);

            SyncedMessages = null;
            IsSynced = true;
        }
Beispiel #11
0
        public void SetUp()
        {
            var builder = new MessageBuilder();
            builder.AppendIdendityName(
                new ContactModel("meeebey", "meebey", "netid", "netprot")
            );
            builder.AppendSpace();
            builder.AppendText("solange eine message aber keine url hat ist der vorteil nur gering (wenn ueberhaupt)");
            SimpleMessage = builder.ToMessage();

            var topic = "Smuxi the IRC client for sophisticated users: http://smuxi.org/ | Smuxi 0.7.2.2 'Lovegood' released (2010-07-27) http://bit.ly/9nvsZF | FAQ: http://smuxi.org/faq/ | Deutsch? -> #smuxi.de | Español? -> #smuxi.es | Smuxi @ FOSDEM 2010 talk: http://bit.ly/anHJfm";
            builder = new MessageBuilder();
            builder.AppendMessage(topic);
            ComplexMessage = builder.ToMessage();
        }
Beispiel #12
0
        public void CommandBenchmarkMessageBuilder(CommandModel cmd)
        {
            Trace.Call(cmd);

            var count = 1000;
            var showHelp = false;
            var appendMessage = false;
            var appendText = false;
            var appendEvent = false;
            var appendFormat = false;
            var toMessage = false;
            try {
                var opts = new NDesk.Options.OptionSet() {
                    { "c|count=", v => count = Int32.Parse(v) },
                    { "m|append-message", v => appendMessage = true },
                    { "t|append-text", v => appendText = true },
                    { "e|append-event", v => appendEvent = true },
                    { "f|append-format", v => appendFormat = true },
                    { "T|to-message", v => toMessage = true },
                };
                opts.Add("h|?|help", x => {
                    showHelp = true;
                    var writer = new StringWriter();
                    opts.WriteOptionDescriptions(writer);
                    AddMessageToFrontend(
                        cmd,
                        CreateMessageBuilder().
                            AppendHeader("{0} usage", cmd.Command).
                            AppendText("\n").
                            AppendText("Parameters:\n").
                            AppendText(writer.ToString()).
                            ToMessage()
                    );
                    return;
                });
                opts.Parse(cmd.Parameter.Split(' '));
                if (showHelp) {
                    return;
                }
            } catch (Exception ex) {
                AddMessageToFrontend(
                    cmd,
                    CreateMessageBuilder().
                        AppendErrorText("Invalid parameter: {0}", ex.Message).
                        ToMessage()
                );
                return;
            }

            DateTime start, stop;
            start = DateTime.UtcNow;
            MessageBuilder builder;
            for (var i = 0; i < count; i++) {
                builder = new MessageBuilder();
                if (appendMessage) {
                    builder.AppendMessage("This is message with a link to https://www.smuxi.org/.");
                }
                if (appendText) {
                    builder.AppendText("This is message with just text.");
                }
                if (appendEvent) {
                    builder.AppendEventPrefix();
                }
                if (appendFormat) {
                    builder.AppendFormat("{0} [{1}] has joined {2}",
                                         "meebey3",
                                         "[email protected]",
                                         "#smuxi-devel");
                }
                if (toMessage) {
                    var msg = builder.ToMessage();
                }
            }
            stop = DateTime.UtcNow;

            builder = new MessageBuilder();
            builder.AppendText("MessageBuilder().");
            if (appendMessage) {
                builder.AppendText("AppendMessage().");
            }
            if (appendText) {
                builder.AppendText("AppendText().");
            }
            if (appendEvent) {
                builder.AppendText("AppendEventPrefix().");
            }
            if (appendFormat) {
                builder.AppendText("AppendFormat().");
            }
            if (toMessage) {
                builder.AppendText("ToMessage()");
            }
            builder.AppendText(
                " count: {1} took: {2:0} ms avg: {3:0.00} ms",
                cmd.Data,
                count,
                (stop - start).TotalMilliseconds,
                (stop - start).TotalMilliseconds / count
            );
            AddMessageToFrontend(cmd, builder.ToMessage());
        }
        public void SetUp()
        {
            JsConfig<MessagePartModel>.ExcludeTypeInfo = true;

            var builder = new MessageBuilder();
            builder.AppendSenderPrefix(
                new ContactModel("meeebey", "meebey", "netid", "netprot")
            );
            builder.AppendText("solange eine message aber keine url hat ist der vorteil nur gering (wenn ueberhaupt)");
            SimpleMessage = builder.ToMessage();
            SimpleMessageJson = JsonSerializer.SerializeToString(SimpleMessage);
            SimpleMessageDtoV1 = JsonSerializer.DeserializeFromString<MessageDtoModelV1>(SimpleMessageJson);

            var topic = "Smuxi the IRC client for sophisticated users: http://smuxi.org/ | Smuxi 0.7.2.2 'Lovegood' released (2010-07-27) http://bit.ly/9nvsZF | FAQ: http://smuxi.org/faq/ | Deutsch? -> #smuxi.de | Español? -> #smuxi.es | Smuxi @ FOSDEM 2010 talk: http://bit.ly/anHJfm";
            builder = new MessageBuilder();
            builder.AppendMessage(topic);
            builder.AppendText(" ");
            builder.AppendUrl("https://www.smuxi.org/issues/show/428", "smuxi#428");
            ComplexMessage = builder.ToMessage();
            ComplexMessageJson = JsonSerializer.SerializeToString(ComplexMessage);
            ComplexMessageDtoV1 = JsonSerializer.DeserializeFromString<MessageDtoModelV1>(ComplexMessageJson);
        }
Beispiel #14
0
 void TestMessage(string message, MessageModel expectedMsg)
 {
     var builder = new MessageBuilder();
     builder.TimeStamp = DateTime.MinValue;
     builder.AppendMessage(message);
     var actualMsg = builder.ToMessage();
     Assert.AreEqual(expectedMsg, actualMsg);
 }
Beispiel #15
0
 void TestMessage(string message, MessageModel expectedMsg)
 {
     var builder = new MessageBuilder();
     builder.TimeStamp = DateTime.MinValue;
     builder.AppendMessage(message);
     var actualMsg = builder.ToMessage();
     Assert.AreEqual(expectedMsg.GetType(), actualMsg.GetType(), "The message type does not match");
     Assert.AreEqual(expectedMsg.MessageParts.Count, actualMsg.MessageParts.Count, "The number of message parts do not match");
     for (int i = 0; i < expectedMsg.MessageParts.Count; i++) {
         Assert.AreEqual(expectedMsg.MessageParts[i].GetType(), actualMsg.MessageParts[i].GetType(), "The type of the message part does not match");
     }
     Assert.AreEqual(expectedMsg, actualMsg);
 }
Beispiel #16
0
        public virtual void Populate()
        {
            Trace.Call();

            Name = SyncedName;

            // sync messages
            // cleanup, be sure the output is empty
            _OutputMessageTextView.Clear();

            if (!Frontend.IsLocalEngine && Frontend.UseLowBandwidthMode) {
                var msg = new MessageBuilder();
                msg.AppendEventPrefix();
                msg.AppendMessage(_("Low Bandwidth Mode is active: no messages synced."));
                AddMessage(msg.ToMessage());
            } else {
                if (SyncedMessages != null) {
                    // TODO: push messages in batches and give back control to
                    // GTK+ in between for blocking the GUI thread less
                    foreach (MessageModel msg in SyncedMessages) {
                        AddMessage(msg);
                    }
                }
            }

            // as we don't track which messages were already seen it would
            // show all chats with message activity after the frontend connect
            if (!HasHighlight) {
                HasActivity = false;
                HasEvent = false;
            }

            // let the user know at which position new messages start
            _OutputMessageTextView.UpdateMarkerline();

            // reset tab icon to normal
            TabImage.Pixbuf = DefaultTabImage.Pixbuf;
            OnStatusChanged(EventArgs.Empty);

            SyncedMessages = null;
            _IsSynced = true;
        }
Beispiel #17
0
        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());
        }