本文整理汇总了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);
}
示例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);
}