Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:/EventStore/EventStore into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras Roshko committed Nov 14, 2012
2 parents ddb1849 + 2dc1b63 commit 206b63d
Show file tree
Hide file tree
Showing 30 changed files with 411 additions and 421 deletions.
Expand Up @@ -5,6 +5,7 @@
using EventStore.Core.Messages;
using EventStore.Core.Services.Storage.ReaderIndex;
using EventStore.Core.Services.Transport.Http;
using EventStore.Core.Services.Transport.Http.Codecs;
using EventStore.Core.TransactionLog.LogRecords;
using NUnit.Framework;
using System.Linq;
Expand Down Expand Up @@ -52,14 +53,14 @@ private static string XmlReadFormat
}
}

public static byte[] GetJsonWrite(string data, string metadata)
public static string GetJsonWrite(string data, string metadata)
{
return Encoding.UTF8.GetBytes(string.Format(JsonWriteFormat,
"-1",
String.Format("\"{0}\"", Guid.NewGuid()),
"\"type\"",
data,
metadata));
return string.Format(JsonWriteFormat,
"-1",
String.Format("\"{0}\"", Guid.NewGuid()),
"\"type\"",
data,
metadata);
}

public static string GetJsonReadResult(ClientMessage.ReadEventCompleted completed, bool dataJson = true, bool metadataJson = true)
Expand All @@ -72,14 +73,9 @@ public static string GetJsonReadResult(ClientMessage.ReadEventCompleted complete
metadataJson ? JsonMetadata : WrapIntoQuotes(AsString(completed.Record.Metadata)));
}

public static byte[] GetXmlWrite(string data, string metadata, bool withBom = true)
public static string GetXmlWrite(string data, string metadata)
{
IEnumerable<byte> result = Enumerable.Empty<byte>();
if (withBom)
result = result.Concat(Encoding.UTF8.GetPreamble());
result = result.Concat(Encoding.UTF8.GetBytes(
string.Format(XmlWriteFormat, "-1", Guid.NewGuid(), "type", data, metadata)));
return result.ToArray();
return string.Format(XmlWriteFormat, "-1", Guid.NewGuid(), "type", data, metadata);
}

public static string GetXmlReadResult(ClientMessage.ReadEventCompleted completed, bool dataJson = true, bool metadataJson = true)
Expand Down
Expand Up @@ -31,6 +31,7 @@
using EventStore.Common.Utils;
using EventStore.Core.Messages;
using EventStore.Core.Services.Transport.Http;
using EventStore.Core.Services.Transport.Http.Codecs;
using EventStore.Transport.Http;
using NUnit.Framework;

Expand Down
8 changes: 7 additions & 1 deletion src/EventStore/EventStore.Core/EventStore.Core.csproj
Expand Up @@ -144,6 +144,12 @@
<Compile Include="Services\Storage\StorageScavenger.cs" />
<Compile Include="Services\SystemNames.cs" />
<Compile Include="Services\RequestManager\Managers\TransactionCommitTwoPhaseRequestManager.cs" />
<Compile Include="Services\Transport\Http\Codecs\CustomCodec.cs" />
<Compile Include="Services\Transport\Http\Codecs\JsonCodec.cs" />
<Compile Include="Services\Transport\Http\Codecs\ManualEncoding.cs" />
<Compile Include="Services\Transport\Http\Codecs\NoCodec.cs" />
<Compile Include="Services\Transport\Http\Codecs\TextCodec.cs" />
<Compile Include="Services\Transport\Http\Codecs\XmlCodec.cs" />
<Compile Include="Services\Transport\Http\Controllers\WebSiteController.cs" />
<Compile Include="Services\RequestManager\Managers\TwoPhaseRequestManagerBase.cs" />
<Compile Include="Services\RequestManager\Managers\WriteStreamTwoPhaseRequestManager.cs" />
Expand Down Expand Up @@ -209,7 +215,7 @@
<Compile Include="Services\Storage\ReaderIndex\ReadIndexStats.cs" />
<Compile Include="Services\Storage\StorageChaser.cs" />
<Compile Include="Services\Storage\StorageReader.cs" />
<Compile Include="Services\Transport\Http\Codecs.cs" />
<Compile Include="Services\Transport\Http\Codecs\Codec.cs" />
<Compile Include="Services\Transport\Http\ControllerAction.cs" />
<Compile Include="Services\Transport\Http\Controllers\AdminController.cs" />
<Compile Include="Services\Transport\Http\Controllers\CommunicationController.cs" />
Expand Down
Expand Up @@ -34,6 +34,7 @@
using EventStore.Common.Log;
using EventStore.Core.Data;
using EventStore.Core.Messages;
using EventStore.Core.Services.Transport.Http.Codecs;
using EventStore.Core.TransactionLog.LogRecords;
using EventStore.Transport.Http;
using Newtonsoft.Json;
Expand Down Expand Up @@ -77,7 +78,7 @@ public static string SmartFormat(ClientMessage.ReadEventCompleted completed, ICo
}
}

public static Tuple<int, Event[]> SmartParse(byte[] request, ICodec sourceCodec)
public static Tuple<int, Event[]> SmartParse(string request, ICodec sourceCodec)
{
var write = Load(request, sourceCodec);
if (write == null || write.Events == null || write.Events.Length == 0)
Expand All @@ -87,7 +88,7 @@ public static string SmartFormat(ClientMessage.ReadEventCompleted completed, ICo
return new Tuple<int, Event[]>(write.ExpectedVersion, events);
}

private static HttpClientMessageDto.WriteEventsDynamic Load(byte[] data, ICodec sourceCodec)
private static HttpClientMessageDto.WriteEventsDynamic Load(string data, ICodec sourceCodec)
{
switch(sourceCodec.ContentType)
{
Expand All @@ -105,21 +106,16 @@ private static HttpClientMessageDto.WriteEventsDynamic Load(byte[] data, ICodec
}
}

private static HttpClientMessageDto.WriteEventsDynamic LoadFromJson(byte[] json)
private static HttpClientMessageDto.WriteEventsDynamic LoadFromJson(string json)
{
return Codec.Json.From<HttpClientMessageDto.WriteEventsDynamic>(Encoding.UTF8.GetString(json));
return Codec.Json.From<HttpClientMessageDto.WriteEventsDynamic>(json);
}

private static HttpClientMessageDto.WriteEventsDynamic LoadFromXml(byte[] xml)
private static HttpClientMessageDto.WriteEventsDynamic LoadFromXml(string xml)
{
try
{
XDocument doc;
using (var memStream = new MemoryStream(xml))
using (var xmlTextReader = new XmlTextReader(memStream))
{
doc = XDocument.Load(xmlTextReader);
}
XDocument doc = XDocument.Parse(xml);

XNamespace jsonNsValue = "http://james.newtonking.com/projects/json";
XName jsonNsName = XNamespace.Xmlns + "json";
Expand Down

0 comments on commit 206b63d

Please sign in to comment.