Skip to content

Commit

Permalink
More serialization changes.
Browse files Browse the repository at this point in the history
Switch command converter to wire serialization.
  • Loading branch information
zapov committed Oct 15, 2014
1 parent bf2284b commit a83336d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
3 changes: 1 addition & 2 deletions Code/Server/Revenj.Core/AutofacConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Autofac;
using Autofac.Builder;
Expand Down Expand Up @@ -158,7 +157,7 @@ private static void SetupSerialization(Autofac.ContainerBuilder builder)
builder.RegisterType<XmlSerialization>().As<ISerialization<XElement>>().SingleInstance();
builder.RegisterType<GenericDeserializationBinder>().SingleInstance();
builder.RegisterType<BinarySerialization>().As<ISerialization<byte[]>>().SingleInstance();
builder.RegisterType<JsonSerialization>().As<ISerialization<string>, ISerialization<StringBuilder>, ISerialization<StreamReader>>().SingleInstance();
builder.RegisterType<JsonSerialization>().As<ISerialization<string>, ISerialization<TextReader>>().SingleInstance();
builder.RegisterType<ProtobufSerialization>().As<ISerialization<MemoryStream>, ISerialization<Stream>>().SingleInstance();
builder.RegisterType<PassThroughSerialization>().As<ISerialization<object>>().SingleInstance();
builder.RegisterType<WireSerialization>().As<IWireSerialization>().SingleInstance();
Expand Down
26 changes: 2 additions & 24 deletions Code/Server/Revenj.Wcf/Rest/CommandConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Globalization;
using System.IO;
using System.Net;
using System.Xml.Linq;
using Revenj.Api;
using Revenj.Extensibility;
using Revenj.Processing;
Expand All @@ -19,34 +18,22 @@ public class CommandConverter : ICommandConverter
private readonly IObjectFactory ObjectFactory;
private readonly IProcessingEngine ProcessingEngine;
private readonly IWireSerialization Serialization;
private readonly ISerialization<Stream> Protobuf;
private readonly ISerialization<XElement> Xml;
private readonly ISerialization<StreamReader> Json;

public CommandConverter(
IRestApplication application,
IObjectFactory objectFactory,
IProcessingEngine processingEngine,
IWireSerialization serialization,
ISerialization<Stream> protobuf,
ISerialization<XElement> xml,
ISerialization<StreamReader> json)
IWireSerialization serialization)
{
Contract.Requires(application != null);
Contract.Requires(objectFactory != null);
Contract.Requires(processingEngine != null);
Contract.Requires(serialization != null);
Contract.Requires(protobuf != null);
Contract.Requires(xml != null);
Contract.Requires(json != null);

this.Application = application;
this.ObjectFactory = objectFactory;
this.ProcessingEngine = processingEngine;
this.Serialization = serialization;
this.Protobuf = protobuf;
this.Xml = xml;
this.Json = json;
}

public Stream PassThrough<TCommand, TArgument>(TArgument argument, string accept)
Expand Down Expand Up @@ -79,18 +66,9 @@ public Stream ConvertStream<TCommand, TArgument>(TArgument argument)
ThreadContext.Request.UriTemplateMatch = match;
if (argument == null)
return Application.Get();
switch (ThreadContext.Request.ContentType)
{
case "application/x-protobuf":
return Application.Post(Protobuf.Serialize(argument));
case "application/json":
return Application.Post(Json.Serialize(argument).BaseStream);
}
using (var ms = ChunkedMemoryStream.Create())
{
var sw = ms.GetWriter();
sw.Write(Xml.Serialize(argument));
sw.Flush();
Serialization.Serialize(argument, ThreadContext.Request.ContentType, ms);
ms.Position = 0;
return Application.Post(ms);
}
Expand Down
3 changes: 1 addition & 2 deletions Code/Server/Revenj.Wcf/StandardModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Reflection;
using System.Security;
using System.ServiceModel;
using System.Text;
using System.Xml.Linq;
using Autofac;
using Autofac.Builder;
Expand Down Expand Up @@ -205,7 +204,7 @@ private static void SetupSerialization(Autofac.ContainerBuilder builder)
builder.RegisterType<XmlSerialization>().As<ISerialization<XElement>>().SingleInstance();
builder.RegisterType<GenericDeserializationBinder>().SingleInstance();
builder.RegisterType<BinarySerialization>().As<ISerialization<byte[]>>().SingleInstance();
builder.RegisterType<JsonSerialization>().As<ISerialization<string>, ISerialization<StringBuilder>, ISerialization<StreamReader>>().SingleInstance();
builder.RegisterType<JsonSerialization>().As<ISerialization<string>, ISerialization<TextReader>>().SingleInstance();
builder.RegisterType<ProtobufSerialization>().As<ISerialization<MemoryStream>, ISerialization<Stream>>().SingleInstance();
builder.RegisterType<PassThroughSerialization>().As<ISerialization<object>>().SingleInstance();
builder.RegisterType<WireSerialization>().As<IWireSerialization>().SingleInstance();
Expand Down

0 comments on commit a83336d

Please sign in to comment.