From 4afb3e436311b9c0e0426d8dd2ce3d831a22cdb0 Mon Sep 17 00:00:00 2001 From: Joe Hayes Date: Fri, 20 Feb 2015 00:27:34 -0500 Subject: [PATCH 1/4] update NUnit, Newtonsoft.Json and Should --- .nuget/packages.config | 2 +- .../MessagePackMediaTypeFormatter.cs | 2 +- .../WebApiContrib.Formatting.MsgPack.csproj | 5 +++-- .../packages.config | 2 +- .../WebApiContrib.Formatting.MsgPack.Tests.csproj | 15 +++++++++------ .../packages.config | 6 +++--- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.nuget/packages.config b/.nuget/packages.config index 83e69d4..7e62aa7 100644 --- a/.nuget/packages.config +++ b/.nuget/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs b/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs index 2e87da9..679773d 100644 --- a/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs +++ b/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs @@ -27,7 +27,7 @@ private static bool IsAllowedType(Type t) return true; return false; - }; + } public MessagePackMediaTypeFormatter() { diff --git a/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj b/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj index 1496968..9609e28 100644 --- a/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj +++ b/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj @@ -36,8 +36,9 @@ ..\..\packages\MsgPack.0.1.0.2011042300\lib\net40\MsgPack.dll - - ..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll diff --git a/src/WebApiContrib.Formatting.MsgPack/packages.config b/src/WebApiContrib.Formatting.MsgPack/packages.config index b2a2a35..1ae3876 100644 --- a/src/WebApiContrib.Formatting.MsgPack/packages.config +++ b/src/WebApiContrib.Formatting.MsgPack/packages.config @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj b/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj index d5edf38..643cdf1 100644 --- a/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj +++ b/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj @@ -33,14 +33,17 @@ 4 - - ..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll - - ..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + False + ..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - ..\..\packages\Should.1.1.12.0\lib\Should.dll + + False + ..\..\packages\Should.1.1.20\lib\Should.dll diff --git a/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config b/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config index 0f77b3e..0f9f599 100644 --- a/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config +++ b/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config @@ -2,7 +2,7 @@ - - - + + + \ No newline at end of file From 6fbbaeb0494e6f6ac9139bc33b8e0e4cd19660c1 Mon Sep 17 00:00:00 2001 From: Joe Hayes Date: Fri, 20 Feb 2015 00:47:45 -0500 Subject: [PATCH 2/4] Replace MsgPack with MsgPack.Cli --- .../MessagePackMediaTypeFormatter.cs | 11 +++++------ .../WebApiContrib.Formatting.MsgPack.csproj | 5 +++-- src/WebApiContrib.Formatting.MsgPack/packages.config | 2 +- .../MessagePackMediaTypeFormatterTests.cs | 5 ----- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs b/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs index 679773d..efd2e06 100644 --- a/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs +++ b/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Net.Http.Formatting; using System.Net.Http.Headers; -using MsgPack; +using MsgPack.Serialization; namespace WebApiContrib.Formatting.MsgPack { @@ -58,8 +58,8 @@ public override object ReadFromStream(Type type, System.IO.Stream readStream, Sy object result; try { - var packer = new CompiledPacker(packPrivateField: false); - result = packer.Unpack(type, readStream); + var packer = SerializationContext.Default.GetSerializer(type); + result = packer.Unpack(readStream); } catch (Exception ex) { @@ -84,9 +84,8 @@ public override void WriteToStream(Type type, object value, System.IO.Stream wri if (typeof(IEnumerable).IsAssignableFrom(type)) value = (value as IEnumerable).ToList(); - var packer = new CompiledPacker(packPrivateField: false); - byte[] buffer = packer.Pack(value); - writeStream.Write(buffer, 0, buffer.Length); + var packer = SerializationContext.Default.GetSerializer(type); + packer.Pack(writeStream, value); } } } diff --git a/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj b/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj index 9609e28..d1ea6dc 100644 --- a/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj +++ b/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj @@ -33,8 +33,9 @@ 4 - - ..\..\packages\MsgPack.0.1.0.2011042300\lib\net40\MsgPack.dll + + False + ..\..\packages\MsgPack.Cli.0.5.10\lib\net40-client\MsgPack.dll False diff --git a/src/WebApiContrib.Formatting.MsgPack/packages.config b/src/WebApiContrib.Formatting.MsgPack/packages.config index 1ae3876..06807f2 100644 --- a/src/WebApiContrib.Formatting.MsgPack/packages.config +++ b/src/WebApiContrib.Formatting.MsgPack/packages.config @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs b/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs index b9985bd..4e916c1 100644 --- a/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs +++ b/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs @@ -1,12 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; -using System.Text; -using System.Threading.Tasks; using NUnit.Framework; using Should; -using WebApiContrib.Formatting.MsgPack; namespace WebApiContrib.Formatting.MsgPack.Tests { From 91ae6053480f9acbce4147f5b8d7065430bcd7de Mon Sep 17 00:00:00 2001 From: Joe Hayes Date: Fri, 20 Feb 2015 00:58:25 -0500 Subject: [PATCH 3/4] update to WebApi 2.2 --- .../WebApiContrib.Formatting.MsgPack.csproj | 26 +++++++++---------- .../packages.config | 7 +++-- ...ApiContrib.Formatting.MsgPack.Tests.csproj | 23 ++++++++-------- .../packages.config | 9 +++---- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj b/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj index d1ea6dc..713e904 100644 --- a/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj +++ b/src/WebApiContrib.Formatting.MsgPack/WebApiContrib.Formatting.MsgPack.csproj @@ -1,5 +1,5 @@  - + Debug @@ -9,9 +9,10 @@ Properties WebApiContrib.Formatting.MsgPack WebApiContrib.Formatting.MsgPack - v4.0 + v4.5 512 - Client + + ..\..\ true @@ -23,6 +24,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -31,27 +33,25 @@ TRACE prompt 4 + false False - ..\..\packages\MsgPack.Cli.0.5.10\lib\net40-client\MsgPack.dll + ..\..\packages\MsgPack.Cli.0.5.10\lib\net45\MsgPack.dll False - ..\..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll - - - ..\..\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll - - - ..\..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll + + + False + ..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + diff --git a/src/WebApiContrib.Formatting.MsgPack/packages.config b/src/WebApiContrib.Formatting.MsgPack/packages.config index 06807f2..e907a2f 100644 --- a/src/WebApiContrib.Formatting.MsgPack/packages.config +++ b/src/WebApiContrib.Formatting.MsgPack/packages.config @@ -1,7 +1,6 @@  - - - - + + + \ No newline at end of file diff --git a/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj b/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj index 643cdf1..64b1083 100644 --- a/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj +++ b/test/WebApiContrib.Formatting.MsgPack.Tests/WebApiContrib.Formatting.MsgPack.Tests.csproj @@ -1,5 +1,5 @@  - + Debug @@ -9,9 +9,10 @@ Properties WebApiContrib.Formatting.MsgPack.Tests WebApiContrib.Formatting.MsgPack.Tests - v4.0 + v4.5 512 - Client + + ..\..\ true @@ -23,6 +24,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -31,11 +33,12 @@ TRACE prompt 4 + false False - ..\..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll False @@ -47,14 +50,10 @@ - - ..\..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll - - - ..\..\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll - - - ..\..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll + + + False + ..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll diff --git a/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config b/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config index 0f9f599..8981002 100644 --- a/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config +++ b/test/WebApiContrib.Formatting.MsgPack.Tests/packages.config @@ -1,8 +1,7 @@  - - - - - + + + + \ No newline at end of file From d1f669ea3f44294e90e9143fe7f71ab4db6bff32 Mon Sep 17 00:00:00 2001 From: Joe Hayes Date: Fri, 20 Feb 2015 01:24:24 -0500 Subject: [PATCH 4/4] bump version - switch base class of MessagePackMediaTypeFormatter to MediaTypeFormatter --- .../MessagePackMediaTypeFormatter.cs | 41 +++++++++++++------ .../Properties/AssemblyInfo.cs | 6 +-- .../MessagePackMediaTypeFormatterTests.cs | 4 +- .../Properties/AssemblyInfo.cs | 2 +- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs b/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs index efd2e06..c3b75f3 100644 --- a/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs +++ b/src/WebApiContrib.Formatting.MsgPack/MessagePackMediaTypeFormatter.cs @@ -1,9 +1,13 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Net; +using System.Net.Http; using System.Net.Http.Formatting; using System.Net.Http.Headers; +using System.Threading.Tasks; using MsgPack.Serialization; namespace WebApiContrib.Formatting.MsgPack @@ -14,7 +18,7 @@ namespace WebApiContrib.Formatting.MsgPack /// Converted from Filip W.'s MessagePackMediaTypeFormatter. /// /// - public class MessagePackMediaTypeFormatter : BufferedMediaTypeFormatter + public class MessagePackMediaTypeFormatter : MediaTypeFormatter { private const string mediaType = "application/x-msgpack"; @@ -37,7 +41,7 @@ public MessagePackMediaTypeFormatter() public override bool CanReadType(Type type) { if (type == null) - throw new ArgumentNullException("type is null"); + throw new ArgumentNullException("type"); return IsAllowedType(type); } @@ -45,12 +49,12 @@ public override bool CanReadType(Type type) public override bool CanWriteType(Type type) { if (type == null) - throw new ArgumentNullException("type is null"); + throw new ArgumentNullException("type"); return IsAllowedType(type); } - public override object ReadFromStream(Type type, System.IO.Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger) + public override Task ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger) { if (content.Headers != null && content.Headers.ContentLength == 0) return null; @@ -59,7 +63,7 @@ public override object ReadFromStream(Type type, System.IO.Stream readStream, Sy try { var packer = SerializationContext.Default.GetSerializer(type); - result = packer.Unpack(readStream); + result = packer.Unpack(stream); } catch (Exception ex) { @@ -70,22 +74,35 @@ public override object ReadFromStream(Type type, System.IO.Stream readStream, Sy result = GetDefaultValueForType(type); } - return result; + return Task.FromResult(result); } - public override void WriteToStream(Type type, object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content) + public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext) { if (type == null) - throw new ArgumentNullException("type is null"); + throw new ArgumentNullException("type"); - if (writeStream == null) - throw new ArgumentNullException("writeStream is null"); + if (stream == null) + throw new ArgumentNullException("stream"); if (typeof(IEnumerable).IsAssignableFrom(type)) value = (value as IEnumerable).ToList(); - var packer = SerializationContext.Default.GetSerializer(type); - packer.Pack(writeStream, value); + var tcs = new TaskCompletionSource(); + + try + { + var packer = SerializationContext.Default.GetSerializer(type); + packer.Pack(stream, value); + + tcs.SetResult(null); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + + return tcs.Task; } } } diff --git a/src/WebApiContrib.Formatting.MsgPack/Properties/AssemblyInfo.cs b/src/WebApiContrib.Formatting.MsgPack/Properties/AssemblyInfo.cs index c6ec817..516f1a5 100644 --- a/src/WebApiContrib.Formatting.MsgPack/Properties/AssemblyInfo.cs +++ b/src/WebApiContrib.Formatting.MsgPack/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("WebApiContrib.Formatting.MsgPack")] -[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.9.2")] -[assembly: AssemblyFileVersion("0.9.2")] +[assembly: AssemblyVersion("0.9.3")] +[assembly: AssemblyFileVersion("0.9.3")] diff --git a/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs b/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs index 4e916c1..f5af55f 100644 --- a/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs +++ b/test/WebApiContrib.Formatting.MsgPack.Tests/MessagePackMediaTypeFormatterTests.cs @@ -60,9 +60,9 @@ public static void Test_Content_Has_Correct_MediaType() } [Test] - public static void Test_Content_Should_Be_Readable_As_Url() + public static async void Test_Content_Should_Be_Readable_As_Url() { - var url = content.ReadAsAsync(new[] { formatter }).Result; + var url = await content.ReadAsAsync(new[] { formatter }); url.ShouldBeSameAs(data); } } diff --git a/test/WebApiContrib.Formatting.MsgPack.Tests/Properties/AssemblyInfo.cs b/test/WebApiContrib.Formatting.MsgPack.Tests/Properties/AssemblyInfo.cs index 9843ec3..da8758b 100644 --- a/test/WebApiContrib.Formatting.MsgPack.Tests/Properties/AssemblyInfo.cs +++ b/test/WebApiContrib.Formatting.MsgPack.Tests/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("WebApiContrib.Formatting.MsgPack.Tests")] -[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]