ToMessage() public method

public ToMessage ( ) : MessageModel
return MessageModel
        public void Contains()
        {
            Assert.IsTrue(Buffer.Contains(TestMessages[0]));

            var msg = new MessageBuilder();
            msg.AppendText("testfoo");
            Assert.IsFalse(Buffer.Contains(msg.ToMessage()));
        }
Beispiel #2
0
 public void AppendBrokenMail()
 {
     var msg = "mailto:/[email protected]";
     var builder = new MessageBuilder();
     builder.TimeStamp = DateTime.MinValue;
     builder.Append(new TextMessagePartModel("mailto:/"));
     builder.Append(new UrlMessagePartModel("mailto:[email protected]", "*****@*****.**"));
     TestMessage(msg, builder.ToMessage());
 }
        public void Add()
        {
            MessageBuilder msg = new MessageBuilder();
            msg.AppendText("test");

            int count = Buffer.Count;
            Buffer.Add(msg.ToMessage());
            Assert.AreEqual(count + 1, Buffer.Count);
        }
Beispiel #4
0
        public void AppendHtmlMessageBold()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");
            textPart.Bold = true;
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage("<b>Test</b>");
            var actualMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #5
0
        public void AppendHtmlMessageCssFgRed()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");
            textPart.ForegroundColor = new TextColor(255, 0, 0);
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage("<div style=\"color: #FF0000\">Test</div>");
            var actualMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #6
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.AppendText("http://example.com");
            var actualMsg = builder.ToMessage();
            MessageParser.ParseUrls(actualMsg);

            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #7
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 #8
0
        public void AppendHtmlMessageWithUrls()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            string html = @"<p>TextA<a href=""url"">urltext</a>TextB</p>";
            builder.AppendHtmlMessage(html);
            var actualMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("TextA");
            builder.AppendUrl("url", "urltext");
            builder.AppendText("TextB");

            var expectedMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #9
0
        public void AppendMessageWithSmartLinks()
        {
            var msg     = "RFC2812";
            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://www.ietf.org/rfc/rfc2812.txt", "RFC2812"));
            TestMessage(msg, builder.ToMessage());

            msg               = "(CVE-2017-0144)";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("("));
            builder.Append(new UrlMessagePartModel("http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0144", "CVE-2017-0144"));
            builder.Append(new TextMessagePartModel(")"));
            TestMessage(msg, builder.ToMessage());
        }
Beispiel #10
0
        public void AppendIPv6Links()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://[::1]"));
            TestMessage("http://[::1]", builder.ToMessage());

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://[2003:71:ce67:e700:3631:c4ff:fe2b:f874]:40000/"));
            TestMessage("http://[2003:71:ce67:e700:3631:c4ff:fe2b:f874]:40000/", builder.ToMessage());

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://[2a01:4f8:a0:7041::2]/"));
            TestMessage("http://[2a01:4f8:a0:7041::2]/", builder.ToMessage());
        }
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 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.AppendText("http://example.com");
            var actualMsg = builder.ToMessage();

            MessageParser.ParseUrls(actualMsg);

            Assert.AreEqual(expectedMsg, actualMsg);
        }
        public void ImplicitRemoveAt()
        {
            Buffer.MaxCapacity = 16;
            // generate 32 extra messsages to exceed the max capacity which
            // forces a RemoveAt() call of the oldest messages
            var bufferCount = Buffer.Count;
            var msgs = new List<MessageModel>(Buffer);
            for (int i = 1; i <= 32; i++) {
                var builder = new MessageBuilder();
                builder.AppendText("msg{0}", bufferCount + i);
                var msg = builder.ToMessage();
                msgs.Add(msg);
                Buffer.Add(msg);
            }

            Assert.AreEqual(Buffer.MaxCapacity, Buffer.Count);
            Assert.AreEqual(msgs[32 - (Buffer.MaxCapacity - bufferCount)].ToString(), Buffer[0].ToString());
        }
