From b90f71200cb60786ab394da3e40b284d0841b989 Mon Sep 17 00:00:00 2001 From: Ziya SARIKAYA Date: Fri, 13 Feb 2015 10:44:19 +0200 Subject: [PATCH] Add serialization integration projects --- .../FireSharp.Serialization.JsonNet.csproj | 70 +++++++++++++++++++ .../FireSharp.Serialization.JsonNet.nuspec | 24 +++++++ .../JsonSerializerWrapper.cs | 18 +++++ .../Properties/AssemblyInfo.cs | 39 +++++++++++ .../packages.config | 6 ++ ...ireSharp.Serialization.ServiceStack.csproj | 70 +++++++++++++++++++ ...ireSharp.Serialization.ServiceStack.nuspec | 24 +++++++ .../Properties/AssemblyInfo.cs | 39 +++++++++++ .../ServiceStackJsonSerializer.cs | 22 ++++++ .../packages.config | 5 ++ FireSharp.Test.Console/App.config | 9 +++ FireSharp.sln | 12 ++++ FireSharp/Config/FirebaseConfig.cs | 7 +- FireSharp/Config/IFirebaseConfig.cs | 5 +- FireSharp/EventStreaming/TODO.md | 53 -------------- FireSharp/Extensions/ObjectExtensions.cs | 15 +++- FireSharp/FireSharp.csproj | 11 ++- FireSharp/Interfaces/ISerializer.cs | 8 +++ FireSharp/Interfaces/JsonSerializerWrapper.cs | 17 +++++ FireSharp/RequestManager.cs | 3 +- FireSharp/content/web.config.transform | 8 --- FireSharp/packages.config | 15 ++-- 22 files changed, 396 insertions(+), 84 deletions(-) create mode 100644 FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.csproj create mode 100644 FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.nuspec create mode 100644 FireSharp.Serialization.JsonNet/JsonSerializerWrapper.cs create mode 100644 FireSharp.Serialization.JsonNet/Properties/AssemblyInfo.cs create mode 100644 FireSharp.Serialization.JsonNet/packages.config create mode 100644 FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.csproj create mode 100644 FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.nuspec create mode 100644 FireSharp.Serialization.ServiceStack/Properties/AssemblyInfo.cs create mode 100644 FireSharp.Serialization.ServiceStack/ServiceStackJsonSerializer.cs create mode 100644 FireSharp.Serialization.ServiceStack/packages.config delete mode 100644 FireSharp/EventStreaming/TODO.md create mode 100644 FireSharp/Interfaces/ISerializer.cs create mode 100644 FireSharp/Interfaces/JsonSerializerWrapper.cs delete mode 100644 FireSharp/content/web.config.transform diff --git a/FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.csproj b/FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.csproj new file mode 100644 index 0000000..c0a5a19 --- /dev/null +++ b/FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.csproj @@ -0,0 +1,70 @@ + + + + + Debug + AnyCPU + {A5F20EAF-9E8E-4CED-90F3-F19869570B7C} + Library + Properties + FireSharp.Serialization.JsonNet + FireSharp.Serialization.JsonNet + v4.5 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + {67B7EA6F-DC34-4F48-8331-58DF137D78C9} + FireSharp + + + + + + \ No newline at end of file diff --git a/FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.nuspec b/FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.nuspec new file mode 100644 index 0000000..395e418 --- /dev/null +++ b/FireSharp.Serialization.JsonNet/FireSharp.Serialization.JsonNet.nuspec @@ -0,0 +1,24 @@ + + + + FireSharp.Serialization.JsonNet + 2.0.0-beta2 + Fire# Serialization JsonNet + ziyasal + ziyasal + https://github.com/ziyasal/FireSharp/blob/master/LICENSE.md + https://github.com/ziyasal/FireSharp + false + Provides JSON serialization support using Newtonsoft.JsonNet. + en-US + firebase rest api client realtime newtonsoft jsonnet json + + + + + + + + + + \ No newline at end of file diff --git a/FireSharp.Serialization.JsonNet/JsonSerializerWrapper.cs b/FireSharp.Serialization.JsonNet/JsonSerializerWrapper.cs new file mode 100644 index 0000000..f48048b --- /dev/null +++ b/FireSharp.Serialization.JsonNet/JsonSerializerWrapper.cs @@ -0,0 +1,18 @@ +using FireSharp.Interfaces; +using Newtonsoft.Json; + +namespace FireSharp.Serialization.JsonNet +{ + internal class JsonSerializerWrapper : ISerializer + { + public T Deserialize(string json) + { + return JsonConvert.DeserializeObject(json); + } + + public string Serialize(T value) + { + return JsonConvert.SerializeObject(value); + } + } +} \ No newline at end of file diff --git a/FireSharp.Serialization.JsonNet/Properties/AssemblyInfo.cs b/FireSharp.Serialization.JsonNet/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..767ef2d --- /dev/null +++ b/FireSharp.Serialization.JsonNet/Properties/AssemblyInfo.cs @@ -0,0 +1,39 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("FireSharp.Serialization.JsonNet")] +[assembly: AssemblyDescription("Provides JSON serialization support using Newtonsoft.JsonNet.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FireSharp.Serialization.JsonNet")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("2eda7645-3da5-4131-971f-b2861facd164")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] + +[assembly: AssemblyVersion("1.1.0")] +[assembly: AssemblyFileVersion("1.1.0")] \ No newline at end of file diff --git a/FireSharp.Serialization.JsonNet/packages.config b/FireSharp.Serialization.JsonNet/packages.config new file mode 100644 index 0000000..a8f3b82 --- /dev/null +++ b/FireSharp.Serialization.JsonNet/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.csproj b/FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.csproj new file mode 100644 index 0000000..2ffd246 --- /dev/null +++ b/FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.csproj @@ -0,0 +1,70 @@ + + + + + Debug + AnyCPU + {7B0E3BC1-4C1D-4748-B678-3197E8E194FC} + Library + Properties + FireSharp.Serialization.ServiceStack + FireSharp.Serialization.ServiceStack + v4.5 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\ServiceStack.Text.4.0.18\lib\net40\ServiceStack.Text.dll + True + + + + + + + + + + + + + + + + + + + + {67B7EA6F-DC34-4F48-8331-58DF137D78C9} + FireSharp + + + + + + \ No newline at end of file diff --git a/FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.nuspec b/FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.nuspec new file mode 100644 index 0000000..c9bb204 --- /dev/null +++ b/FireSharp.Serialization.ServiceStack/FireSharp.Serialization.ServiceStack.nuspec @@ -0,0 +1,24 @@ + + + + FireSharp.Serialization.ServiceStack + 2.0.0-beta2 + Fire# Serialization ServiceStack + ziyasal + ziyasal + https://github.com/ziyasal/FireSharp/blob/master/LICENSE.md + https://github.com/ziyasal/FireSharp + false + Provides JSON serialization support using ServiceStack.Text. + en-US + firebase rest api client realtime servicestack json + + + + + + + + + + \ No newline at end of file diff --git a/FireSharp.Serialization.ServiceStack/Properties/AssemblyInfo.cs b/FireSharp.Serialization.ServiceStack/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..94584ed --- /dev/null +++ b/FireSharp.Serialization.ServiceStack/Properties/AssemblyInfo.cs @@ -0,0 +1,39 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("FireSharp.Serialization.ServiceStack")] +[assembly: AssemblyDescription("Provides JSON serialization support using ServiceStack.Text.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FireSharp.Serialization.ServiceStack")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("58917e1e-bd52-4983-9569-490eda166ac6")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] + +[assembly: AssemblyVersion("1.1.0")] +[assembly: AssemblyFileVersion("1.1.0")] \ No newline at end of file diff --git a/FireSharp.Serialization.ServiceStack/ServiceStackJsonSerializer.cs b/FireSharp.Serialization.ServiceStack/ServiceStackJsonSerializer.cs new file mode 100644 index 0000000..d700dae --- /dev/null +++ b/FireSharp.Serialization.ServiceStack/ServiceStackJsonSerializer.cs @@ -0,0 +1,22 @@ +using FireSharp.Interfaces; +using ServiceStack.Text; + +namespace FireSharp.Serialization.ServiceStack +{ + /// + /// ServiceSatck JSON serializer for request bodies + /// ServiceStack.Text supports DataContract,DataMember attributes + /// + public class ServiceStackJsonSerializer : ISerializer + { + public T Deserialize(string json) + { + return JsonSerializer.DeserializeFromString(json); + } + + public string Serialize(T value) + { + return JsonSerializer.SerializeToString(value); + } + } +} \ No newline at end of file diff --git a/FireSharp.Serialization.ServiceStack/packages.config b/FireSharp.Serialization.ServiceStack/packages.config new file mode 100644 index 0000000..97d4b26 --- /dev/null +++ b/FireSharp.Serialization.ServiceStack/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/FireSharp.Test.Console/App.config b/FireSharp.Test.Console/App.config index c774a25..1c9ebec 100644 --- a/FireSharp.Test.Console/App.config +++ b/FireSharp.Test.Console/App.config @@ -4,4 +4,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/FireSharp.sln b/FireSharp.sln index e63b412..dafb21b 100644 --- a/FireSharp.sln +++ b/FireSharp.sln @@ -18,6 +18,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FireSharp", "FireSharp\Fire EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FireSharp.Test.Console", "FireSharp.Test.Console\FireSharp.Test.Console.csproj", "{0DF0042E-769D-409B-A9F7-19449FD0AFD0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FireSharp.Serialization.JsonNet", "FireSharp.Serialization.JsonNet\FireSharp.Serialization.JsonNet.csproj", "{A5F20EAF-9E8E-4CED-90F3-F19869570B7C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FireSharp.Serialization.ServiceStack", "FireSharp.Serialization.ServiceStack\FireSharp.Serialization.ServiceStack.csproj", "{7B0E3BC1-4C1D-4748-B678-3197E8E194FC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -40,6 +44,14 @@ Global {0DF0042E-769D-409B-A9F7-19449FD0AFD0}.Debug|Any CPU.Build.0 = Debug|Any CPU {0DF0042E-769D-409B-A9F7-19449FD0AFD0}.Release|Any CPU.ActiveCfg = Release|Any CPU {0DF0042E-769D-409B-A9F7-19449FD0AFD0}.Release|Any CPU.Build.0 = Release|Any CPU + {A5F20EAF-9E8E-4CED-90F3-F19869570B7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5F20EAF-9E8E-4CED-90F3-F19869570B7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5F20EAF-9E8E-4CED-90F3-F19869570B7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5F20EAF-9E8E-4CED-90F3-F19869570B7C}.Release|Any CPU.Build.0 = Release|Any CPU + {7B0E3BC1-4C1D-4748-B678-3197E8E194FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B0E3BC1-4C1D-4748-B678-3197E8E194FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B0E3BC1-4C1D-4748-B678-3197E8E194FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B0E3BC1-4C1D-4748-B678-3197E8E194FC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FireSharp/Config/FirebaseConfig.cs b/FireSharp/Config/FirebaseConfig.cs index 08fcdc5..2d9511d 100644 --- a/FireSharp/Config/FirebaseConfig.cs +++ b/FireSharp/Config/FirebaseConfig.cs @@ -1,14 +1,19 @@ -namespace FireSharp.Config +using FireSharp.Interfaces; + +namespace FireSharp.Config { public class FirebaseConfig : IFirebaseConfig { public FirebaseConfig() { TimeoutInMinute = 1; + Serializer = new JsonSerializerWrapper(); } public string BasePath { get; set; } public string AuthSecret { get; set; } public int TimeoutInMinute { get; set; } + + public ISerializer Serializer { get; set; } } } diff --git a/FireSharp/Config/IFirebaseConfig.cs b/FireSharp/Config/IFirebaseConfig.cs index 6ee9127..37d1ac7 100644 --- a/FireSharp/Config/IFirebaseConfig.cs +++ b/FireSharp/Config/IFirebaseConfig.cs @@ -1,9 +1,12 @@ -namespace FireSharp.Config +using FireSharp.Interfaces; + +namespace FireSharp.Config { public interface IFirebaseConfig { string BasePath { get; set; } string AuthSecret { get; set; } int TimeoutInMinute { get; set; } + ISerializer Serializer { get; set; } } } \ No newline at end of file diff --git a/FireSharp/EventStreaming/TODO.md b/FireSharp/EventStreaming/TODO.md deleted file mode 100644 index a3f2103..0000000 --- a/FireSharp/EventStreaming/TODO.md +++ /dev/null @@ -1,53 +0,0 @@ -https://www.firebase.com/docs/rest-api.html - -Streaming from the REST API -============================= - -Firebase REST endpoints support the EventSource / Server-Sent Events protocol as well. To stream changes to a single location in your Firebase, you will need to do a few things: - -Set the client's Accept header to "text/event-stream" -Respect HTTP Redirects, in particular HTTP status code 307 -If the location requires permission to read, you must include the auth parameter (see above in Query Parameters) -In return, the server will send named events as the state of the data at the requested URL changes. The structure of these messages conforms to the EventSource protocol: - -event: event name -data: JSON encoded data payload -The server may send the following events: - -put -The JSON-encoded data will be an object with two keys: path and data -The path points to a location relative to the request URL -The client should replace all of the data at that location in its cache with the data given in the message - -patch -The JSON-encoded data will be an object with two keys: path and data -The path points to a location relative to the request URL -For each key in the data, the client should replace the corresponding key in its cache with the data for that key in the message - -keep-alive -The data for this event is null, no action is required - -cancel -The data for this event is null -This event will be sent if the security rules cause a read at the requested location to no longer be allowed - -auth_revoked -The data for this event is a string indicating that a the credential has expired -This event will be sent when the supplied auth parameter is no longer valid -Here's an example set of events that the server may send: - -// Set your entire cache to {"a": 1, "b": 2} -event: put -data: {"path": "/", "data": {"a": 1, "b": 2}} - - -// Put the new data in your cache under the key 'c', so that the complete cache now looks like: -// {"a": 1, "b": 2, "c": {"foo": true, "bar": false}} -event: put -data: {"path": "/c", "data": {"foo": true, "bar": false}} - - -// For each key in the data, update (or add) the corresponding key in your cache at path /c, -// for a final cache of: {"a": 1, "b": 2, "c": {"foo": 3, "bar": false, "baz": 4}} -event: patch -data: {"path": "/c", "data": {"foo": 3, "baz": 4}} \ No newline at end of file diff --git a/FireSharp/Extensions/ObjectExtensions.cs b/FireSharp/Extensions/ObjectExtensions.cs index 0429fa3..61b6901 100644 --- a/FireSharp/Extensions/ObjectExtensions.cs +++ b/FireSharp/Extensions/ObjectExtensions.cs @@ -1,19 +1,28 @@ using System.Net.Http; -using Newtonsoft.Json; +using FireSharp.Interfaces; namespace FireSharp.Extensions { public static class ObjectExtensions { + private static ISerializer _serializer; + + public static ISerializer Serializer + { + get { return _serializer ?? (_serializer = new JsonSerializerWrapper()); } + set { _serializer = value; } + } + + public static string ToJson(this object @object) { - return JsonConvert.SerializeObject(@object); + return _serializer.Serialize(@object); } public static T ReadAs(this HttpResponseMessage response) { var task = response.Content.ReadAsStringAsync(); - return JsonConvert.DeserializeObject(task.Result); + return _serializer.Deserialize(task.Result); } } } \ No newline at end of file diff --git a/FireSharp/FireSharp.csproj b/FireSharp/FireSharp.csproj index 8a6c9eb..af47196 100644 --- a/FireSharp/FireSharp.csproj +++ b/FireSharp/FireSharp.csproj @@ -38,6 +38,9 @@ + + ..\packages\Newtonsoft.Json.6.0.4\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll + @@ -45,7 +48,6 @@ - @@ -59,6 +61,8 @@ + + @@ -75,9 +79,6 @@ ..\packages\Microsoft.Bcl.Async.1.0.168\lib\portable-net40+sl4+win8+wp71+wpa81\Microsoft.Threading.Tasks.Extensions.dll - - ..\packages\Newtonsoft.Json.6.0.4\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll - ..\packages\Microsoft.Bcl.1.1.9\lib\portable-net40+sl5+win8+wp8+wpa81\System.IO.dll @@ -96,8 +97,6 @@ ..\packages\Microsoft.Bcl.1.1.9\lib\portable-net40+sl5+win8+wp8+wpa81\System.Threading.Tasks.dll - - diff --git a/FireSharp/Interfaces/ISerializer.cs b/FireSharp/Interfaces/ISerializer.cs new file mode 100644 index 0000000..afd6be8 --- /dev/null +++ b/FireSharp/Interfaces/ISerializer.cs @@ -0,0 +1,8 @@ +namespace FireSharp.Interfaces +{ + public interface ISerializer + { + T Deserialize(string json); + string Serialize(T value); + } +} \ No newline at end of file diff --git a/FireSharp/Interfaces/JsonSerializerWrapper.cs b/FireSharp/Interfaces/JsonSerializerWrapper.cs new file mode 100644 index 0000000..090da94 --- /dev/null +++ b/FireSharp/Interfaces/JsonSerializerWrapper.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace FireSharp.Interfaces +{ + internal class JsonSerializerWrapper : ISerializer + { + public T Deserialize(string json) + { + return JsonConvert.DeserializeObject(json); + } + + public string Serialize(T value) + { + return JsonConvert.SerializeObject(value); + } + } +} \ No newline at end of file diff --git a/FireSharp/RequestManager.cs b/FireSharp/RequestManager.cs index 581334c..2326f42 100644 --- a/FireSharp/RequestManager.cs +++ b/FireSharp/RequestManager.cs @@ -5,7 +5,6 @@ using FireSharp.Config; using FireSharp.Exceptions; using FireSharp.Interfaces; -using Newtonsoft.Json; namespace FireSharp { @@ -109,7 +108,7 @@ private Task ProcessRequest(HttpMethod method, string path, if (payload != null) { - var json = JsonConvert.SerializeObject(payload); + var json = _config.Serializer.Serialize(payload); request.Content = new StringContent(json); } diff --git a/FireSharp/content/web.config.transform b/FireSharp/content/web.config.transform deleted file mode 100644 index c6765ba..0000000 --- a/FireSharp/content/web.config.transform +++ /dev/null @@ -1,8 +0,0 @@ - - -
- - - - - \ No newline at end of file diff --git a/FireSharp/packages.config b/FireSharp/packages.config index 4db8f62..d21495a 100644 --- a/FireSharp/packages.config +++ b/FireSharp/packages.config @@ -1,14 +1,9 @@  - - - - - + + + + + \ No newline at end of file