/** * Convert a Object to DBXValue * @param o * @param value * @param DBXTypeName */ public static void JSONtoDBX(Object o, DBXValue value, String DBXTypeName) { try { if (DBXTypeName.StartsWith("TDBX") && DBXTypeName.EndsWith("Value") && !(DBXTypeName.IndexOf("Stream") > 0) && !(DBXTypeName.IndexOf("Reader") > 0)) { if (JTokenToObject(o) == null) { value.GetAsDBXValue().setNull(); return; } } if (!((o == null) && (DBXTypeName.Equals("")))) { switch (value.getDBXType()) { case DBXDataTypes.Int8Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXInt8Value"))) { value.GetAsDBXValue() .SetAsInt8(Int16.Parse(o.ToString())); } else value.SetAsInt8(Int16.Parse(o.ToString())); break; case DBXDataTypes.Int16Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXInt16Value"))) { value.GetAsDBXValue().SetAsInt16( (Int16.Parse(o.ToString()))); } else value.SetAsInt16(Int16.Parse(o.ToString())); break; case DBXDataTypes.Int32Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXInt32Value"))) { value.GetAsDBXValue().SetAsInt32( (Int32.Parse(o.ToString()))); } else value.SetAsInt32(Int32.Parse(o.ToString())); break; case DBXDataTypes.Int64Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXInt64Value"))) { value.GetAsDBXValue().SetAsInt64( (Int64.Parse(o.ToString()))); } else value.SetAsInt64(Int64.Parse(o.ToString())); break; case DBXDataTypes.BcdType: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXBcdValue"))) { value.GetAsDBXValue().SetAsBcd( DBXDefaultFormatter.getInstance().StringToDouble(o.ToString())); } else value.SetAsBcd((DBXDefaultFormatter.getInstance() .StringToDouble((o.ToString())))); break; case DBXDataTypes.UInt8Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXUInt8Value"))) { value.GetAsDBXValue().SetAsUInt8( (UInt16.Parse(o.ToString()))); } else value.SetAsUInt8(UInt16.Parse(o.ToString())); break; case DBXDataTypes.UInt16Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXUInt16Value"))) { value.GetAsDBXValue().SetAsUInt16( (UInt16.Parse(o.ToString()))); } else value.SetAsUInt16(UInt16.Parse(o.ToString())); break; case DBXDataTypes.UInt32Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXUInt32Value"))) { value.GetAsDBXValue().SetAsUInt32( UInt32.Parse((o.ToString()))); } else value.SetAsUInt32(UInt32.Parse(o.ToString())); break; case DBXDataTypes.UInt64Type: if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXUInt64Value"))) { value.GetAsDBXValue().SetAsUInt64( int.Parse(o.ToString())); } else value.SetAsUInt64(int.Parse(o.ToString())); break; case DBXDataTypes.DoubleType: { if (o is JToken) o = ((JToken)o).Value<Object>(); if (DBXTypeName.Equals("TDBXDoubleValue")) { value.GetAsDBXValue().SetAsDouble( (Convert.ToDouble(o.ToString()))); } else value.SetAsDouble(Convert.ToDouble(o.ToString())); break; } case DBXDataTypes.SingleType: { if (o is JToken) o = ((JToken)o).Value<Object>(); if (DBXTypeName.Equals("TDBXSingleValue")) { value.GetAsDBXValue().SetAsSingle( Convert.ToSingle(o.ToString())); } else value.SetAsSingle(Convert.ToSingle(o.ToString())); break; } case DBXDataTypes.CurrencyType: { if (o is JToken) o = ((JToken)o).Value<Object>(); value.SetAsCurrency(Convert.ToDouble(o)); break; } case DBXDataTypes.JsonValueType: { value.SetAsJSONValue((TJSONValue)DBXJSONTools .JSONToJSONValue(o)); break; } case DBXDataTypes.BinaryBlobType: { if (DBXTypeName.Equals("TDBXStreamValue")) { value.GetAsDBXValue().SetAsStream(DBXJSONTools.JSONToStream(new TJSONArray((JArray)o))); } else value.SetAsStream(DBXJSONTools.JSONToStream(new TJSONArray((JArray)o))); break; } case DBXDataTypes.BlobType: { value.SetAsBlob(DBXJSONTools.JSONToStream(new TJSONArray((JArray)o))); break; } case DBXDataTypes.TimeStampType: { if (o is JToken) o = ((JToken)o).Value<Object>(); DateTime d = DBXDefaultFormatter.getInstance() .StringToDateTime((String)o); if (d == null) throw new DBXException("Invalid date"); if (DBXTypeName.Equals("TDBXTimeStampValue")) { value.GetAsDBXValue().SetAsTimeStamp(d); } else value.SetAsTimeStamp(d); break; } case DBXDataTypes.AnsiStringType: { if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXAnsiStringValue")) || (DBXTypeName.Equals("TDBXStringValue")) || (DBXTypeName.Equals("TDBXAnsiCharsValue"))) { value.GetAsDBXValue().SetAsAnsiString((String)o); } else value.SetAsString((string)o); break; } case DBXDataTypes.TableType: { if (DBXTypeName.Equals("TDBXReaderValue")) { value.GetAsDBXValue().SetAsTable( (TableType)DBXJSONTools.JSONToTableType(o, DBXTypeName)); } else { value.SetAsTable((TableType)DBXJSONTools.JSONToTableType( o, DBXTypeName)); } break; } case DBXDataTypes.WideStringType: { if (o is JToken) o = ((JToken)o).Value<Object>(); if ((DBXTypeName.Equals("TDBXAnsiStringValue")) || (DBXTypeName.Equals("TDBXStringValue")) || (DBXTypeName.Equals("TDBXAnsiCharsValue")) || (DBXTypeName.Equals("TDBXWideStringValue"))) { value.GetAsDBXValue().SetAsString((String)o); } else value.SetAsString((string)o); break; } case DBXDataTypes.TimeType: { if (o is JToken) o = ((JToken)o).Value<Object>(); int t = DBXDefaultFormatter.getInstance().StringToTDBXTime( (String)o); if (DBXTypeName.Equals("TDBXTimeValue")) { value.GetAsDBXValue().SetAsTDBXTime(t); } else value.SetAsTDBXTime(t); break; } case DBXDataTypes.DateType: { if (o is JToken) o = ((JToken)o).Value<Object>(); int t = DBXDefaultFormatter.getInstance().StringToTDBXDate( (String)o); if (DBXTypeName.Equals("TDBXDateValue")) { value.GetAsDBXValue().SetAsTDBXDate(t); } else value.SetAsTDBXDate(t); break; } case DBXDataTypes.DateTimeType: { if (o is JToken) o = ((JToken)o).Value<Object>(); DateTime d = DBXDefaultFormatter.getInstance() .StringToDateTime((String)o); if (d == null) throw new DBXException("Invalid date"); value.SetAsDateTime(d); break; } case DBXDataTypes.BooleanType: { if (o is JToken) o = ((JToken)o).Value<Object>(); if (DBXTypeName.Equals("TDBXBooleanValue")) { value.GetAsDBXValue().SetAsBoolean(Convert.ToBoolean(o.ToString())); } else value.SetAsBoolean(Convert.ToBoolean(o.ToString())); break; } default: throw new DBXException("Cannot convert datatype " + value.getDBXType().ToString()); } // switch } } catch (Exception ex) { throw new DBXException(ex.Message); } }
// ********** DBXValueType ****************************** public override void SetAsDBXValue(DBXValue Value) { setDBXType(Value.getDBXType()); isSimpleValueType = true; DBXValueValue = Value; }
// ********** DBXValueType ****************************** // Setter public virtual void SetAsDBXValue(DBXValue Value) { throw new DBXException("Invalid Type Access"); }
/** * Convert a Object to DBXValue * @param o * @param value * @param DBXTypeName */ public static void JSONtoDBX(Object o, DBXValue value, String DBXTypeName) { try { if (DBXTypeName.StartsWith("TDBX") && DBXTypeName.EndsWith("Value") && !(DBXTypeName.IndexOf("Stream") > 0) && !(DBXTypeName.IndexOf("Reader") > 0)) { if (JTokenToObject(o) == null) { value.GetAsDBXValue().setNull(); return; } } if (!((o == null) && (DBXTypeName.Equals("")))) { switch (value.getDBXType()) { case DBXDataTypes.Int8Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXInt8Value"))) { value.GetAsDBXValue() .SetAsInt8(Int16.Parse(o.ToString())); } else { value.SetAsInt8(Int16.Parse(o.ToString())); } break; case DBXDataTypes.Int16Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXInt16Value"))) { value.GetAsDBXValue().SetAsInt16( (Int16.Parse(o.ToString()))); } else { value.SetAsInt16(Int16.Parse(o.ToString())); } break; case DBXDataTypes.Int32Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXInt32Value"))) { value.GetAsDBXValue().SetAsInt32( (Int32.Parse(o.ToString()))); } else { value.SetAsInt32(Int32.Parse(o.ToString())); } break; case DBXDataTypes.Int64Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXInt64Value"))) { value.GetAsDBXValue().SetAsInt64( (Int64.Parse(o.ToString()))); } else { value.SetAsInt64(Int64.Parse(o.ToString())); } break; case DBXDataTypes.BcdType: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXBcdValue"))) { value.GetAsDBXValue().SetAsBcd( DBXDefaultFormatter.getInstance().StringToDouble(o.ToString())); } else { value.SetAsBcd((DBXDefaultFormatter.getInstance() .StringToDouble((o.ToString())))); } break; case DBXDataTypes.UInt8Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXUInt8Value"))) { value.GetAsDBXValue().SetAsUInt8( (UInt16.Parse(o.ToString()))); } else { value.SetAsUInt8(UInt16.Parse(o.ToString())); } break; case DBXDataTypes.UInt16Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXUInt16Value"))) { value.GetAsDBXValue().SetAsUInt16( (UInt16.Parse(o.ToString()))); } else { value.SetAsUInt16(UInt16.Parse(o.ToString())); } break; case DBXDataTypes.UInt32Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXUInt32Value"))) { value.GetAsDBXValue().SetAsUInt32( UInt32.Parse((o.ToString()))); } else { value.SetAsUInt32(UInt32.Parse(o.ToString())); } break; case DBXDataTypes.UInt64Type: if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXUInt64Value"))) { value.GetAsDBXValue().SetAsUInt64( int.Parse(o.ToString())); } else { value.SetAsUInt64(int.Parse(o.ToString())); } break; case DBXDataTypes.DoubleType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } if (DBXTypeName.Equals("TDBXDoubleValue")) { value.GetAsDBXValue().SetAsDouble( (Convert.ToDouble(o.ToString()))); } else { value.SetAsDouble(Convert.ToDouble(o.ToString())); } break; } case DBXDataTypes.SingleType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } if (DBXTypeName.Equals("TDBXSingleValue")) { value.GetAsDBXValue().SetAsSingle( Convert.ToSingle(o.ToString())); } else { value.SetAsSingle(Convert.ToSingle(o.ToString())); } break; } case DBXDataTypes.CurrencyType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } value.SetAsCurrency(Convert.ToDouble(o)); break; } case DBXDataTypes.JsonValueType: { value.SetAsJSONValue((TJSONValue)DBXJSONTools .JSONToJSONValue(o)); break; } case DBXDataTypes.BinaryBlobType: { if (DBXTypeName.Equals("TDBXStreamValue")) { value.GetAsDBXValue().SetAsStream(DBXJSONTools.JSONToStream(new TJSONArray((JArray)o))); } else { value.SetAsStream(DBXJSONTools.JSONToStream(new TJSONArray((JArray)o))); } break; } case DBXDataTypes.BlobType: { value.SetAsBlob(DBXJSONTools.JSONToStream(new TJSONArray((JArray)o))); break; } case DBXDataTypes.TimeStampType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } DateTime d = DBXDefaultFormatter.getInstance() .StringToDateTime((String)o); if (d == null) { throw new DBXException("Invalid date"); } if (DBXTypeName.Equals("TDBXTimeStampValue")) { value.GetAsDBXValue().SetAsTimeStamp(d); } else { value.SetAsTimeStamp(d); } break; } case DBXDataTypes.AnsiStringType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXAnsiStringValue")) || (DBXTypeName.Equals("TDBXStringValue")) || (DBXTypeName.Equals("TDBXAnsiCharsValue"))) { value.GetAsDBXValue().SetAsAnsiString((String)o); } else { value.SetAsString((string)o); } break; } case DBXDataTypes.TableType: { if (DBXTypeName.Equals("TDBXReaderValue")) { value.GetAsDBXValue().SetAsTable( (TableType)DBXJSONTools.JSONToTableType(o, DBXTypeName)); } else { value.SetAsTable((TableType)DBXJSONTools.JSONToTableType( o, DBXTypeName)); } break; } case DBXDataTypes.WideStringType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } if ((DBXTypeName.Equals("TDBXAnsiStringValue")) || (DBXTypeName.Equals("TDBXStringValue")) || (DBXTypeName.Equals("TDBXAnsiCharsValue")) || (DBXTypeName.Equals("TDBXWideStringValue"))) { value.GetAsDBXValue().SetAsString((String)o); } else { value.SetAsString((string)o); } break; } case DBXDataTypes.TimeType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } int t = DBXDefaultFormatter.getInstance().StringToTDBXTime( (String)o); if (DBXTypeName.Equals("TDBXTimeValue")) { value.GetAsDBXValue().SetAsTDBXTime(t); } else { value.SetAsTDBXTime(t); } break; } case DBXDataTypes.DateType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } int t = DBXDefaultFormatter.getInstance().StringToTDBXDate( (String)o); if (DBXTypeName.Equals("TDBXDateValue")) { value.GetAsDBXValue().SetAsTDBXDate(t); } else { value.SetAsTDBXDate(t); } break; } case DBXDataTypes.DateTimeType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } DateTime d = DBXDefaultFormatter.getInstance() .StringToDateTime((String)o); if (d == null) { throw new DBXException("Invalid date"); } value.SetAsDateTime(d); break; } case DBXDataTypes.BooleanType: { if (o is JToken) { o = ((JToken)o).Value <Object>(); } if (DBXTypeName.Equals("TDBXBooleanValue")) { value.GetAsDBXValue().SetAsBoolean(Convert.ToBoolean(o.ToString())); } else { value.SetAsBoolean(Convert.ToBoolean(o.ToString())); } break; } default: throw new DBXException("Cannot convert datatype " + value.getDBXType().ToString()); } // switch } } catch (Exception ex) { throw new DBXException(ex.Message); } }
// ********** DBXValueType ****************************** public override void SetAsDBXValue(DBXValue Value) { setDBXType(Value.getDBXType()); isSimpleValueType = true; DBXValueValue = Value; }
// ********** DBXValueType ****************************** // Setter public virtual void SetAsDBXValue(DBXValue Value) { throw new DBXException("Invalid Type Access"); }