Beispiel #14
0
        public void AppendHtmlMessageCssFgRed()
        {
            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");

            textPart.ForegroundColor = new TextColor(255, 0, 0);
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage("<div style=\"color: #FF0000\">Test</div>");
            var actualMsg = builder.ToMessage();

            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #15
0
        public void AppendHtmlMessageBold()
        {
            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");

            textPart.Bold = true;
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage("<b>Test</b>");
            var actualMsg = builder.ToMessage();

            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #16
0
        public void AppendFormatWithSubmessage()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("I wonder if I can trick this bot to op me.");
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("op");
            var insideMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendFormat("I wonder if I can trick this bot to {0} me.", insideMsg);
            var actualMsg = builder.ToMessage();

            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #17
0
        public void AppendHtmlMessageWithNewlines()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            string html = "<p>TextA\nTextB<p>\nTextC</p>\n</p>";
            builder.AppendHtmlMessage(html);
            var actualMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("TextA");
            builder.AppendSpace();
            builder.AppendText("TextB");
            builder.AppendSpace();
            builder.AppendText("TextC");

            var expectedMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #18
0
        public void AppendHtmlMessageCssFgRedBgBlue()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");
            textPart.ForegroundColor = new TextColor(255, 0, 0);
            textPart.BackgroundColor = new TextColor(0, 0, 255);
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage(
                "<div style=\"" +
                    "color: #FF0000; " +
                    "background: #0000FF url('smiley.gif') no-repeat fixed center" +
                "\">Test</div>");
            var actualMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
Beispiel #19
0
 public void AppendTextUrlParsingSanity()
 {
     var msg = @"http://ab.cd.ef.de-hlub.gummi.museum/my_script%20windows.php?test=blub&blar=93";
     var builder = new MessageBuilder();
     builder.TimeStamp = DateTime.MinValue;
     builder.Append(new UrlMessagePartModel(msg));
     TestMessage(msg, builder.ToMessage());
     /*
     var msg = @"<http://smuxi.im/#sometag>";
     var msg = @"hey look at this: http://test.org, it is really cool";
     var msg = @"have you recently looked at xkcd.org?";
     var msg = @"my homepage (http://mine.my) has nothing on it";
     var msg = @"[smuxi] meebey pushed 2 new commits to stable: https://github.com/meebey/smuxi/compare/153153feddd4...ff7d23a7550c";
     var msg = @"[372 (Motd)] - FOSSCON [http://www.fosscon.org] and fossevents ";
     var msg = @"[372 (Motd)] - page (http://freenode.net/policy.shtml). Thank you for usin";
     var msg = @"look at all those deprecated fields pidgin still sets: <c xmlns=""http://jabber.org/protocol/caps"" hash=""sha-1"" node=""http://pidgin.im/"" ext=""voice-v1 camera-v1 video-v1"" ver=""AcN1/PEN8nq7AHD+9jpxMV4U6YM="" />";
     var msg = @"16:04:11 <clonkspot> Glückwunsch! (@YouTube http://t.co/IXjWtfGJ5d)";
     var msg = @"This is a http://sentence.that/ends.with?a. This is another sentence.";
     */
 }
Beispiel #20
0
        public void AppendHtmlMessageCssFgRedBgBlue()
        {
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            var textPart = builder.CreateText("Test");
            textPart.ForegroundColor = new TextColor(255, 0, 0);
            textPart.BackgroundColor = new TextColor(0, 0, 255);
            builder.Append(textPart);
            var expectedMsg = builder.ToMessage();

            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendHtmlMessage(
                "<div style=\"" +
                    "color: #FF0000; " +
                    "background: #0000FF url('smiley.gif') no-repeat fixed center" +
                "\">Test</div>");
            var actualMsg = builder.ToMessage();
            Assert.AreEqual(expectedMsg, actualMsg);
        }
        public void ImplicitFlush()
        {
            // generate 32 extra messsages to exceed the buffer size which
            // forces a flush of the buffer to db4o
            var bufferCount = Buffer.Count;
            var msgs = new List<MessageModel>(Buffer);
            for (int i = 1; i <= 32; i++) {
                var builder = new MessageBuilder();
                builder.AppendText("msg{0}", bufferCount + i);
                var msg = builder.ToMessage();
                msgs.Add(msg);
                Buffer.Add(msg);
            }

            int j = 0;
            foreach (var msg in Buffer) {
                Assert.AreEqual(msgs[j++].ToString(), msg.ToString());
            }
            Assert.AreEqual(msgs.Count, j);
        }
Beispiel #22
0
        public void ImplicitRemoveAt()
        {
            Buffer.MaxCapacity = 16;
            // generate 32 extra messsages to exceed the max capacity which
            // forces a RemoveAt() call of the oldest messages
            var bufferCount = Buffer.Count;
            var msgs        = new List <MessageModel>(Buffer);

            for (int i = 1; i <= 32; i++)
            {
                var builder = new MessageBuilder();
                builder.AppendText("msg{0}", bufferCount + i);
                var msg = builder.ToMessage();
                msgs.Add(msg);
                Buffer.Add(msg);
            }

            Assert.AreEqual(Buffer.MaxCapacity, Buffer.Count);
            Assert.AreEqual(msgs[32 - (Buffer.MaxCapacity - bufferCount)].ToString(), Buffer[0].ToString());
        }
Beispiel #23
0
 public void AppendTextUrlParsingEndsInQuestionmark()
 {
     var msg = @"have you recently looked at xkcd.com?";
     var url = @"http://xkcd.com";
     var urltext = @"xkcd.com";
     var builder = new MessageBuilder();
     builder.TimeStamp = DateTime.MinValue;
     builder.Append(new TextMessagePartModel("have you recently looked at "));
     builder.Append(new UrlMessagePartModel(url, urltext));
     builder.Append(new TextMessagePartModel("?"));
     TestMessage(msg, builder.ToMessage());
     /*
     var msg = @"my homepage (http://mine.my) has nothing on it";
     var msg = @"[smuxi] meebey pushed 2 new commits to stable: https://github.com/meebey/smuxi/compare/153153feddd4...ff7d23a7550c";
     var msg = @"[372 (Motd)] - FOSSCON [http://www.fosscon.org] and fossevents ";
     var msg = @"[372 (Motd)] - page (http://freenode.net/policy.shtml). Thank you for usin";
     var msg = @"look at all those deprecated fields pidgin still sets: <c xmlns=""http://jabber.org/protocol/caps"" hash=""sha-1"" node=""http://pidgin.im/"" ext=""voice-v1 camera-v1 video-v1"" ver=""AcN1/PEN8nq7AHD+9jpxMV4U6YM="" />";
     var msg = @"16:04:11 <clonkspot> Glückwunsch! (@YouTube http://t.co/IXjWtfGJ5d)";
     var msg = @"This is a http://sentence.that/ends.with?a. This is another sentence.";
     */
 }
Beispiel #24
0
        private void InitDatabase()
        {
            ConfigureDatabase();
            try {
                OpenDatabase();
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("InitDatabase(): failed to open message " +
                             "database: " + DatabaseFile, ex);
#endif
                FixDatabase(ex);
                // WORXNOWPLX
                OpenDatabase();

                var builder = new MessageBuilder();
                builder.AppendEventPrefix();
                builder.AppendErrorText(
                    _("Your chat history is no longer available because of " +
                      "an error but will be preserved from now on.")
                    );
                Add(builder.ToMessage());
            }
        }
Beispiel #25
0
        public void BrokenAppendMessageWithOddUrls()
        {
            var msg     = "https://en.wikipedia.org/wiki/Brace_(singer)";
            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel(msg));
            TestMessage(msg, builder.ToMessage());

            msg               = "see the link (https://en.wikipedia.org/wiki/Brace_(singer))";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("see the link ("));
            builder.Append(new UrlMessagePartModel(msg));
            builder.Append(new TextMessagePartModel(")"));
            TestMessage(msg, builder.ToMessage());

            msg               = "https://www.amazon.de/TP-Link-TL-SG105-Gigabit-lüfterloses-Passivkühlkonzept/dp/B00A128S24/";
            builder           = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel(msg));
            TestMessage(msg, builder.ToMessage());
        }
