Skip to content

Commit

Permalink
added arg validation to debug bridge issue and bumped version
Browse files Browse the repository at this point in the history
  • Loading branch information
hasankhan committed Jan 31, 2015
1 parent 943037e commit a820a51
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Shared/AssemblyInfo.Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyVersion("3.4.3.0")]
[assembly: AssemblyVersion("3.4.4.0")]
2 changes: 2 additions & 0 deletions Squiggle.Bridge/BridgeHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public void SendChatMessage(bool local, IPEndPoint target, Core.Chat.Transport.M

public void SendPresenceMessage(IPEndPoint target, byte[] message)
{
Validator.IsNotNull(target, "target");
Validator.IsNotNull(message, "message");
Send(target, new ForwardPresenceMessage() { BridgeEndPoint = externalEndPoint, Message = message});
}

Expand Down
2 changes: 2 additions & 0 deletions Squiggle.Utilities/Net/Pipe/UnicastMessagePipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protected override NetMQSocket CreateListener()

public void Send(IPEndPoint target, byte[] message)
{
Validator.IsNotNull(target, "target");
Validator.IsNotNull(message, "message");
Send(target.Address.ToString(), target.Port, message);
}

Expand Down
25 changes: 13 additions & 12 deletions Squiggle.Utilities/Serialization/SerializationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using ProtoBuf.Meta;
using System.Runtime.Serialization;
using System.Diagnostics;

namespace Squiggle.Utilities.Serialization
{
Expand All @@ -20,28 +21,28 @@ public static byte[] Serialize<T>(T item)
var stream = new MemoryStream();
ProtoBuf.Serializer.Serialize<T>(stream, item);
return stream.ToArray();
}

public static T Deserialize<T>(byte[] data)
{
if (data == null)
throw new ArgumentNullException("data");

var stream = new MemoryStream(data);
T item = ProtoBuf.Serializer.Deserialize<T>(stream);
return item;
}
}

public static void Deserialize<T>(byte[] data, Action<T> onDeserialize, string entityName) where T:class
{
T obj = null;
if (ExceptionMonster.EatTheException(() =>
{
obj = SerializationHelper.Deserialize<T>(data);
}, "deserializing " + entityName))
}, "deserializing " + entityName + " of type " + typeof(T).Name))
{
onDeserialize(obj);
}
}

static T Deserialize<T>(byte[] data)
{
if (data == null)
throw new ArgumentNullException("data");

var stream = new MemoryStream(data);
T item = ProtoBuf.Serializer.Deserialize<T>(stream);
return item;
}
}
}
1 change: 1 addition & 0 deletions Squiggle.Utilities/Squiggle.Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="TimeExtensions.cs" />
<Compile Include="Application\UserActivityMonitor.cs" />
<Compile Include="Application\WinStartup.cs" />
<Compile Include="Validator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
17 changes: 17 additions & 0 deletions Squiggle.Utilities/Validator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System
{
public static class Validator
{
public static void IsNotNull(object value, string name)
{
if (value == null)
throw new ArgumentNullException(name);
}
}
}

0 comments on commit a820a51

Please sign in to comment.