コード例 #1
0
 public static DBXDefaultFormatter getInstance()
 {
     if (instance == null)
     {
         instance = new DBXDefaultFormatter();
     }
     return(instance);
 }
コード例 #2
0
 protected void SetUpAuthorizationHeader(HttpWebRequest Client)
 {
     if (connection.UserName == null || connection.UserName.Equals(""))
     {
         Client.Headers["Authorization"] = "Basic Og=="; // no auth
     }
     else
     {
         String auth = DBXDefaultFormatter.getInstance().Base64Encode(
             connection.UserName + ":" + connection.Password);
         Client.Headers["Authorization"] = "Basic " + auth; // auth
     }
 }
コード例 #3
0
        /**
         * Class constructor, initialized the internal value by parse the String passed
         * @param value
         */
        public TJSONNumber(String value) : base()
        {
            Clear();
            long longres;

            if (long.TryParse(value, out longres))
            {
                valueInt = longres;
            }
            else
            {
                this.valueDouble = DBXDefaultFormatter.getInstance().StringToDouble(value);
            }
            isDouble = valueDouble != null;
        }
コード例 #4
0
 public override String ToString()
 {
     if (isDouble.HasValue)
     {
         if (isDouble.Value)
         {
             if (valueDouble != null)
             {
                 return(DBXDefaultFormatter.getInstance().doubleToString(valueDouble.Value));
             }
         }
         else
         {
             if (valueInt != null)
             {
                 return(DBXDefaultFormatter.getInstance().Int64ToString(valueInt.Value));
             }
         }
     }
     return(NullString);
 }
コード例 #5
0
 public static DBXDefaultFormatter getInstance()
 {
     if (instance == null)
         instance = new DBXDefaultFormatter();
     return instance;
 }
コード例 #6
0
ファイル: DBXValue.cs プロジェクト: svn2github/rest-dataware
        /**
         * Convert to String a DBXValue
         */
        public override String ToString()
        {
            try {
                if (containsASimpleValueType())
                {
                    if (GetAsDBXValue().isNull())
                    {
                        return(new TJSONNull().asJSONString());
                    }
                    else
                    {
                        return(GetAsDBXValue().ToString());
                    }
                }
                switch (CurrentDBXType)
                {
                case DBXDataTypes.AnsiStringType: {
                    return(DBXDefaultFormatter.getInstance().AnsiStringToString(
                               GetAsString()));
                }

                case DBXDataTypes.WideStringType: {
                    return(DBXDefaultFormatter.getInstance().WideStringToString(
                               GetAsString()));
                }

                case DBXDataTypes.Int8Type: {
                    return(DBXDefaultFormatter.getInstance().Int8ToString(
                               GetAsInt8()));
                }

                case DBXDataTypes.Int16Type: {
                    return(DBXDefaultFormatter.getInstance().Int16ToString(
                               GetAsInt16()));
                }

                case DBXDataTypes.Int32Type: {
                    return(DBXDefaultFormatter.getInstance().Int32ToString(
                               GetAsInt32()));
                }

                case DBXDataTypes.Int64Type: {
                    return(DBXDefaultFormatter.getInstance().Int64ToString(
                               GetAsInt64()));
                }

                case DBXDataTypes.UInt8Type: {
                    return(DBXDefaultFormatter.getInstance().UInt8ToString(GetAsUInt8()));
                }

                case DBXDataTypes.UInt16Type: {
                    return(DBXDefaultFormatter.getInstance().UInt16ToString(
                               GetAsUInt16()));
                }

                case DBXDataTypes.UInt32Type: {
                    return(DBXDefaultFormatter.getInstance().UInt32ToString(
                               GetAsUInt32()));
                }

                case DBXDataTypes.UInt64Type: {
                    return(DBXDefaultFormatter.getInstance().UInt64ToString(
                               GetAsUInt64()));
                }

                case DBXDataTypes.DateTimeType: {
                    return(DBXDefaultFormatter.getInstance().DateTimeToString(
                               GetAsDateTime()));
                }

                case DBXDataTypes.TimeStampType: {
                    return(DBXDefaultFormatter.getInstance().DateTimeToString(
                               GetAsTimeStamp()));
                }

                case DBXDataTypes.DateType: {
                    String s = DBXDefaultFormatter.getInstance().TDBXDateToString(
                        GetAsTDBXDate());
                    return(s);
                }

                case DBXDataTypes.TimeType: {
                    String s = DBXDefaultFormatter.getInstance().TDBXTimeToString(
                        GetAsTDBXTime());
                    return(s);
                }

                case DBXDataTypes.DoubleType: {
                    return(DBXDefaultFormatter.getInstance().doubleToString(
                               GetAsDouble()));
                }

                case DBXDataTypes.SingleType: {
                    return(DBXDefaultFormatter.getInstance().floatToString(
                               GetAsSingle()));
                }

                case DBXDataTypes.CurrencyType: {
                    return(DBXDefaultFormatter.getInstance().currencyToString(
                               GetAsCurrency()));
                }

                case DBXDataTypes.BooleanType: {
                    return(DBXDefaultFormatter.getInstance().booleanToString(GetAsBoolean()));
                }

                case DBXDataTypes.BcdType: {
                    return(DBXDefaultFormatter.getInstance().doubleToString(GetAsBcd()));
                }

                default:
                    throw new DBXException("Cannot convert this type to string");
                }
            } catch (DBXException) {
                return("<CANNOT CONVERT DBXType [" + Convert.ToString(CurrentDBXType) + "] TO STRING>");
            }
        }
