Exemplo n.º 1
0
 public SequenceDeviceBasic FromJsonAlias(JsonValue alias)
 {
     if (TryGetValue(alias.AsString(), out SequenceDeviceBasic d))
     {
         return(d);
     }
     throw new JsonValueInvalidException(alias, "Unknown device name");
 }
Exemplo n.º 2
0
        public static object ConvertJsonValueToObject(JsonValue value)
        {
            if (value.IsNull)
            {
                return(null);
            }

            if (value.IsBoolean)
            {
                return(value.AsBoolean());
            }

            if (value.IsFloat || value.IsNumber)
            {
                return(value.AsDecimal());
            }

            if (value.IsString)
            {
                return(value.AsString());
            }

            if (value.IsArray)
            {
                return(value.AsArray().Select(ConvertJsonValueToObject).ToArray());
            }

            if (!value.IsRecord)
            {
                throw new NotImplementedException($"There's not implementation for JsonValue tag {value.Tag}");
            }

            var record = (JsonValue.Record)value;

            return(record.properties.ToDictionary(kvPair => kvPair.Item1, kvPair => ConvertJsonValueToObject(kvPair.Item2)));
        }
Exemplo n.º 3
0
 public void Receive(JsonValue aJsonValue)
 {
     if (aJsonValue.IsObject)
     {
         JsonValue aType = aJsonValue.Get("type");
         if (!aType.IsString)
         {
             Console.WriteLine("Bad message from client: {0}", aJsonValue);
             return;
         }
         string userid;
         switch (aType.AsString())
         {
             case "message":
                 lock (iLock)
                 {
                     userid = iUserId;
                 }
                 iChatApp.NewMessage(userid, aJsonValue.Get("content").AsString());
                 break;
             case "changeuser":
                 iBrowserTabProxy.SwitchUser(null);
                 break;
             case "user":
                 userid = aJsonValue.Get("id").AsString();
                 Console.WriteLine("SHOULD NOT GET HERE.");
                 iBrowserTabProxy.SetCookie("xappuser", userid, null);
                 iBrowserTabProxy.ReloadPage();
                 iBrowserTabProxy.SwitchUser(userid);
                 /*
                 User user;
                 if (!iUserList.TryGetUserById(userid, out user))
                 {
                     Console.WriteLine("Bad user id from client: {0}", userid);
                 }*/
                 //ChangeUser(userid);
                 break;
         }
     } else if (aJsonValue.IsString)
     {
         // Legacy.
         iChatApp.NewMessage(iUserId, aJsonValue.AsString());
     }
 }
Exemplo n.º 4
0
 public void Receive(JsonValue aJsonValue)
 {
     if (aJsonValue.IsObject)
     {
         JsonValue aType = aJsonValue.Get("type");
         if (!aType.IsString)
         {
             Console.WriteLine("Bad message from client: {0}", aJsonValue);
             return;
         }
         string userid;
         switch (aType.AsString())
         {
             case "message":
                 lock (iLock)
                 {
                     userid = iUserId;
                 }
                 iTestApp.NewMessage(userid, aJsonValue.Get("content").AsString());
                 break;
         }
     } else if (aJsonValue.IsString)
     {
         // Legacy.
         iTestApp.NewMessage(iUserId, aJsonValue.AsString());
     }
 }