当前位置: 首页>>代码示例>>C#>>正文


C# MessageBuilder.ToMessage方法代码示例

本文整理汇总了C#中Smuxi.Engine.MessageBuilder.ToMessage方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBuilder.ToMessage方法的具体用法?C# MessageBuilder.ToMessage怎么用?C# MessageBuilder.ToMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Smuxi.Engine.MessageBuilder的用法示例。


在下文中一共展示了MessageBuilder.ToMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Contains

        public void Contains()
        {
            Assert.IsTrue(Buffer.Contains(TestMessages[0]));

            var msg = new MessageBuilder();
            msg.AppendText("testfoo");
            Assert.IsFalse(Buffer.Contains(msg.ToMessage()));
        }
开发者ID:grendello,项目名称:smuxi,代码行数:8,代码来源:MessageBufferTestsBase.cs

示例2: Add

        public void Add()
        {
            MessageBuilder msg = new MessageBuilder();
            msg.AppendText("test");

            int count = Buffer.Count;
            Buffer.Add(msg.ToMessage());
            Assert.AreEqual(count + 1, Buffer.Count);
        }
开发者ID:NattyNarwhal,项目名称:smuxi,代码行数:9,代码来源:MessageBufferTestsBase.cs

示例3: AppendBrokenMail

 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]", "[email protected]"));
     TestMessage(msg, builder.ToMessage());
 }
开发者ID:glwu,项目名称:smuxi,代码行数:9,代码来源:MessageBuilderTests.cs

示例4: AppendHtmlMessageBold

        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);
        }
开发者ID:oli-obk,项目名称:smuxi,代码行数:15,代码来源:MessageBuilderTests.cs

示例5: AppendHtmlMessageCssFgRed

        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);
        }
开发者ID:oli-obk,项目名称:smuxi,代码行数:15,代码来源:MessageBuilderTests.cs

示例6: ParseUrlsSimple

        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);
        }
开发者ID:grendello,项目名称:smuxi,代码行数:15,代码来源:MessageParserTests.cs

示例7: ImplicitRemoveAt

        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());
        }
开发者ID:pacificIT,项目名称:smuxi,代码行数:18,代码来源:Db4oMessageBufferTests.cs

示例8: AppendHtmlMessageCssFgRedBgBlue

        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);
        }
开发者ID:oli-obk,项目名称:smuxi,代码行数:20,代码来源:MessageBuilderTests.cs

示例9: ImplicitFlush

        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);
        }
开发者ID:pacificIT,项目名称:smuxi,代码行数:20,代码来源:Db4oMessageBufferTests.cs

示例10: Populate

        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;
        }
开发者ID:meebey,项目名称:smuxi,代码行数:48,代码来源:ChatView.cs

示例11: CommandGenerateMessages

        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());
        }
开发者ID:johansson,项目名称:smuxi,代码行数:37,代码来源:CommandManager.cs

示例12: CommandGenerateMessages

        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());
        }
开发者ID:pacificIT,项目名称:smuxi,代码行数:12,代码来源:Entry.cs

示例13: RenderPersonIdentityName

 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;
     }
 }
开发者ID:pacificIT,项目名称:smuxi,代码行数:18,代码来源:GroupChatView.cs

示例14: InitMessageBuffer

        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;
            }
        }
开发者ID:grendello,项目名称:smuxi,代码行数:56,代码来源:ChatModel.cs

示例15: AddMessage

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

//.........这里部分代码省略.........
开发者ID:meebey,项目名称:smuxi,代码行数:101,代码来源:MessageTextView.cs


注:本文中的Smuxi.Engine.MessageBuilder.ToMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。