當前位置: 首頁>>代碼示例>>C#>>正文


C# MessageModel.Compact方法代碼示例

本文整理匯總了C#中Smuxi.Engine.MessageModel.Compact方法的典型用法代碼示例。如果您正苦於以下問題:C# MessageModel.Compact方法的具體用法?C# MessageModel.Compact怎麽用?C# MessageModel.Compact使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Smuxi.Engine.MessageModel的用法示例。


在下文中一共展示了MessageModel.Compact方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Compact

        public void Compact()
        {
            var msg = new MessageModel("foo bar");
            msg.Compact();
            Assert.AreEqual(1, msg.MessageParts.Count);
            var textPart = (TextMessagePartModel) msg.MessageParts[0];
            Assert.AreEqual("foo bar", textPart.Text);

            msg = new MessageModel();
            msg.MessageParts.Add(new TextMessagePartModel("foo"));
            msg.MessageParts.Add(new TextMessagePartModel(" bar"));
            msg.MessageParts.Add(new TextMessagePartModel(" me"));
            msg.Compact();
            Assert.AreEqual(1, msg.MessageParts.Count);
            textPart = (TextMessagePartModel) msg.MessageParts[0];
            Assert.AreEqual("foo bar me", textPart.Text);

            msg = new MessageModel();
            msg.MessageParts.Add(new TextMessagePartModel("foo"));
            msg.MessageParts.Add(new TextMessagePartModel(" bar"));
            msg.MessageParts.Add(new TextMessagePartModel(" me", true));
            msg.Compact();
            Assert.AreEqual(2, msg.MessageParts.Count);
            textPart = (TextMessagePartModel) msg.MessageParts[0];
            Assert.AreEqual("foo bar", textPart.Text);
            textPart = (TextMessagePartModel) msg.MessageParts[1];
            Assert.AreEqual(" me", textPart.Text);
            Assert.IsTrue(textPart.IsHighlight);

            var msgA = new MessageModel();
            msgA.MessageParts.Add(new TextMessagePartModel(TextColor.Black, null, false, false, false, "foo"));
            msgA.MessageParts.Add(new TextMessagePartModel(TextColor.White, null, false, false, false, " bar"));
            var msgB = new MessageModel();
            msgB.TimeStamp = msgA.TimeStamp;
            msgB.MessageParts.Add(new TextMessagePartModel(TextColor.Black, null, false, false, false, "foo"));
            msgB.MessageParts.Add(new TextMessagePartModel(TextColor.White, null, false, false, false, " bar"));
            msgB.Compact();
            Assert.AreEqual(2, msg.MessageParts.Count);
            Assert.AreEqual(msgA, msgB);

            msg = new MessageModel();
            msg.MessageParts.Add(new TextMessagePartModel("foo "));
            msg.MessageParts.Add(new UrlMessagePartModel("http://foo.tld"));
            msg.MessageParts.Add(new UrlMessagePartModel("http://bar.tld"));
            msg.MessageParts.Add(new TextMessagePartModel(" bar", true));
            msg.MessageParts.Add(new TextMessagePartModel(" me", true));
            msg.MessageParts.Add(new TextMessagePartModel(" real"));
            msg.MessageParts.Add(new TextMessagePartModel(" good"));
            msg.Compact();
            Assert.AreEqual(5, msg.MessageParts.Count);

            Assert.IsInstanceOfType(typeof(TextMessagePartModel), msg.MessageParts[0]);
            textPart = (TextMessagePartModel) msg.MessageParts[0];
            Assert.AreEqual("foo ", textPart.Text);

            Assert.IsInstanceOfType(typeof(UrlMessagePartModel), msg.MessageParts[1]);
            var urlPart = (UrlMessagePartModel) msg.MessageParts[1];
            Assert.AreEqual("http://foo.tld", urlPart.Url);

            Assert.IsInstanceOfType(typeof(UrlMessagePartModel), msg.MessageParts[2]);
            urlPart = (UrlMessagePartModel) msg.MessageParts[2];
            Assert.AreEqual("http://bar.tld", urlPart.Url);

            Assert.IsInstanceOfType(typeof(TextMessagePartModel), msg.MessageParts[3]);
            textPart = (TextMessagePartModel) msg.MessageParts[3];
            Assert.AreEqual(" bar me", textPart.Text);
            Assert.IsTrue(textPart.IsHighlight);

            Assert.IsInstanceOfType(typeof(TextMessagePartModel), msg.MessageParts[4]);
            textPart = (TextMessagePartModel) msg.MessageParts[4];
            Assert.AreEqual(" real good", textPart.Text);
            Assert.IsFalse(textPart.IsHighlight);
        }
