Exemple #1
0
        public Broadcast(String rawData, AppInstance instance)
        {
            var dp = (MsgBroadcast)MsgBroadcast.Deserialize(rawData);
            guid = dp.Id;
            msgContent = dp.Content;

            var bcast = new MsgBroadcast();
            bcast.FromInstanceId = instance.InstanceId;
            bcast.Id = guid;
            bcast.Content = msgContent;

            msg = verb + ' ' + bcast.Serialize();

            this.FromInstance = instance;
            sendto = new List<AppInstance>();
        }
        public void TestMsgBroadcastSerialization()
        {
            var msgBroadcast = new MsgBroadcast();
            msgBroadcast.Id = "uuid";
            var dct = new Dictionary<string, object>();
            dct.Add("text", "pickle unicorn");
            var innerDct = new Dictionary<string, object>();
            innerDct.Add("other", "blah");
            dct.Add("thing", innerDct);
            msgBroadcast.Content = dct;

            string json = msgBroadcast.Serialize();
            System.Diagnostics.Debug.WriteLine(json);

            Assert.IsTrue(json.IndexOf("\"other\":\"blah\"") > 0, "should have inner dict content");
        }
Exemple #3
0
 public static new DataPacket Deserialize(string json)
 {
     try
     {
         var ret = new MsgBroadcast();
         dynamic obj = Json.Decode(json);
         ret.Id = obj["id"];
         if (ret.Id == null)
             throw new ParseException(json, "No id was supplied");
         ret.Content = obj["content"];
         if (ret.Content == null)
             throw new ParseException(json, "No content was supplied");
         return ret;
     }
     catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)
     {
         throw new ParseException(json, "General binding exception. Was something invalid?");
     }
     catch (ArgumentException)
     {
         throw new ParseException(json, "Invalid JSON");
     }
 }