コード例 #7
0
ファイル: DBXValue.cs プロジェクト: svn2github/rest-dataware
        /**
         * Adds in a JArray DBXValue and then use it in the body of the request
         */
        public void appendTo(TJSONArray json)
        {
            try {
                if (containsASimpleValueType())
                {
                    GetAsDBXValue().appendTo(json);
                    return;
                }

                switch (CurrentDBXType)
                {
                case DBXDataTypes.Int8Type: {
                    json.add(new TJSONNumber(GetAsInt8()));
                    break;
                }

                case DBXDataTypes.Int16Type: {
                    json.add(new TJSONNumber(GetAsInt16()));
                    break;
                }

                case DBXDataTypes.Int32Type: {
                    json.add(new TJSONNumber(GetAsInt32()));
                    break;
                }

                case DBXDataTypes.Int64Type: {
                    json.add(new TJSONNumber(GetAsInt64()));
                    break;
                }

                case DBXDataTypes.UInt8Type: {
                    json.add(new TJSONNumber(GetAsUInt8()));
                    break;
                }

                case DBXDataTypes.UInt16Type: {
                    json.add(new TJSONNumber(GetAsUInt16()));
                    break;
                }

                case DBXDataTypes.UInt32Type: {
                    json.add(new TJSONNumber(GetAsUInt32()));
                    break;
                }

                case DBXDataTypes.UInt64Type: {
                    json.add(new TJSONNumber(GetAsUInt64()));
                    break;
                }

                case DBXDataTypes.AnsiStringType:
                case DBXDataTypes.WideStringType: {
                    json.add(new TJSONString(GetAsString()));
                    break;
                }

                case DBXDataTypes.DateTimeType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().DateTimeToString(
                                                 dateTimeValue)));
                    break;
                }

                case DBXDataTypes.TimeStampType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().DateTimeToString(
                                                 TimeStampValue)));
                    break;
                }

                case DBXDataTypes.DateType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().TDBXDateToString(
                                                 GetAsTDBXDate())));
                    break;
                }

                case DBXDataTypes.TimeType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().TDBXTimeToString(
                                                 GetAsTDBXTime())));
                    break;
                }

                case DBXDataTypes.JsonValueType: {
                    Object o = GetAsJSONValue().getInternalObject();
                    json.add(o);
                    break;
                }

                case DBXDataTypes.TableType: {
                    try {
                        json.add(((JSONSerializable)objectValue).asJSONObject());
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.CurrencyType: {
                    try {
                        json.add(new TJSONNumber(GetAsCurrency()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.DoubleType: {
                    try {
                        json.add(new TJSONNumber(GetAsDouble()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.SingleType: {
                    try {
                        json.add(new TJSONNumber(GetAsSingle()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.BinaryBlobType: {
                    json.add(StreamToJson());
                    break;
                }

                default:
                    throw new DBXException("Cannot convert this type to string");
                }
            } catch (DBXException) {
                return;
            }
        }
コード例 #8
0
        /**
         * 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);
            }
        }