Beispiel #26
0
        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 #27
0
        public void ImplicitFlush()
        {
            // generate 32 extra messsages to exceed the buffer size which
            // forces a flush of the buffer to db4o
            var bufferCount = Buffer.Count;
            var msgs        = new List <MessageModel>(Buffer);

            for (int i = 1; i <= 32; i++)
            {
                var builder = new MessageBuilder();
                builder.AppendText("msg{0}", bufferCount + i);
                var msg = builder.ToMessage();
                msgs.Add(msg);
                Buffer.Add(msg);
            }

            int j = 0;

            foreach (var msg in Buffer)
            {
                Assert.AreEqual(msgs[j++].ToString(), msg.ToString());
            }
            Assert.AreEqual(msgs.Count, j);
        }
Beispiel #28
0
        public void SetUp()
        {
            Buffer       = CreateBuffer();
            TestMessages = new List <MessageModel>();

            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("msg1");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg2");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg3");
            TestMessages.Add(builder.ToMessage());

            foreach (var msg in TestMessages)
            {
                Buffer.Add(msg);
            }
        }
Beispiel #29
0
 bool TypingDotsCallback()
 {
     if (IsDisposed) {
         return false;
     }
     if (IsComposing) {
         NumberOfTypingDots++;
         if (NumberOfTypingDots == 4) {
             NumberOfTypingDots = 0;
         }
     } else {
         NumberOfTypingDots--;
         if (NumberOfTypingDots <= 0) {
             // done
             TypingDots = null;
             UpdateChatState();
             ChatStateTimeoutRunning = false;
             return false;
         }
     }
     var builder = new MessageBuilder();
     builder.AppendText(new string('.', NumberOfTypingDots));
     TypingDots = builder.ToMessage();
     UpdateChatState();
     GLib.Timeout.Add(300, TypingDotsCallback);
     return false;
 }
