Inheritance: MsgBase
Exemple #1
0
 public Query(MsgQuery query, AppInstance instance)
 {
     this.FromInstance = instance;
     this.query = query;
     if (instance != null)
         this.query.FromInstanceId = instance.InstanceId;
     this.guid = query.Id;
     this.HasValidGuid = false;
     this.ShouldArchive = false;
 }
Exemple #2
0
 public static new DataPacket Deserialize(string json)
 {
     try
     {
         MsgQuery ret = new MsgQuery();
         dynamic obj = Json.Decode(json);
         ret.Id = obj["id"];
         if (ret.Id == null)
             throw new ParseException(json, "No id found");
         ret.Capability = obj["capability"];
         if (ret.Capability == null)
             throw new ParseException(json, "No capability found");
         ret.Action = obj["action"];
         if (ret.Action == null)
             throw new ParseException(json, "No action found");
         ret.Data = ParseDataThing(obj["data"]);
         ret.InstanceId = new List<string>();
         DynamicJsonArray instanceIds = obj["instanceId"];
         if (instanceIds != null)
         {
             foreach (object elem in instanceIds)
             {
                 ret.InstanceId.Add(elem.ToString());
             }
         }
         ret.Priority = obj["priority"];
         return ret;
     }
     catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)
     {
         throw new ParseException(json, "General binding exception. Is something invalid?");
     }
     catch (ArgumentException)
     {
         throw new ParseException(json, "Invalid JSON");
     }
 }
 public DirectedQuery(MsgQuery query, AppInstance instance)
     : base(query, instance)
 {
 }
Exemple #4
0
        public void TestMsgQuerySerialization()
        {
            var msgQuery = new MsgQuery();
            msgQuery.Id = "uuid";
            msgQuery.Capability = "weather";
            msgQuery.Action = "get_temperature";
            var instanceIds = new List<string>();
            instanceIds.Add("xxxx");
            instanceIds.Add("xx2");
            msgQuery.InstanceId = instanceIds;
            var data = new Dictionary<string, object>();
            data["scale"] = "fahrenheit";
            var inner = new Dictionary<string, object>();
            inner["k"] = "v";
            data["other"] = inner;
            msgQuery.Data = data;

            string json = msgQuery.Serialize();
            Debug.WriteLine(json);

            Assert.IsFalse(json.IndexOf("\"data\":null") >= 0, "Sould not contain null for data");
            Assert.IsFalse(json.IndexOf("KeyValuePairOf") >= 0, "Should not have strange toString");
            Assert.IsFalse(json.IndexOf("\"data\":[]") >= 0, "Should not have empty array for data");
        }