0

I have defined a type in C# called

using Message = System.Collections.Generic.Dictionary<string, object>;

I have no problem with sending this from a C# server to the C# client.

But now they want one of the value pairs to be an array of Message, as illustrated (the tracked variable with dummy values) below:

        Message msg = new Message();
        msg.Add("timestamp", Tools.ToMS(seconds, microseconds));
        msg.Add("DateTime", Tools.ToISO(this.seconds, this.microseconds));
        msg.Add("guid", Guid.NewGuid().ToString());
        msg.Add("heading", this.heading);
        msg.Add("correction", this.correction);
        msg.Add("valid", this.valid);
        msg.Add("lat", lat);
        msg.Add("lon", lon);
        msg.Add("altitude", altitude);
        msg.Add("Channel", "Oxford.GPS");

        Message[] tracked = new Message[2];
        tracked[0] = new Message();
        tracked[1] = new Message();
        tracked[0].Add("first", 1);
        tracked[1].Add("second", 2);
        msg.Add("tracked", tracked);
        return msg;

Ok, I get no errors in sending, but on the receiving side the embedded Dictionary is not converting to a Dictionary, instead I am getting an array of Newtonsoft.Json.Linq.JArray

     Type: Object
HasValues: 1
    First: [1x1 Newtonsoft.Json.Linq.JProperty]
     Last: [1x1 Newtonsoft.Json.Linq.JProperty]
    Count: 1
   Parent: [1x1 Newtonsoft.Json.Linq.JArray]
     Root: [1x1 Newtonsoft.Json.Linq.JArray]
     Next: [1x1 Newtonsoft.Json.Linq.JObject]
 Previous: []
     Path: [1x1 System.String]

Here is what the Detailed Trace is showing arriving at the Client, which looks good to my untrained eyes:

{"C":"d-4A172629-B,5549|C,0|D,1","M":[{"H":"GatewayHub","M":"post","A":[{"timestamp":1450469910308,"DateTime":"2015-12-18T20:18:30.3090000Z","guid":"60ef4307-1225-40f9-b0e0-f2f1d87e760d","heading":210.340958,"correction":3,"valid":true,"lat":42.299856271140619,"lon":-83.698864895162188,"altitude":269.147216796875,"Channel":"Oxford.GPS","tracked":[{"first":1},{"second":2}]}]}]})

Yes, believe it or not, I am then sending this via an event to Matlab, which also works, but not for the nested values.

Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
  • You could try this: https://stackoverflow.com/questions/32314638/signalr-typenamehandling – dbc Apr 08 '16 at 20:50

1 Answers1

0

Since my goal is merely to pass values from a sensor driver (written as a dll) from "server" box -> a Matlab Client on a seperate machine, I have changed how I am doing this.

I am taking the binary struct value, using a dynamic C# type and feeding it to JSON.NET inside of SignalR. This is doing a sufficiently efficient encoding.

Then I can do a:

        proxy.On<string, dynamic>("post2", (chan, pkt) =>
        {
            Console.WriteLine("channel: " + chan);
            pkt.channel = chan;
            trigger2(pkt);
        });

and get the data inside of the embedded C# dll (embedded in Matlab). I trigger an event (last line) and send the full JSON.NET object up to Matlab, which then can use .SelectToken() to grab values.

I thought this was neat, you can call it ugly and I won't cry.

Dr.YSG
  • 7,171
  • 22
  • 81
  • 139