Beispiel #30
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 #31
0
        void CommandHelp(CommandModel cmd)
        {
            var chatView = f_MainWindow.ChatViewManager.GetChat(cmd.Chat);
            var builder = new MessageBuilder();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below
            builder.AppendHeader(_("Frontend Commands"));
            chatView.AddMessage(builder.ToMessage());

            string[] help = {
                "help",
                "window number",
                "exit",
            };

            foreach (string line in help) {
                builder = new MessageBuilder();
                builder.AppendEventPrefix();
                builder.AppendText(line);
                chatView.AddMessage(builder.ToMessage());
            }
        }
Beispiel #32
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 #33
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
            #if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
            #endif

            if (msg == null) {
                throw new ArgumentNullException("msg");
            }

            var buffer = Buffer;
            var iter = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);

            var senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag = null;
            if (senderPrefixWidth != 0) {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null) {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps) {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null) {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0) {
                        var dayLine = new MessageBuilder().
                            AppendEventPrefix();
                        if (span.Days > 1) {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        } else {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format)) {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null) {
                    InsertTimeStamp(buffer, ref iter, timestamp, msg);

                    // apply timestamp width to indent tag
                    if (indentTag != null) {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts) {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight) {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (UrlMessagePartModel) msgPart);
                } else if (msgPart is TextMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (TextMessagePartModel) msgPart);
                } else if (msgPart is ImageMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (ImageMessagePartModel) msgPart);
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event) {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null) {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null) {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak) {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17) {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null) {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null) {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight) {
                if (MessageHighlighted != null) {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
Beispiel #34
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());
        }
Beispiel #35
0
        public void CopyConstructor()
        {
            var builder = new MessageBuilder();
            builder.AppendEventPrefix();
            builder.AppendUrl("http://example.com");
            builder.AppendText("foobar");
            var msg = builder.ToMessage();
            var copiedMsg = new MessageModel(msg);

            Assert.AreNotSame(msg, copiedMsg);
            Assert.IsNotNull(copiedMsg.MessageParts);
            Assert.AreNotSame(msg.MessageParts, copiedMsg.MessageParts);
            Assert.AreEqual(msg, copiedMsg);
        }