開發者ID:Jaykul,項目名稱:smuxi,代碼行數:73,代碼來源:MessageModelTests.cs

示例2: CompactBenchmark

        public void CompactBenchmark()
        {
            var formatter = new BinaryFormatter();
            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";
            var msg = new MessageModel(topic) {
                IsCompactable = false
            };

            var stream = new MemoryStream(1024);
            formatter.Serialize(stream, msg);
            Console.WriteLine("Parts: " + msg.MessageParts.Count);
            Console.WriteLine("Size: " + stream.Length);

            msg.Compact();
            stream = new MemoryStream(1024);
            formatter.Serialize(stream, msg);
            Console.WriteLine("Compacted Parts: " + msg.MessageParts.Count);
            Console.WriteLine("Compacted Size: " + stream.Length);

            // regular message without URL
            // <meebey> solange eine message aber keine url hat ist der vorteil nur gering (wenn ueberhaupt)
            msg = new MessageModel() {
                IsCompactable = false
            };
            msg.MessageParts.Add(new TextMessagePartModel("<"));
            msg.MessageParts.Add(
                new TextMessagePartModel(
                    TextColor.White, null, false, false, false, "meebey"
                )
            );
            msg.MessageParts.Add(new TextMessagePartModel("> "));
            msg.MessageParts.Add(
                new TextMessagePartModel(
                    "solange eine message aber keine url hat ist der " +
                    "vorteil nur gering (wenn ueberhaupt)"
                )
            );
            stream = new MemoryStream(1024);
            formatter.Serialize(stream, msg);
            Console.WriteLine("Parts: " + msg.MessageParts.Count);
            Console.WriteLine("Size: " + stream.Length);

            msg.Compact();
            stream = new MemoryStream(1024);
            formatter.Serialize(stream, msg);
            Console.WriteLine("Compacted Parts: " + msg.MessageParts.Count);
            Console.WriteLine("Compacted Size: " + stream.Length);

            // regular short message with URL
            // <meebey> http://www.smuxi.org/issues/show/107 kannst ja watchen
            msg = new MessageModel() {
                IsCompactable = false
            };
            msg.MessageParts.Add(new TextMessagePartModel("<"));
            msg.MessageParts.Add(
                new TextMessagePartModel(
                    TextColor.White, null, false, false, false, "meebey"
                )
            );
            msg.MessageParts.Add(new TextMessagePartModel("> "));
            msg.MessageParts.Add(
                new UrlMessagePartModel(
                    "http://www.smuxi.org/issues/show/107"
                )
            );
            msg.MessageParts.Add(new TextMessagePartModel(" kannst ja watchen"));

            stream = new MemoryStream(1024);
            formatter.Serialize(stream, msg);
            Console.WriteLine("Parts: " + msg.MessageParts.Count);
            Console.WriteLine("Size: " + stream.Length);

            msg.Compact();
            stream = new MemoryStream(1024);
            formatter.Serialize(stream, msg);
            Console.WriteLine("Compacted Parts: " + msg.MessageParts.Count);
            Console.WriteLine("Compacted Size: " + stream.Length);
        }
開發者ID:Jaykul,項目名稱:smuxi,代碼行數:78,代碼來源:MessageModelTests.cs


注:本文中的Smuxi.Engine.MessageModel.Compact方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。