using json as serializer

This commit is contained in:
Alexander Eckart committed 2013-05-05 16:53:16 +02:00
1 parent 80b54cad25
commit eb9e17d2e6
6 files changed
+12 -9

No files matched your search

+1
View File
@@ -42,6 +42,7 @@ Output/Songs
/ClientServerLib/ClientServerLib/ClientServerLib.csproj.user /ClientServerLib/ClientServerLib/ClientServerLib.csproj.user
/ClientServerLib/ClientServerLib/bin/Debug/ClientServerLib.dll /ClientServerLib/ClientServerLib/bin/Debug/ClientServerLib.dll
/ClientServerLib/ClientTest/bin/Debug/ClientServerLib.dll /ClientServerLib/ClientTest/bin/Debug/ClientServerLib.dll
/ClientServerLib/ClientTest/bin/Release/ClientServerLib.dll
/ClientServerLib/ClientServerLib/bin/ClientServerLib.dll /ClientServerLib/ClientServerLib/bin/ClientServerLib.dll
ClientTest.exe ClientTest.exe
*.vshost.* *.vshost.*
@@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
@@ -2,16 +2,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.IO; using System.IO;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text; using System.Text;
using System.Security.Cryptography; using System.Security.Cryptography;
using Newtonsoft.Json;
namespace Vocaluxe.Base.Server namespace Vocaluxe.Base.Server
{ {
public static class CCommands public static class CCommands
{ {
private static UTF8Encoding encoder = new UTF8Encoding();
public static SHA256Managed SHA256 = new SHA256Managed(); public static SHA256Managed SHA256 = new SHA256Managed();
public const int ResponseOK = 1; public const int ResponseOK = 1;
@@ -75,9 +76,8 @@ namespace Vocaluxe.Base.Server
byte[] data; byte[] data;
using (MemoryStream ms = new MemoryStream()) using (MemoryStream ms = new MemoryStream())
{ {
BinaryFormatter formatter = new BinaryFormatter(); string json = JsonConvert.SerializeObject(obj);
formatter.Serialize(ms, obj); data = encoder.GetBytes(json);
data = ms.ToArray();
} }
stream.Write(data, 0, data.Length); stream.Write(data, 0, data.Length);
return stream.ToArray(); return stream.ToArray();
@@ -99,11 +99,10 @@ namespace Vocaluxe.Base.Server
{ {
try try
{ {
BinaryFormatter formatter = new BinaryFormatter(); obj = JsonConvert.DeserializeObject<T>(encoder.GetString(data));
obj = (T)formatter.Deserialize(ms);
return true; return true;
} }
catch (Exception e) catch
{ {
return false; return false;
} }
@@ -2,7 +2,6 @@
namespace Vocaluxe.Base.Server namespace Vocaluxe.Base.Server
{ {
[Serializable]
public struct SLoginData public struct SLoginData
{ {
public byte[] SHA256; public byte[] SHA256;
Binary file not shown.
Binary file not shown.