Beispiel #36
0
        public void InitMessageBuffer(MessageBufferPersistencyType persistency)
        {
            Trace.Call(persistency);

            if (MessageBuffer != null) {
                return;
            }

            switch (persistency) {
                case MessageBufferPersistencyType.Volatile:
                    MessageBuffer = new ListMessageBuffer();
                    break;
                case MessageBufferPersistencyType.Persistent:
                    try {
                        var start = DateTime.UtcNow;
                        MessageBuffer = new Db4oMessageBuffer(
                            ProtocolManager.Session.Username,
                            ProtocolManager.Protocol,
                            ProtocolManager.NetworkID,
                            ID
                        );
                        var stop = DateTime.UtcNow;
            #if LOG4NET
                        _Logger.DebugFormat(
                            "InitMessageBuffer(): initializing " +
                            "Db4oMessageBuffer({0}, {1}, {2}, {3}) " +
                            "took: {4:0.00} ms",
                            ProtocolManager.Session.Username,
                            ProtocolManager.Protocol,
                            ProtocolManager.NetworkID,
                            ID,
                            (stop - start).TotalMilliseconds
                        );
            #endif
                    } catch (Exception ex) {
            #if LOG4NET
                        _Logger.Error(
                            "InitMessageBuffer(): Db4oMessageBuffer() threw " +
                            "exception, falling back to memory backend!", ex
                        );
            #endif
                        MessageBuffer = new ListMessageBuffer();

                        var builder = new MessageBuilder();
                        builder.AppendEventPrefix();
                        builder.AppendErrorText(
                            _("Failed to open chat history for writing. " +
                              "Your chat history will not be preserved. " +
                              "Reason: {0}"),
                            ex.Message
                        );
                        MessageBuffer.Add(builder.ToMessage());
                    }
                    break;
            }
        }
Beispiel #37
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 #38
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 #39
0
        void CommandGenerateMessages(CommandModel cmd)
        {
            var chat = ChatViewManager.CurrentChatView;
            _CommandManager.CommandGenerateMessages(cmd, chat);

            var builder = new MessageBuilder();
            builder.AppendText(
                "ChatView.AddMessage(): MessageTextTagTable.Size: {0}",
                chat.OutputMessageTextView.MessageTextTagTable.Size
            );
            chat.AddMessage(builder.ToMessage());
        }
Beispiel #40
0
        public void InitMessageBuffer(MessageBufferPersistencyType persistency)
        {
            Trace.Call(persistency);

            if (MessageBuffer != null)
            {
                return;
            }

            switch (persistency)
            {
            case MessageBufferPersistencyType.Volatile:
                MessageBuffer = new ListMessageBuffer();
                break;

            case Smuxi.Engine.MessageBufferPersistencyType.PersistentDb4o:
                try {
                    var start = DateTime.UtcNow;
                    MessageBuffer = new Db4oMessageBuffer(
                        ProtocolManager.Session.Username,
                        ProtocolManager.Protocol,
                        ProtocolManager.NetworkID,
                        ID
                        );
                    var stop = DateTime.UtcNow;
#if LOG4NET
                    _Logger.DebugFormat(
                        "InitMessageBuffer(): initializing " +
                        "Db4oMessageBuffer({0}, {1}, {2}, {3}) " +
                        "took: {4:0.00} ms",
                        ProtocolManager.Session.Username,
                        ProtocolManager.Protocol,
                        ProtocolManager.NetworkID,
                        ID,
                        (stop - start).TotalMilliseconds
                        );
#endif
                } catch (Exception ex) {
#if LOG4NET
                    _Logger.Error(
                        "InitMessageBuffer(): Db4oMessageBuffer() threw " +
                        "exception, falling back to memory backend!", ex
                        );
#endif
                    MessageBuffer = new ListMessageBuffer();

                    var builder = new MessageBuilder();
                    builder.AppendEventPrefix();
                    builder.AppendErrorText(
                        _("Failed to open chat history for writing. " +
                          "Your chat history will not be preserved. " +
                          "Reason: {0}"),
                        ex.Message
                        );
                    MessageBuffer.Add(builder.ToMessage());
                }
                break;

            case Smuxi.Engine.MessageBufferPersistencyType.Persistent:
            case Smuxi.Engine.MessageBufferPersistencyType.PersistentSqlite: {
                var start = DateTime.UtcNow;
                MessageBuffer = new SqliteMessageBuffer(
                    ProtocolManager.Session.Username,
                    ProtocolManager.Protocol,
                    ProtocolManager.NetworkID,
                    ID
                    );
                var stop = DateTime.UtcNow;
#if LOG4NET
                _Logger.DebugFormat(
                    "InitMessageBuffer(): initializing " +
                    "SqliteMessageBuffer({0}, {1}, {2}, {3}) " +
                    "took: {4:0.00} ms",
                    ProtocolManager.Session.Username,
                    ProtocolManager.Protocol,
                    ProtocolManager.NetworkID,
                    ID,
                    (stop - start).TotalMilliseconds
                    );
#endif
            }
            break;
            }
        }
        public void IndexOf()
        {
            Assert.AreEqual(1, Buffer.IndexOf(TestMessages[1]));

            var builder = new MessageBuilder();
            builder.AppendText("non-existent");
            var msg = builder.ToMessage();
            Assert.AreEqual(-1, Buffer.IndexOf(msg));
        }
