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); } }
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)); } }
private WoopsaValue(string text, WoopsaValueType type, DateTime? timestamp) { _text = text; _type = type; _timestamp = timestamp; if (type == WoopsaValueType.JsonData) _jsonData = Woopsa.WoopsaJsonData.CreateFromText(text); }
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())); } }
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())); } }
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())); } }
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())); } }
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())); } }
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())); } }
public bool TryGetArrayIndex(int index, out WoopsaJsonData result) { if (IsArray) { result = CreateFromDeserializedData(_jsonElement[index]); return(true); } else { result = null; return(false); } }
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"); } }
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); }
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); }
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"); }
public static string Serialize(this WoopsaJsonData data) { JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(data.InternalObject)); }
public WoopsaValue(WoopsaJsonData jsonData, DateTime? timestamp = null) { _jsonData = jsonData; _type = WoopsaValueType.JsonData; _timestamp = timestamp; }
public WoopsaValue(WoopsaJsonData jsonData, DateTime?timestamp = null) { _jsonData = jsonData; _type = WoopsaValueType.JsonData; _timestamp = timestamp; }
public WoopsaJsonDataDynamic(WoopsaJsonData data) { _data = data; }
public static WoopsaJsonDataDynamic ToDynamic(this WoopsaJsonData data) { return(new WoopsaJsonDataDynamic(data)); }
public static string Serialize(this WoopsaJsonData data) { return(JsonSerializer.Serialize(data.InternalObject)); }