Permalink
Browse files

removed dead code, changed httpprocessors to use xml, changed autoeve…

…ntconverter to use separate types for smart parsing, made clienteventtext to always use strings
  • Loading branch information...
1 parent 2789f95 commit ab0c0ed3995be1317d52ea3f286c3232aab7b9d2 @PropertyOfTuckerSystems PropertyOfTuckerSystems committed Nov 13, 2012
@@ -38,20 +38,45 @@ public static class HttpClientMessageDto
{
#region HTTP DTO
- [XmlType(TypeName = "event")]
- public class ClientEventText
+ public class ClientEventDynamic
{
public Guid EventId { get; set; }
public string EventType { get; set; }
public object Data { get; set; }
public object Metadata { get; set; }
+ }
+
+ public class WriteEventsDynamic
+ {
+ public int ExpectedVersion { get; set; }
+ public ClientEventDynamic[] Events { get; set; }
+
+ public WriteEventsDynamic()
+ {
+ }
+
+ public WriteEventsDynamic(int expectedVersion, ClientEventDynamic[] events)
+ {
+ ExpectedVersion = expectedVersion;
+ Events = events;
+ }
+ }
+
+ [XmlType(TypeName = "event")]
+ public class ClientEventText
+ {
+ public Guid EventId { get; set; }
+ public string EventType { get; set; }
+
+ public string Data { get; set; }
+ public string Metadata { get; set; }
public ClientEventText()
{
}
- public ClientEventText(Guid eventId, string eventType, object data, object metadata)
+ public ClientEventText(Guid eventId, string eventType, string data, string metadata)
{
Ensure.NotEmptyGuid(eventId, "eventId");
Ensure.NotNull(data, "data");
@@ -80,7 +80,7 @@ public static string SmartFormat(ClientMessage.ReadEventCompleted completed, ICo
return targetCodec.To(dto);
}
- private static HttpClientMessageDto.WriteEventsText Load(string s, ICodec sourceCodec)
+ private static HttpClientMessageDto.WriteEventsDynamic Load(string s, ICodec sourceCodec)
{
var requestType = sourceCodec.ContentType;
@@ -92,12 +92,12 @@ private static HttpClientMessageDto.WriteEventsText Load(string s, ICodec source
return null;
}
- private static HttpClientMessageDto.WriteEventsText LoadFromJson(string json)
+ private static HttpClientMessageDto.WriteEventsDynamic LoadFromJson(string json)
{
- return Codec.Json.From<HttpClientMessageDto.WriteEventsText>(json);
+ return Codec.Json.From<HttpClientMessageDto.WriteEventsDynamic>(json);
}
- private static HttpClientMessageDto.WriteEventsText LoadFromXml(string xml)
+ private static HttpClientMessageDto.WriteEventsDynamic LoadFromXml(string xml)
{
try
{
@@ -123,8 +123,8 @@ private static HttpClientMessageDto.WriteEventsText LoadFromXml(string xml)
element.RemoveAttributes();
var json = JsonConvert.SerializeXNode(doc, Formatting.None, false);
- var textEvents = JsonConvert.DeserializeObject<JObject>(json)["write-events"]["Events"].ToObject<HttpClientMessageDto.ClientEventText[]>();
- return new HttpClientMessageDto.WriteEventsText(int.Parse(expectedVersion.Value), textEvents.ToArray());
+ var dynamicEvents = JsonConvert.DeserializeObject<JObject>(json)["write-events"]["Events"].ToObject<HttpClientMessageDto.ClientEventDynamic[]>();
+ return new HttpClientMessageDto.WriteEventsDynamic(int.Parse(expectedVersion.Value), dynamicEvents.ToArray());
}
catch (Exception e)
{
@@ -133,10 +133,10 @@ private static HttpClientMessageDto.WriteEventsText LoadFromXml(string xml)
}
}
- private static Event[] Parse(HttpClientMessageDto.ClientEventText[] textEvents)
+ private static Event[] Parse(HttpClientMessageDto.ClientEventDynamic[] dynamicEvents)
{
- var events = new List<Event>(textEvents.Length);
- foreach (var textEvent in textEvents)
+ var events = new List<Event>(dynamicEvents.Length);
+ foreach (var textEvent in dynamicEvents)
{
bool dataIsJson;
bool metadataIsJson;
@@ -31,7 +31,6 @@
using EventStore.Core.Messages;
using EventStore.Core.Messaging;
using EventStore.Core.Services.Storage.ReaderIndex;
-using EventStore.Transport.Http;
using EventStore.Transport.Http.EntityManagement;
namespace EventStore.Core.Services.Transport.Http
@@ -146,22 +145,6 @@ public static string TextMessage(HttpEntity entity, Message message)
return textMessage != null ? entity.ResponseCodec.To(textMessage) : string.Empty;
}
- public static string WriteEvents(ICodec codec, Message message)
- {
- Debug.Assert(message.GetType() == typeof (ClientMessage.WriteEvents));
-
- var writeEvents = message as ClientMessage.WriteEvents;
- if (writeEvents == null)
- return string.Empty;
-
- return codec.To(new HttpClientMessageDto.WriteEventsText(
- writeEvents.ExpectedVersion,
- writeEvents.Events.Select(e => new HttpClientMessageDto.ClientEventText(e.EventId,
- e.EventType,
- e.Data,
- e.Metadata)).ToArray()));
- }
-
public static string WriteEventsCompleted(HttpEntity entity, Message message)
{
Debug.Assert(message.GetType() == typeof(ClientMessage.WriteEventsCompleted));
@@ -128,8 +128,8 @@ private void WriteFlood(CommandProcessorContext context, string eventStreamId, i
"DATA" + new string('*', 256),
"METADATA" + new string('$', 100))
});
- var requestString = Codec.Json.To(write);
- client.Post(url, requestString, Codec.Json.ContentType, succHandler, exc =>
+ var requestString = Codec.Xml.To(write);
+ client.Post(url, requestString, Codec.Xml.ContentType, succHandler, exc =>
{
context.Log.ErrorException(exc, "Error during POST.");
Interlocked.Increment(ref fail);
@@ -124,10 +124,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, int req
"DATA" + new string('*', 256),
"METADATA" + new string('$', 100))
});
- var request = Codec.Json.To(write);
+ var request = Codec.Xml.To(write);
client.Post(url,
request,
- Codec.Json.ContentType,
+ Codec.Xml.ContentType,
succHandler,
exc =>
{
@@ -65,15 +65,15 @@ public bool Execute(CommandProcessorContext context, string[] args)
var url = context.Client.HttpEndpoint.ToHttpUrl("/streams/{0}", eventStreamId);
context.Log.Info("Writing to {0}...", url);
- var request = Codec.Json.To(new HttpClientMessageDto.WriteEventsText(
+ var request = Codec.Xml.To(new HttpClientMessageDto.WriteEventsText(
expectedVersion,
new[] { new HttpClientMessageDto.ClientEventText(Guid.NewGuid(), "type", data, metadata) }));
var sw = Stopwatch.StartNew();
client.Post(
url,
request,
- Codec.Json.ContentType,
+ Codec.Xml.ContentType,
response =>
{
sw.Stop();
@@ -192,10 +192,10 @@ public bool Execute(CommandProcessorContext context, string[] args)
"DATA" + dataResultingSize.ToString(" 00000 ") + new string('*', dataResultingSize),
"METADATA" + new string('$', 100))
});
- var request = Codec.Json.To(write);
+ var request = Codec.Xml.To(write);
client.Post(url,
request,
- Codec.Json.ContentType,
+ Codec.Xml.ContentType,
succHandler,
exc =>
{

0 comments on commit ab0c0ed

Please sign in to comment.