Beispiel #42
0
 public virtual void RenderPersonIdentityName(Gtk.TreeViewColumn column,
                                              Gtk.CellRenderer cellr,
                                              Gtk.TreeModel model, Gtk.TreeIter iter)
 {
     PersonModel person = (PersonModel) model.GetValue(iter, 0);
     var renderer = (Gtk.CellRendererText) cellr;
     if (NickColors) {
         // TODO: do we need to optimize this? it's called very often...
         Gdk.Color bgColor = _PersonTreeView.Style.Base(Gtk.StateType.Normal);
         var builder = new MessageBuilder();
         builder.Settings.NickColors = true;
         builder.AppendNick(person);
         renderer.Markup = PangoTools.ToMarkup(builder.ToMessage(),
                                               bgColor);
     } else {
         renderer.Text = person.IdentityName;
     }
 }
Beispiel #43
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
            #if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
            #endif

            if (msg == null) {
                throw new ArgumentNullException("msg");
            }

            var buffer = Buffer;
            var iter = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);

            var senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag = null;
            if (senderPrefixWidth != 0) {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null) {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps) {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null) {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0) {
                        var dayLine = new MessageBuilder().
                            AppendEventPrefix();
                        if (span.Days > 1) {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        } else {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format)) {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null) {
                    timestamp = String.Format("{0} ", timestamp);
                    buffer.Insert(ref iter, timestamp);

                    // apply timestamp width to indent tag
                    if (indentTag != null) {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts) {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight) {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel) {
                    var urlPart = (UrlMessagePartModel) msgPart;
                    var linkText = urlPart.Text ?? urlPart.Url;

                    var url = urlPart.Url;
                    Uri uri;
                    try {
                        uri = new Uri(url);
                    } catch (UriFormatException ex) {
            #if LOG4NET
                        _Logger.Error("AddMessage(): Invalid URL: " + url, ex);
            #endif
                        buffer.Insert(ref iter, linkText);
                        continue;
                    }

                    var tags = new List<Gtk.TextTag>();
                    // link URI tag
                    var linkTag = new LinkTag(uri);
                    linkTag.TextEvent += OnLinkTagTextEvent;
                    _MessageTextTagTable.Add(linkTag);
                    tags.Add(linkTag);

                    // link style tag
                    tags.Add(LinkTag);

                    buffer.InsertWithTags(ref iter, linkText, tags.ToArray());
                } else if (msgPart is TextMessagePartModel) {
                    var tags = new List<Gtk.TextTag>();
                    TextMessagePartModel fmsgti = (TextMessagePartModel) msgPart;
                    if (fmsgti.ForegroundColor != TextColor.None) {
                        var bg = ColorConverter.GetTextColor(BackgroundColor);
                        if (fmsgti.BackgroundColor != TextColor.None) {
                            bg = fmsgti.BackgroundColor;
                        }
                        TextColor color = TextColorTools.GetBestTextColor(
                            fmsgti.ForegroundColor, bg
                        );
                        string tagname = GetTextTagName(color, null);
                        var tag = _MessageTextTagTable.Lookup(tagname);
                        tags.Add(tag);
                    }
                    if (fmsgti.BackgroundColor != TextColor.None) {
                        // TODO: get this from ChatView
                        string tagname = GetTextTagName(null, fmsgti.BackgroundColor);
                        var tag = _MessageTextTagTable.Lookup(tagname);
                        tags.Add(tag);
                    }
                    if (fmsgti.Underline) {
            #if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Underline is true");
            #endif
                        tags.Add(UnderlineTag);
                    }
                    if (fmsgti.Bold) {
            #if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Bold is true");
            #endif
                        tags.Add(BoldTag);
                    }
                    if (fmsgti.Italic) {
            #if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Italic is true");
            #endif
                        tags.Add(ItalicTag);
                    }

                    if (tags.Count > 0) {
                        buffer.InsertWithTags(ref iter, fmsgti.Text, tags.ToArray());
                    } else {
                        buffer.Insert(ref iter, fmsgti.Text);
                    }
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event) {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null) {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null) {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak) {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17) {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null) {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null) {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight) {
                if (MessageHighlighted != null) {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
Beispiel #44
0
 bool UpdateChatState()
 {
     if (IsDisposed) {
         return false;
     }
     if (IsComposing) {
         NumberOfTypingDots++;
         if (NumberOfTypingDots == 4) {
             NumberOfTypingDots = 0;
         }
     } else {
         NumberOfTypingDots--;
         if (NumberOfTypingDots <= 0) {
             // done
             DeleteOldChatState();
             ChatStateTimeoutRunning = false;
             return false;
         }
     }
     var builder = new MessageBuilder();
     builder.AppendText(new string('.', NumberOfTypingDots));
     AddChatState(builder.ToMessage());
     GLib.Timeout.Add(300, UpdateChatState);
     return false;
 }
Beispiel #45
0
        public void AppendMessageWithOddUrls()
        {
            var msg = @"zack: http://anonscm.debian.org/gitweb/?p=lintian/lintian.git;a=blob;f=checks/source-copyright.desc;h=3276a57e81b1c8c38073e667221e262df1a606c0;hb=167170d7911473a726f7e77008d8b2246a6822e8";
            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("zack: "));
            builder.Append(new UrlMessagePartModel("http://anonscm.debian.org/gitweb/?p=lintian/lintian.git;a=blob;f=checks/source-copyright.desc;h=3276a57e81b1c8c38073e667221e262df1a606c0;hb=167170d7911473a726f7e77008d8b2246a6822e8"));
            TestMessage(msg, builder.ToMessage());

            msg = "http://sources.debian.net/src/kfreebsd-10/10.0~svn259778-1/sys/cddl/dev/dtrace/dtrace_anon.c";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://sources.debian.net/src/kfreebsd-10/10.0~svn259778-1/sys/cddl/dev/dtrace/dtrace_anon.c"));
            TestMessage(msg, builder.ToMessage());

            msg = "http://www.stack.nl/~jilles/cgi-bin/hgwebdir.cgi/charybdis/raw-rev/9d769851c1c7";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://www.stack.nl/~jilles/cgi-bin/hgwebdir.cgi/charybdis/raw-rev/9d769851c1c7"));
            TestMessage(msg, builder.ToMessage());

            msg = "<RAOF> meebey: Associated mono branch is master-experimental in git+ssh://git.debian.org/~/public_git/mono.git";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<RAOF> meebey: Associated mono branch is master-experimental in "));
            builder.Append(new UrlMessagePartModel("git+ssh://git.debian.org/~/public_git/mono.git"));
            TestMessage(msg, builder.ToMessage());

            msg = "<knocte> meebey: does this URL highlight ok with latest master?  https://groups.google.com/forum/#!topic/fsharp-opensource/KLejo_vw5R4";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<knocte> meebey: does this URL highlight ok with latest master?  "));
            builder.Append(new UrlMessagePartModel("https://groups.google.com/forum/#!topic/fsharp-opensource/KLejo_vw5R4"));
            TestMessage(msg, builder.ToMessage());

            msg = "<astronouth7303> found another bad URL: http://www.flickr.com/photos/34962649@N00/12000715226/in/photostream/";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<astronouth7303> found another bad URL: "));
            builder.Append(new UrlMessagePartModel("http://www.flickr.com/photos/34962649@N00/12000715226/in/photostream/"));
            TestMessage(msg, builder.ToMessage());

            msg = "http://en.wikipedia.org/Talk:Main_Page";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://en.wikipedia.org/Talk:Main_Page"));
            TestMessage(msg, builder.ToMessage());

            msg = "http://en.wikipedia.org/wiki/Godunov's_scheme";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://en.wikipedia.org/wiki/Godunov's_scheme"));
            TestMessage(msg, builder.ToMessage());

            msg = "<astronouth7303> ok, this is just trippy URL matching: http://couchdb.local/mydb/_magic";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new TextMessagePartModel("<astronouth7303> ok, this is just trippy URL matching: "));
            builder.Append(new UrlMessagePartModel("http://couchdb.local/mydb/_magic"));
            TestMessage(msg, builder.ToMessage());

            msg = "https://web.archive.org/web/20050208144213/http://www.jaganelli.de/";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("https://web.archive.org/web/20050208144213/http://www.jaganelli.de/"));
            TestMessage(msg, builder.ToMessage());

            msg = "irc://freenode/smuxi";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel(msg));
            TestMessage(msg, builder.ToMessage());

            msg = "http://www.test.de/bilder.html?data[meta_id]=13895&data[bild_id]=7";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel("http://www.test.de/bilder.html?data[meta_id]=13895&data[bild_id]=7"));
            TestMessage(msg, builder.ToMessage());

            msg = "https://eu.api.soyoustart.com/console/#/order/dedicated/server/{serviceName}#GET";
            builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.Append(new UrlMessagePartModel(msg));
            TestMessage(msg, builder.ToMessage());
        }
        public void SetUp()
        {
            Buffer = CreateBuffer();
            TestMessages = new List<MessageModel>();

            var builder = new MessageBuilder();
            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("msg1");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg2");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendErrorText("msg3");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg4");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg5");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg6");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg7");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg8");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg9");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg10");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg11");
            TestMessages.Add(builder.ToMessage());

            foreach (var msg in TestMessages) {
                Buffer.Add(msg);
            }

            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();
        }
