[smuxi/experiments/sqlite: 3/27] [Engine] Implemented MessageDtoModelV1
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi/experiments/sqlite: 3/27] [Engine] Implemented MessageDtoModelV1
- Date: Sun, 23 Feb 2014 17:06:38 +0000 (UTC)
commit 6dacffd19b0fb3d7aa00227f3af18a52154a5c3f
Author: Mirco Bauer <meebey meebey net>
Date: Thu Feb 23 22:59:34 2012 +0100
[Engine] Implemented MessageDtoModelV1
src/Engine-Tests/MessageDtoModelV1Tests.cs | 94 +++++++++++++++++++++++++
src/Engine/Messages/Dto/MessageDtoModelV1.cs | 96 ++++++++++++++++++++++++++
src/Engine/Messages/ImageMessagePartModel.cs | 4 +
src/Engine/Messages/UrlMessagePartModel.cs | 4 +
4 files changed, 198 insertions(+), 0 deletions(-)
---
diff --git a/src/Engine-Tests/MessageDtoModelV1Tests.cs b/src/Engine-Tests/MessageDtoModelV1Tests.cs
new file mode 100644
index 0000000..9beb9ac
--- /dev/null
+++ b/src/Engine-Tests/MessageDtoModelV1Tests.cs
@@ -0,0 +1,94 @@
+// Smuxi - Smart MUltipleXed Irc
+//
+// Copyright (c) 2012 Mirco Bauer <meebey meebey net>
+//
+// Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+using System;
+using NUnit.Framework;
+using ServiceStack.Text;
+using Smuxi.Engine.Dto;
+
+namespace Smuxi.Engine
+{
+ public class MessageDtoModelV1Tests
+ {
+ MessageModel SimpleMessage { get; set; }
+ MessageModel ComplexMessage { get; set; }
+ MessageDtoModelV1 SimpleMessageDtoV1 { get; set; }
+ MessageDtoModelV1 ComplexMessageDtoV1 { get; set; }
+ string SimpleMessageJson { get; set; }
+ string ComplexMessageJson { get; set; }
+
+ [TestFixtureSetUp]
+ public void SetUp()
+ {
+ JsConfig<MessagePartModel>.ExcludeTypeInfo = true;
+
+ 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();
+ 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";
+ var msg = new MessageModel(topic);
+ MessageParser.ParseUrls(msg);
+ msg.Compact();
+ ComplexMessage = msg;
+ ComplexMessageJson = JsonSerializer.SerializeToString(ComplexMessage);
+ ComplexMessageDtoV1 =
JsonSerializer.DeserializeFromString<MessageDtoModelV1>(ComplexMessageJson);
+ }
+
+ [Test]
+ public void ToMessageBenchmark()
+ {
+ int runs = 50000;
+ DateTime start, stop;
+
+ start = DateTime.UtcNow;
+ MessageModel msg = null;
+ for (int i = 0; i < runs; i++) {
+ msg = SimpleMessageDtoV1.ToMessage();
+ }
+ stop = DateTime.UtcNow;
+ var total = (stop - start).TotalMilliseconds;
+ Console.WriteLine(
+ "SimpleMessageDtoV1.ToMessage(): avg: {0:0.00} ms runs: {1} took: {2:0.00} ms",
+ total / runs,
+ runs,
+ total
+ );
+
+ start = DateTime.UtcNow;
+ for (int i = 0; i < runs; i++) {
+ msg = ComplexMessageDtoV1.ToMessage();
+ }
+ stop = DateTime.UtcNow;
+ total = (stop - start).TotalMilliseconds;
+ Console.WriteLine(
+ "ComplexMessageDtoV1.ToMessage(): avg: {0:0.00} ms runs: {1} took: {2:0.00} ms",
+ total / runs,
+ runs,
+ total
+ );
+ }
+ }
+}
diff --git a/src/Engine/Messages/Dto/MessageDtoModelV1.cs b/src/Engine/Messages/Dto/MessageDtoModelV1.cs
new file mode 100644
index 0000000..aa6598d
--- /dev/null
+++ b/src/Engine/Messages/Dto/MessageDtoModelV1.cs
@@ -0,0 +1,96 @@
+// Smuxi - Smart MUltipleXed Irc
+//
+// Copyright (c) 2012 Mirco Bauer <meebey meebey net>
+//
+// Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+using System;
+using System.Collections.Generic;
+
+namespace Smuxi.Engine.Dto
+{
+ public class MessageDtoModelV1
+ {
+ public DateTime TimeStamp { get; set; }
+ public List<MessagePartDtoModelV1> MessageParts { get; set; }
+ public MessageType MessageType { get; set; }
+
+ public MessageModel ToMessage()
+ {
+ var msg = new MessageModel() {
+ MessageType = this.MessageType,
+ TimeStamp = this.TimeStamp
+ };
+ foreach (var msgPart in MessageParts) {
+ MessagePartModel part = null;
+ switch (msgPart.Type) {
+ case "Text":
+ var textPart = new TextMessagePartModel() {
+ ForegroundColor = msgPart.ForegroundColor,
+ BackgroundColor = msgPart.BackgroundColor,
+ Underline = msgPart.Underline,
+ Bold = msgPart.Bold,
+ Italic = msgPart.Italic,
+ Text = msgPart.Text
+ };
+ part = textPart;
+ break;
+ case "URL":
+ var urlPart = new UrlMessagePartModel() {
+ Url = msgPart.Url,
+ Protocol = msgPart.Protocol
+ };
+ part = urlPart;
+ break;
+ case "Image":
+ var imagePart = new ImageMessagePartModel() {
+ ImageFileName = msgPart.ImageFileName,
+ AlternativeText = msgPart.AlternativeText
+ };
+ part = imagePart;
+ break;
+ }
+ if (part == null) {
+ continue;
+ }
+ part.IsHighlight = msgPart.IsHighlight;
+ msg.MessageParts.Add(part);
+ }
+ return msg;
+ }
+ }
+
+ public class MessagePartDtoModelV1
+ {
+ // MessagePartModel
+ public string Type { get; set; }
+ public bool IsHighlight { get; set; }
+ // TextMessagePartModel
+ public TextColor ForegroundColor { get; set; }
+ public TextColor BackgroundColor { get; set; }
+ public bool Underline { get; set; }
+ public bool Bold { get; set; }
+ public bool Italic { get; set; }
+ public string Text { get; set; }
+ // UrlMessagePartModel
+ public string Url { get; set; }
+ public UrlProtocol Protocol { get; set; }
+ // ImageMessagePartModel
+ public string ImageFileName { get; set; }
+ public string AlternativeText { get; set; }
+ }
+}
+
diff --git a/src/Engine/Messages/ImageMessagePartModel.cs b/src/Engine/Messages/ImageMessagePartModel.cs
index d76796a..d6ea51a 100644
--- a/src/Engine/Messages/ImageMessagePartModel.cs
+++ b/src/Engine/Messages/ImageMessagePartModel.cs
@@ -70,6 +70,10 @@ namespace Smuxi.Engine
}
}
+ public ImageMessagePartModel()
+ {
+ }
+
public ImageMessagePartModel(string imageFileName, string alternativeText)
{
if (imageFileName == null) {
diff --git a/src/Engine/Messages/UrlMessagePartModel.cs b/src/Engine/Messages/UrlMessagePartModel.cs
index 0a787ee..207ae59 100644
--- a/src/Engine/Messages/UrlMessagePartModel.cs
+++ b/src/Engine/Messages/UrlMessagePartModel.cs
@@ -74,6 +74,10 @@ namespace Smuxi.Engine
_Url = value;
}
}
+
+ public UrlMessagePartModel()
+ {
+ }
public UrlMessagePartModel(string url) :
this(url, null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]