public void SetUsersToFollow(TJSONArray Users, SetUsersToFollowCallback callback = null, ExceptionCallback ExCal = null) { DSRESTCommand cmd = getConnection().CreateCommand(); cmd.setRequestType(DSHTTPRequestType.POST); cmd.setText("TCompanyTweet.SetUsersToFollow"); cmd.prepare(get_TCompanyTweet_SetUsersToFollow_Metadata()); InternalConnectionDelegate SetUsersToFollowDel = () => { if (callback != null) { try { callback.DynamicInvoke(); } catch (Exception ex) { if (ExCal != null) { getConnection().syncContext.Send(new SendOrPostCallback(x => ExCal.DynamicInvoke(ex.InnerException)), null); } else { getConnection().syncContext.Send(new SendOrPostCallback(x => BaseExCal.DynamicInvoke(ex.InnerException)), null); } } } }; cmd.getParameter(0).getValue().SetAsJSONValue(Users); getConnection().execute(cmd, this, SetUsersToFollowDel, ExCal); }
/** * Create a JSONObject from a DBXReader * @param dbxReader * @return JSONObject */ public static TJSONObject DBXReaderToJSONObject(TDBXReader dbxReader) { TJSONObject json = new TJSONObject(); TJSONArray arr2; TParams columns = dbxReader.getColumns(); try { arr2 = new TJSONArray(); for (int i = 0; i < columns.size(); i++) { arr2.add(columns.getParameter(i).tojson()); // Create the empty JArray for the data. Will be filled after json.addPairs(columns.getParameter(i).getName(), new TJSONArray()); } while (dbxReader.next()) { for (int c = 0; c < columns.size(); c++) { dbxReader.getColumns().getParameter(c).getValue().appendTo( json.getJSONArray(columns.getParameter(c) .getName())); } } json.addPairs("table", arr2); } catch (Exception) { } return(json); }
/** * create a DBXValueType from a JArray * @param json JArray with the values to set into DBXValuesType * @return a DBXValueType */ public static DBXValueType JSONToValueType(TJSONArray json) { DBXValueType vt = new DBXValueType(); JSONToValueType(json, vt); return(vt); }
public HTTPPOSTExecutor(DSRESTConnection connection, HttpWebRequest Client, DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback, TJSONArray parameters) : base(connection, Client, command, Sender, callback, EXCallback) { this._parameters = parameters; Client.Method = "POST"; SetUpHeaders(Client); }
/** * Returns a new TStream create by the value contained in the specified {@link JSONArray} * @param value * @return TStream */ public static TStream CreateFrom(TJSONArray value) { byte[] b1 = new byte[value.size()]; for (int i = 0; i < value.size(); i++) { b1[i] = Convert.ToByte(value.getInt(i).Value); } return(new TStream(b1)); }
/** * Returns a new TStream create by the value contained in the specified {@link JSONArray} * @param value * @return TStream */ public static TStream CreateFrom(TJSONArray value) { byte[] b1 = new byte[value.size()]; for (int i = 0; i < value.size(); i++) { b1[i] = Convert.ToByte(value.getInt(i).Value); } return new TStream(b1); }
/** * Create a JSONObject from a DBXParameters * @param dbxParameters * @return JSONObject */ public static TJSONObject DBXParametersToJSONObject(TParams dbxParameters) { TJSONObject json = new TJSONObject(); TJSONObject jsonobj = new TJSONObject(); for (int i = 0; i < dbxParameters.size(); i++) { TJSONArray arr3; try { arr3 = new TJSONArray(); arr3.add(new TJSONString(dbxParameters.getParameter(i).getValue().ToString())); json.addPairs(dbxParameters.getParameter(i).getName(), arr3); } catch (Exception) { } } TJSONArray arr2; arr2 = new TJSONArray(); for (int i = 0; i < dbxParameters.size(); i++) { TJSONArray arr; arr = new TJSONArray(); arr.add(new TJSONString(dbxParameters.getParameter(i).getName())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getDataType())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getOrdinal())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSubType())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getScale())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSize())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getPrecision())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getChildPosition())); if (dbxParameters.getParameter(i).getNullable()) arr.add(new TJSONTrue()); else arr.add(new TJSONFalse()); if (dbxParameters.getParameter(i).getHidden()) arr.add(new TJSONTrue()); else arr.add(new TJSONFalse()); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getParameterDirection())); if (dbxParameters.getParameter(i).getValueParameter()) arr.add(new TJSONTrue()); else arr.add(new TJSONFalse()); if (dbxParameters.getParameter(i).getLiteral()) arr.add(new TJSONTrue()); else arr.add(new TJSONFalse()); arr2.add(arr); } try { json.addPairs("table", arr2); } catch (Exception) { } return json; }
/** * * @return a JArray with the ByteArray of Stream */ protected TJSONArray StreamToJson() { checkCurrentDBXType(DBXDataTypes.BinaryBlobType); try { byte[] b = DBXTools.streamToByteArray(streamValue); TJSONArray jsArr = new TJSONArray(); for (int i = 0; i < b.Length; i++) { jsArr.add(new TJSONNumber(Convert.ToInt32(b[i]))); } return(jsArr); } catch (Exception e) { throw new DBXException(e.Message); } }
/** * send the the contents of the server response at the "execute" method of our DBXCallback class * @param json the contents of the server response */ private void invokeEvent(JObject json) { TJSONArray arr = new TJSONArray(json.Value <JArray>("invoke")); String callbackID = arr.getAsJsonString(0).getValue(); arr.remove(0); DBXCallback cb = callbacks[callbackID]; if (cb != null) { cb.Execute(arr.get(0), Convert.ToInt32(arr.getInt(1).Value)); } else { throw new DBXException("Invalid callback response"); } }
/** * create a DBXValueType from a JArray * @param json JArray with the values * @param vt the DBXValueType to set */ public static void JSONToValueType(TJSONArray arr, DBXValueType vt) { JArray json = (JArray)arr.getInternalObject(); vt.setName(json.Value <string>(0)); vt.setDataType(json.Value <int>(1)); vt.setOrdinal(json.Value <int>(2)); vt.setSubType(json.Value <int>(3)); vt.setScale(json.Value <int>(4)); vt.setSize(json.Value <int>(5)); vt.setPrecision(json.Value <int>(6)); vt.setChildPosition(json.Value <int>(7)); vt.setNullable(json.Value <bool>(8)); vt.setHidden(json.Value <bool>(9)); vt.setParameterDirection(json.Value <int>(10)); vt.setValueParameter(json.Value <bool>(11)); vt.setLiteral(json.Value <bool>(12)); }
private void broadcastEvent(JObject json) { List <string> keys = new List <string>(callbacks.Keys); TJSONArray arr = new TJSONArray(json.Value <JArray>("broadcast")); foreach (String callbackskeys in keys) { DBXCallback cb = callbacks[callbackskeys]; if (cb != null) { cb.Execute(arr.get(0), Convert.ToInt32(arr.getInt(1).Value)); } else { throw new DBXException("Invalid callback response"); } } }
/** * Returns a new TParams created by the metadata represented in the specified {@link JSONArray} * @param paramsMetadata * @return TParams */ public static TParams CreateParametersFromMetadata(TJSONArray parametersMetadata) { TParams o = new TParams(); JArray paramMetadata; JArray paramsMetadata = parametersMetadata.asJSONArray(); DBXParameter parameter; try { for (int i = 0; i < paramsMetadata.Count; i++) { paramMetadata = paramsMetadata.Value<JArray>(i); parameter = new DBXParameter(); DBXJSONTools.JSONToValueType(new TJSONArray(paramMetadata), parameter); o.addParameter(parameter); } } catch (Exception e) { throw new DBXException(e.Message); } return o; }
/** * Returns a new TParams created by the metadata represented in the specified {@link JSONArray} * @param paramsMetadata * @return TParams */ public static TParams CreateParametersFromMetadata(TJSONArray parametersMetadata) { TParams o = new TParams(); JArray paramMetadata; JArray paramsMetadata = parametersMetadata.asJSONArray(); DBXParameter parameter; try { for (int i = 0; i < paramsMetadata.Count; i++) { paramMetadata = paramsMetadata.Value <JArray>(i); parameter = new DBXParameter(); DBXJSONTools.JSONToValueType(new TJSONArray(paramMetadata), parameter); o.addParameter(parameter); } } catch (Exception e) { throw new DBXException(e.Message); } return(o); }
/** * Execute the request from a specific {@link DSRESTCommand} input, that * will contain useful information to construct the URL as the type of * request, the method to execute and the parameters to be passed. This * information be added to those contained in this object as protocol, * target host, context... They form the complete request to execute. This * method is need to pass parameters correctly or under the parameter * direction, it will be append on the url string or written in the body of * the request. Upon receipt of the response will have to check the * correctness of the received parameters and set them in the * {@link DSRESTCommand}. * * @param command the specific {@link DSRESTCommand} * @param Sender DSAdmin * @param callback Delegate * @param EXCallback Delegate */ public void execute(DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback = null) { TJSONArray _parameters = null; String URL = BuildRequestURL(command); LinkedList <DSRESTParameter> ParametersToSend = new LinkedList <DSRESTParameter>(); if (command.getParameters().Count > 0) { foreach (DSRESTParameter parameter in command.getParameters()) { if (parameter.Direction == DSRESTParamDirection.Input || parameter.Direction == DSRESTParamDirection.InputOutput) { ParametersToSend.AddLast(parameter); } } } if (command.getRequestType() == DSHTTPRequestType.GET || command.getRequestType() == DSHTTPRequestType.DELETE) { foreach (DSRESTParameter parameter in ParametersToSend) { URL += encodeURIComponent(parameter) + '/'; } } else // POST or PUT { bool CanAddParamsToUrl = true; _parameters = new TJSONArray(); foreach (DSRESTParameter parameter in ParametersToSend) { if (CanAddParamsToUrl && isURLParameter(parameter)) { URL += encodeURIComponent(parameter) + '/'; } else // add the json rapresentation in the body { CanAddParamsToUrl = false; parameter.getValue().appendTo(_parameters); } } } HttpWebRequest Client = (HttpWebRequest)WebRequest.Create(URL + "?" + DateTime.Now.Ticks.ToString()); HTTPExecutor _executor = null; try { switch (command.getRequestType()) { case DSHTTPRequestType.GET: { _executor = new HTTPGETExecutor(this, Client, command, Sender, callback, EXCallback); break; } case DSHTTPRequestType.DELETE: { _executor = new HTTPDELETEExecutor(this, Client, command, Sender, callback, EXCallback); break; } case DSHTTPRequestType.POST: { _executor = new HTTPPOSTExecutor(this, Client, command, Sender, callback, EXCallback, _parameters); break; } case DSHTTPRequestType.PUT: { _executor = new HTTPPUTExecutor(this, Client, command, Sender, callback, EXCallback, _parameters); break; } default: { break; } } if (_executor != null) { try { _executor.execute(); } catch (Exception ex) { _executor.stop(); throw new DBXException(ex.Message); } } } catch (DBXException e) { throw new DBXException(e.Message); } }
/** * 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; } }
public HTTPPOSTExecutor(DSRESTConnection connection, HttpWebRequest Client, DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback, TJSONArray parameters) : base(connection, Client, command, Sender, callback, EXCallback) { this._parameters = parameters; Client.Method = "POST"; SetUpHeaders(Client); }
/** * create a DBXValueType from a JArray * @param json JArray with the values * @param vt the DBXValueType to set */ public static void JSONToValueType(TJSONArray arr, DBXValueType vt) { JArray json = (JArray)arr.getInternalObject(); vt.setName(json.Value<string>(0)); vt.setDataType(json.Value<int>(1)); vt.setOrdinal(json.Value<int>(2)); vt.setSubType(json.Value<int>(3)); vt.setScale(json.Value<int>(4)); vt.setSize(json.Value<int>(5)); vt.setPrecision(json.Value<int>(6)); vt.setChildPosition(json.Value<int>(7)); vt.setNullable(json.Value<bool>(8)); vt.setHidden(json.Value<bool>(9)); vt.setParameterDirection(json.Value<int>(10)); vt.setValueParameter(json.Value<bool>(11)); vt.setLiteral(json.Value<bool>(12)); }
/** * 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; } }
/** * Create a TStream from a JArray * @param value * @return TStream */ public static TStream JSONToStream(TJSONArray value) { return TStream.CreateFrom(value); }
/** * Create a TStream from a JArray * @param value * @return TStream */ public static TStream JSONToStream(TJSONArray value) { return(TStream.CreateFrom(value)); }
private void broadcastEvent(JObject json) { List<string> keys = new List<string>(callbacks.Keys); TJSONArray arr = new TJSONArray(json.Value<JArray>("broadcast")); foreach (String callbackskeys in keys) { DBXCallback cb = callbacks[callbackskeys]; if (cb != null) cb.Execute(arr.get(0), Convert.ToInt32(arr.getInt(1).Value)); else throw new DBXException("Invalid callback response"); } }
/** * Create a JSONObject from a DBXParameters * @param dbxParameters * @return JSONObject */ public static TJSONObject DBXParametersToJSONObject(TParams dbxParameters) { TJSONObject json = new TJSONObject(); TJSONObject jsonobj = new TJSONObject(); for (int i = 0; i < dbxParameters.size(); i++) { TJSONArray arr3; try { arr3 = new TJSONArray(); arr3.add(new TJSONString(dbxParameters.getParameter(i).getValue().ToString())); json.addPairs(dbxParameters.getParameter(i).getName(), arr3); } catch (Exception) { } } TJSONArray arr2; arr2 = new TJSONArray(); for (int i = 0; i < dbxParameters.size(); i++) { TJSONArray arr; arr = new TJSONArray(); arr.add(new TJSONString(dbxParameters.getParameter(i).getName())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getDataType())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getOrdinal())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSubType())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getScale())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSize())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getPrecision())); arr.add(new TJSONNumber(dbxParameters.getParameter(i).getChildPosition())); if (dbxParameters.getParameter(i).getNullable()) { arr.add(new TJSONTrue()); } else { arr.add(new TJSONFalse()); } if (dbxParameters.getParameter(i).getHidden()) { arr.add(new TJSONTrue()); } else { arr.add(new TJSONFalse()); } arr.add(new TJSONNumber(dbxParameters.getParameter(i).getParameterDirection())); if (dbxParameters.getParameter(i).getValueParameter()) { arr.add(new TJSONTrue()); } else { arr.add(new TJSONFalse()); } if (dbxParameters.getParameter(i).getLiteral()) { arr.add(new TJSONTrue()); } else { arr.add(new TJSONFalse()); } arr2.add(arr); } try { json.addPairs("table", arr2); } catch (Exception) { } return(json); }
/** * send the the contents of the server response at the "execute" method of our DBXCallback class * @param json the contents of the server response */ private void invokeEvent(JObject json) { TJSONArray arr = new TJSONArray(json.Value<JArray>("invoke")); String callbackID = arr.getAsJsonString(0).getValue(); arr.remove(0); DBXCallback cb = callbacks[callbackID]; if (cb != null) cb.Execute(arr.get(0), Convert.ToInt32(arr.getInt(1).Value)); else throw new DBXException("Invalid callback response"); }
/** * create a DBXValueType from a JArray * @param json JArray with the values to set into DBXValuesType * @return a DBXValueType */ public static DBXValueType JSONToValueType(TJSONArray json) { DBXValueType vt = new DBXValueType(); JSONToValueType(json, vt); return vt; }
/** * Execute the request from a specific {@link DSRESTCommand} input, that * will contain useful information to construct the URL as the type of * request, the method to execute and the parameters to be passed. This * information be added to those contained in this object as protocol, * target host, context... They form the complete request to execute. This * method is need to pass parameters correctly or under the parameter * direction, it will be append on the url string or written in the body of * the request. Upon receipt of the response will have to check the * correctness of the received parameters and set them in the * {@link DSRESTCommand}. * * @param command the specific {@link DSRESTCommand} * @param Sender DSAdmin * @param callback Delegate * @param EXCallback Delegate */ public void execute(DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback = null) { TJSONArray _parameters = null; String URL = BuildRequestURL(command); LinkedList<DSRESTParameter> ParametersToSend = new LinkedList<DSRESTParameter>(); if (command.getParameters().Count > 0) foreach (DSRESTParameter parameter in command.getParameters()) { if (parameter.Direction == DSRESTParamDirection.Input || parameter.Direction == DSRESTParamDirection.InputOutput) ParametersToSend.AddLast(parameter); } if (command.getRequestType() == DSHTTPRequestType.GET || command.getRequestType() == DSHTTPRequestType.DELETE) { foreach (DSRESTParameter parameter in ParametersToSend) URL += encodeURIComponent(parameter) + '/'; } else // POST or PUT { bool CanAddParamsToUrl = true; _parameters = new TJSONArray(); foreach (DSRESTParameter parameter in ParametersToSend) if (CanAddParamsToUrl && isURLParameter(parameter)) URL += encodeURIComponent(parameter) + '/'; else // add the json rapresentation in the body { CanAddParamsToUrl = false; parameter.getValue().appendTo(_parameters); } } HttpWebRequest Client = (HttpWebRequest)WebRequest.Create(URL + "?" + DateTime.Now.Ticks.ToString()); HTTPExecutor _executor = null; try { switch (command.getRequestType()) { case DSHTTPRequestType.GET: { _executor = new HTTPGETExecutor(this, Client, command, Sender, callback, EXCallback); break; } case DSHTTPRequestType.DELETE: { _executor = new HTTPDELETEExecutor(this, Client, command, Sender, callback, EXCallback); break; } case DSHTTPRequestType.POST: { _executor = new HTTPPOSTExecutor(this, Client, command, Sender, callback, EXCallback, _parameters); break; } case DSHTTPRequestType.PUT: { _executor = new HTTPPUTExecutor(this, Client, command, Sender, callback, EXCallback, _parameters); break; } default: { break; } } if (_executor != null) { try { _executor.execute(); } catch (Exception ex) { _executor.stop(); throw new DBXException(ex.Message); } } } catch (DBXException e) { throw new DBXException(e.Message); } }
/** * Create a JSONObject from a DBXReader * @param dbxReader * @return JSONObject */ public static TJSONObject DBXReaderToJSONObject(TDBXReader dbxReader) { TJSONObject json = new TJSONObject(); TJSONArray arr2; TParams columns = dbxReader.getColumns(); try { arr2 = new TJSONArray(); for (int i = 0; i < columns.size(); i++) { arr2.add(columns.getParameter(i).tojson()); // Create the empty JArray for the data. Will be filled after json.addPairs(columns.getParameter(i).getName(), new TJSONArray()); } while (dbxReader.next()) { for (int c = 0; c < columns.size(); c++) dbxReader.getColumns().getParameter(c).getValue().appendTo( json.getJSONArray(columns.getParameter(c) .getName())); } json.addPairs("table", arr2); } catch (Exception) { } return json; }
/** * * @return a JArray with the ByteArray of Stream */ protected TJSONArray StreamToJson() { checkCurrentDBXType(DBXDataTypes.BinaryBlobType); try { byte[] b = DBXTools.streamToByteArray(streamValue); TJSONArray jsArr = new TJSONArray(); for (int i = 0; i < b.Length; i++) jsArr.add(new TJSONNumber(Convert.ToInt32(b[i]))); return jsArr; } catch (Exception e) { throw new DBXException(e.Message); } }