Beispiel #47
0
        private void _CommandHelp(CommandModel cd)
        {
            var chatView = ChatViewManager.GetChat(cd.Chat);
            var builder = new MessageBuilder();
            // TRANSLATOR: this line is used as a label / category for a
            // list of commands below
            builder.AppendHeader(_("Frontend Commands"));
            chatView.AddMessage(builder.ToMessage());

            string[] help = {
            "window (number|channelname|queryname|close)",
            "sync",
            "sort",
            "clear",
            "echo data",
            "exec command",
            "detach",
            "list [search key]",
            };

            foreach (string line in help) {
                builder = new MessageBuilder();
                builder.AppendEventPrefix();
                builder.AppendText(line);
                chatView.AddMessage(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 #49
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());
        }
Beispiel #50
0
        private void CommandWindow(CommandModel cmd)
        {
            if (cmd.Parameter == "close") {
                f_ChatViewManager.CurrentChat.Close();
                return;
            } else if (cmd.Parameter == "list") {
                var thisChatView = f_MainWindow.ChatViewManager.GetChat(cmd.Chat);

                for (int i = 0;; ++i) {
                    ChatView availableChatView = f_MainWindow.ChatViewManager.GetChat(i);
                    if (availableChatView == null) {
                        break;
                    }

                    var builder = new MessageBuilder();
                    builder.AppendEventPrefix();
                    builder.AppendFormat("{0} - {1}", i + 1, availableChatView.Name ?? "");
                    thisChatView.AddMessage(builder.ToMessage());
                }
                return;
            }

            int window;
            if (!Int32.TryParse(cmd.Parameter, out window)) {
                return;
            }
            ChatView chat = f_ChatViewManager.GetChat(window - 1);
            if (chat == null) {
                return;
            }
            f_ChatViewManager.CurrentChat = chat;
        }
Beispiel #51
0
        private void InitDatabase()
        {
            ConfigureDatabase();
            try {
                OpenDatabase();
            } catch (Exception ex) {
            #if LOG4NET
                Logger.Error("InitDatabase(): failed to open message " +
                             "database: " + DatabaseFile, ex);
            #endif
                FixDatabase(ex);
                // WORXNOWPLX
                OpenDatabase();

                var builder = new MessageBuilder();
                builder.AppendEventPrefix();
                builder.AppendErrorText(
                    _("Your chat history is no longer available because of " +
                      "an error but will be preserved from now on.")
                );
                Add(builder.ToMessage());
            }
        }
Beispiel #52
0
        public void SetUp()
        {
            Buffer       = CreateBuffer();
            TestMessages = new List <MessageModel>();

            var builder = new MessageBuilder();

            builder.TimeStamp = DateTime.MinValue;
            builder.AppendText("msg1");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg2");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendErrorText("msg3");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg4");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg5");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg6");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg7");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg8");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg9");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg10");
            TestMessages.Add(builder.ToMessage());

            builder = new MessageBuilder();
            builder.AppendText("msg11");
            TestMessages.Add(builder.ToMessage());

            foreach (var msg in TestMessages)
            {
                Buffer.Add(msg);
            }

            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();
        }