public static ToStringWoopsa ( System.DateTime dateTime ) : string | ||
dateTime | System.DateTime | |
return | string |
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 static WoopsaValue ToWoopsaValue(object value, WoopsaValueType type, DateTime?timeStamp = null) { try { switch (type) { case WoopsaValueType.Logical: return(new WoopsaValue((bool)value, timeStamp)); case WoopsaValueType.Integer: return(new WoopsaValue(Convert.ToInt64(value), timeStamp)); case WoopsaValueType.Real: return(new WoopsaValue(Convert.ToDouble(value), timeStamp)); case WoopsaValueType.DateTime: return(new WoopsaValue((DateTime)value, timeStamp)); case WoopsaValueType.TimeSpan: if (value is TimeSpan) { return(new WoopsaValue((TimeSpan)value, timeStamp)); } else { return(new WoopsaValue(TimeSpan.FromSeconds(Convert.ToDouble(value)), timeStamp)); } case WoopsaValueType.Text: if (value == null) { return(new WoopsaValue(string.Empty, timeStamp)); } else if (value.GetType().IsEnum) { return(new WoopsaValue(value.ToString(), timeStamp)); } else if (string.IsNullOrEmpty((string)value)) { return(new WoopsaValue(string.Empty, timeStamp)); } else { return(new WoopsaValue(WoopsaFormat.ToStringWoopsa(value), timeStamp)); } default: return(WoopsaValue.CreateUnchecked(WoopsaFormat.ToStringWoopsa(value), type, timeStamp)); } } catch (InvalidCastException) { throw new WoopsaException(String.Format("Cannot typecast object of type {0} to Woopsa Type {1}", value.GetType(), type.ToString())); } }
public static bool ToBool(this WoopsaJsonData data) { if (data.IsSimple) { return(WoopsaFormat.ToBool(WoopsaFormat.ToStringWoopsa(data.InternalObject))); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("bool", data.InternalObject.GetType().ToString())); } }
public static void Serialize(StringBuilder stringBuilder, IWoopsaValue value) { stringBuilder.Append(ElementOpen); // Value if (MustQuote(value.Type)) { SerializeKeyValue(stringBuilder, KeyValue, value.AsText, true, true); } else { SerializeKeyValue(stringBuilder, KeyValue, value.AsText, false, false); } stringBuilder.Append(ElementSeparator); // Type SerializeKeyValue(stringBuilder, KeyType, value.Type.ToString(), true, false); // TimeStamp if (value.TimeStamp.HasValue) { stringBuilder.Append(ElementSeparator); SerializeKeyValue(stringBuilder, KeyTimeStamp, WoopsaFormat.ToStringWoopsa(value.TimeStamp.Value), true, false); } stringBuilder.Append(ElementClose); }
public WoopsaValue(TimeSpan value, DateTime?timestamp = null) : this(WoopsaFormat.ToStringWoopsa(value), WoopsaValueType.TimeSpan, timestamp) { }
public WoopsaValue(double value, DateTime?timestamp = null) : this(WoopsaFormat.ToStringWoopsa(value), WoopsaValueType.Real, timestamp) { }
public WoopsaValue(Int64 value, DateTime?timestamp = null) : this(WoopsaFormat.ToStringWoopsa(value), WoopsaValueType.Integer, timestamp) { }
public WoopsaValue(bool value, DateTime?timestamp = null) : this(WoopsaFormat.ToStringWoopsa(value), WoopsaValueType.Logical, timestamp) { }