[smuxi/experiments/sqlite: 9/27] [Engine] Implemented GitMessageBuffer get indexer
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi/experiments/sqlite: 9/27] [Engine] Implemented GitMessageBuffer get indexer
- Date: Sun, 23 Feb 2014 17:07:08 +0000 (UTC)
commit c72501d64642f6ecd4753830c1e0782a8d55e97b
Author: Mirco Bauer <meebey meebey net>
Date: Sun Feb 26 11:55:22 2012 +0100
[Engine] Implemented GitMessageBuffer get indexer
src/Engine/MessageBuffers/GitMessageBuffer.cs | 30 ++++++++++++++++++++++--
1 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/src/Engine/MessageBuffers/GitMessageBuffer.cs b/src/Engine/MessageBuffers/GitMessageBuffer.cs
index 82c0cef..547208f 100644
--- a/src/Engine/MessageBuffers/GitMessageBuffer.cs
+++ b/src/Engine/MessageBuffers/GitMessageBuffer.cs
@@ -20,10 +20,13 @@
using System;
using System.IO;
using System.Text;
+using System.Linq;
using System.Threading;
+using System.Collections.Generic;
using ServiceStack.Text;
using LibGit2Sharp;
using Smuxi.Common;
+using Smuxi.Engine.Dto;
namespace Smuxi.Engine
{
@@ -98,7 +101,7 @@ namespace Smuxi.Engine
}
*/
- var msgFileName = String.Format("{0}.v1.json", ++MessageNumber);
+ var msgFileName = String.Format("{0}.v1.json", MessageNumber++);
var msgFilePath = Path.Combine(RepositoryPath, msgFileName);
using (var writer = File.OpenWrite(msgFilePath))
using (var textWriter = new StreamWriter(writer, Encoding.UTF8)) {
@@ -134,11 +137,32 @@ namespace Smuxi.Engine
public override MessageModel this[int index] {
get {
- throw new NotImplementedException ();
+ if (index < 0) {
+ throw new IndexOutOfRangeException();
+ }
+ var fileName = String.Format("{0}.v1.json", index);
+ var entry = Repository.Index[fileName];
+ if (entry == null) {
+ throw new IndexOutOfRangeException();
+ }
+ return GetMessage(entry.Id);
}
set {
- throw new NotImplementedException ();
+ throw new NotImplementedException();
+ }
+ }
+
+ MessageModel GetMessage(ObjectId id)
+ {
+ if (id == null) {
+ throw new ArgumentNullException("id");
+ }
+ var blob = Repository.Lookup<Blob>(id);
+ if (blob == null) {
+ throw new ArgumentOutOfRangeException("id", id, "ObjectId not found");
}
+ var dto = JsonSerializer.DeserializeFromStream<MessageDtoModelV1>(blob.ContentStream);
+ return dto.ToMessage();
}
public override void Clear ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]