예제 #1
0
        public static WoopsaValue DeserializeWoopsaValue(string jsonText)
        {
            var result = JsonSerializer.Deserialize <WoopsaReadResult>(jsonText);

            if (result != null)
            {
                var         valueType = (WoopsaValueType)Enum.Parse(typeof(WoopsaValueType), result.Type);
                WoopsaValue resultWoopsaValue;
                DateTime?   timeStamp;
                if (result.TimeStamp != null)
                {
                    timeStamp = DateTime.Parse(result.TimeStamp, CultureInfo.InvariantCulture);
                }
                else
                {
                    timeStamp = null;
                }
                if (valueType == WoopsaValueType.JsonData)
                {
                    resultWoopsaValue = new WoopsaValue(WoopsaJsonData.CreateFromDeserializedData(result.Value), timeStamp);
                }
                else
                {
                    resultWoopsaValue = WoopsaValue.CreateChecked(WoopsaFormat.ToStringWoopsa(result.Value),
                                                                  valueType, timeStamp);
                }
                return(resultWoopsaValue);
            }
            else
            {
                return(WoopsaValue.Null);
            }
        }
예제 #2
0
        public WoopsaJsonData WaitNotification(int subscriptionChannel, int lastNotificationId)
        {
            int channelId      = subscriptionChannel;
            int notificationId = lastNotificationId;
            WoopsaSubscriptionChannel channel;

            lock (_channels)
                if (_channels.ContainsKey(channelId))
                {
                    channel = _channels[channelId];
                }
                else
                {
                    channel = null;
                }
            if (channel != null)
            {
                IWoopsaNotifications notifications = channel.WaitNotification(WoopsaSubscriptionServiceConst.WaitNotificationTimeout, notificationId);
                return(WoopsaJsonData.CreateFromText(notifications.Serialize()));
            }
            else
            {
                throw new WoopsaInvalidSubscriptionChannelException(string.Format("Tried to call WaitNotification on channel with id={0} that does not exist", channelId));
            }
        }
예제 #3
0
 private WoopsaValue(string text, WoopsaValueType type, DateTime? timestamp)
 {
     _text = text;
     _type = type;
     _timestamp = timestamp;
     if (type == WoopsaValueType.JsonData)
         _jsonData = Woopsa.WoopsaJsonData.CreateFromText(text);
 }
예제 #4
0
 public static double ToDouble(this WoopsaJsonData data)
 {
     if (data.IsSimple)
     {
         return(data.InternalObject.GetDouble());
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("double", data.InternalObject.GetType().ToString()));
     }
 }
예제 #5
0
 public static ulong ToUInt64(this WoopsaJsonData data)
 {
     if (data.IsSimple)
     {
         return(data.InternalObject.GetUInt64());
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("UInt64", data.InternalObject.GetType().ToString()));
     }
 }
예제 #6
0
 public static int ToInt32(this WoopsaJsonData data)
 {
     if (data.IsSimple)
     {
         return(data.InternalObject.GetInt32());
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("Int32", data.InternalObject.GetType().ToString()));
     }
 }
예제 #7
0
 public static bool ToBool(this WoopsaJsonData data)
 {
     if (data.IsSimple)
     {
         return(data.InternalObject.GetBoolean());
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("bool", data.InternalObject.GetType().ToString()));
     }
 }
예제 #8
0
 public static float ToFloat(this WoopsaJsonData data)
 {
     if (data.IsSimple)
     {
         return((float)Convert.ToDouble(data.InternalObject));
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("float", data.InternalObject.GetType().ToString()));
     }
 }
예제 #9
0
 public static UInt16 ToUInt16(this WoopsaJsonData data)
 {
     if (data.IsSimple)
     {
         return(Convert.ToUInt16(data.InternalObject));
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("UInt16", data.InternalObject.GetType().ToString()));
     }
 }
예제 #10
0
 public bool TryGetArrayIndex(int index, out WoopsaJsonData result)
 {
     if (IsArray)
     {
         result = CreateFromDeserializedData(_jsonElement[index]);
         return(true);
     }
     else
     {
         result = null;
         return(false);
     }
 }
예제 #11
0
 internal void DispatchResults(WoopsaJsonData jsonData)
 {
     if (jsonData.IsArray)
     {
         for (int i = 0; i < jsonData.Length; i++)
         {
             WoopsaJsonData      item = jsonData[i];
             int                 id   = item[WoopsaFormat.KeyId];
             WoopsaClientRequest request;
             if (_clientRequestsById.TryGetValue(id, out request))
             {
                 WoopsaJsonData result = item[WoopsaFormat.KeyResult];
                 if (result.ContainsKey(WoopsaFormat.KeyError))
                 {
                     request.Result = new WoopsaClientRequestResult()
                     {
                         Error      = WoopsaFormat.DeserializeError(result.AsText),
                         ResultType = WoopsaClientRequestResultType.Error
                     };
                 }
                 else if (request.Request.Verb == WoopsaFormat.VerbMeta)
                 {
                     request.Result = new WoopsaClientRequestResult()
                     {
                         Meta       = WoopsaFormat.DeserializeMeta(result.AsText),
                         ResultType = WoopsaClientRequestResultType.Meta
                     };
                 }
                 else
                 {
                     request.Result = new WoopsaClientRequestResult()
                     {
                         Value      = WoopsaFormat.DeserializeWoopsaValue(result.AsText),
                         ResultType = WoopsaClientRequestResultType.Value
                     };
                 }
                 request.IsDone = true;
             }
             else
             {
                 throw new WoopsaException(
                           string.Format("MultiRequest received a result for an unkwnon request Id={0}", id));
             }
         }
     }
     else
     {
         throw new WoopsaException("MultiRequest response has invalid format");
     }
 }
예제 #12
0
        public bool TryGetDictionaryKey(string key, out WoopsaJsonData value)
        {
            if (IsDictionary)
            {
                if (_jsonElement.TryGetProperty(key, out var dictionnaryEntry))
                {
                    value = CreateFromDeserializedData(dictionnaryEntry);
                    return(true);
                }
            }

            // else
            value = null;
            return(false);
        }
예제 #13
0
        public bool TryGetDictionaryKey(string key, out WoopsaJsonData value)
        {
            if (IsDictionary)
            {
                object dictionnaryEntry;
                if (_asDictionary.TryGetValue(key, out dictionnaryEntry))
                {
                    value = CreateFromDeserializedData(_asDictionary[key]);
                    return(true);
                }
            }

            // else
            value = null;
            return(false);
        }
예제 #14
0
 public static string Serialize(this WoopsaJsonData data)
 {
     return(data.InternalObject.GetRawText());
 }
 internal void DispatchResults(WoopsaJsonData jsonData)
 {
     if (jsonData.IsArray)
         for (int i = 0; i < jsonData.Length; i++)
         {
             WoopsaJsonData item = jsonData[i];
             int id = item[WoopsaFormat.KeyId];
             WoopsaClientRequest request;
             if (_clientRequestsById.TryGetValue(id, out request))
             {
                 WoopsaJsonData result = item[WoopsaFormat.KeyResult];
                 if (result.ContainsKey(WoopsaFormat.KeyError))
                 {
                     request.Result = new WoopsaClientRequestResult()
                     {
                         Error = WoopsaFormat.DeserializeError(result.AsText),
                         ResultType = WoopsaClientRequestResultType.Error
                     };
                 }
                 else if (request.Request.Verb == WoopsaFormat.VerbMeta)
                 {
                     request.Result = new WoopsaClientRequestResult()
                     {
                         Meta = WoopsaFormat.DeserializeMeta(result.AsText),
                         ResultType = WoopsaClientRequestResultType.Meta
                     };
                 }
                 else
                 {
                     request.Result = new WoopsaClientRequestResult()
                     {
                         Value = WoopsaFormat.DeserializeWoopsaValue(result.AsText),
                         ResultType = WoopsaClientRequestResultType.Value
                     };
                 }
                 request.IsDone = true;
             }
             else
                 throw new WoopsaException(
                     string.Format("MultiRequest received a result for an unkwnon request Id={0}", id));
         }
     else
         throw new WoopsaException("MultiRequest response has invalid format");
 }
예제 #16
0
        public static string Serialize(this WoopsaJsonData data)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(data.InternalObject));
        }
예제 #17
0
 public WoopsaValue(WoopsaJsonData jsonData, DateTime? timestamp = null)
 {
     _jsonData = jsonData;
     _type = WoopsaValueType.JsonData;
     _timestamp = timestamp;
 }
예제 #18
0
 public WoopsaValue(WoopsaJsonData jsonData, DateTime?timestamp = null)
 {
     _jsonData  = jsonData;
     _type      = WoopsaValueType.JsonData;
     _timestamp = timestamp;
 }
예제 #19
0
 public WoopsaJsonDataDynamic(WoopsaJsonData data)
 {
     _data = data;
 }
예제 #20
0
 public static WoopsaJsonDataDynamic ToDynamic(this WoopsaJsonData data)
 {
     return(new WoopsaJsonDataDynamic(data));
 }
 public WoopsaJsonDataDynamic(WoopsaJsonData data)
 {
     _data = data;
 }
예제 #22
0
 public static string Serialize(this WoopsaJsonData data)
 {
     return(JsonSerializer.Serialize(data.InternalObject));
 }