/** * @param ins the input stream * @return a String that represents the param Stream */ public static String convertStreamToString(TStream ins) { if (ins != null) { StreamReader reader = new StreamReader(ins); return reader.ReadToEnd(); } else { return ""; } }
/** * @param ins the input stream * @return a String that represents the param Stream */ public static String convertStreamToString(TStream ins) { if (ins != null) { StreamReader reader = new StreamReader(ins); return(reader.ReadToEnd()); } else { return(""); } }
/** * Set as BinaryBlobType */ public override void SetAsStream(TStream Value) { streamValue = Value; setDBXType(DBXDataTypes.BinaryBlobType); }
/** * Set as BlobType */ public override void SetAsBlob(TStream value) { this.objectValue = value; setDBXType(DBXDataTypes.BlobType); }
public virtual void SetAsBlob(TStream value) { throwInvalidAccess(); }
public virtual void SetAsStream(TStream Value) { throwInvalidAccess(); }
public override void execute() { if (_parameters == null) throw new DBXException( "Parameters cannot be null in a POST request"); TJSONObject body = new TJSONObject(); body.addPairs("_parameters", _parameters); Client.BeginGetRequestStream((IAsyncResult asynchronousResult) => { Stream postStream = Client.EndGetRequestStream(asynchronousResult); byte[] postBytes = Encoding.UTF8.GetBytes(body.ToString()); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); Client.BeginGetResponse((IAsyncResult asynchResult) => { HttpWebRequest request = (HttpWebRequest)asynchResult.AsyncState; HttpWebResponse response = null; try { response = (HttpWebResponse)request.EndGetResponse(asynchResult); } catch (WebException e) { try { Stream s = ((HttpWebResponse)e.Response).GetResponseStream(); TextReader txt = new StreamReader(s); if (s.Length > 0) { connection.throwExceptionIfNeeded(JObject.Parse(txt.ReadToEnd())); } else { throw new DBXException(e.Message); } } catch (Exception ex) { if (EXCallback != null) connection.syncContext.Send(new SendOrPostCallback(x => EXCallback.DynamicInvoke(ex)), null); else if (Sender.BaseExCal != null) connection.syncContext.Send(new SendOrPostCallback(x => Sender.BaseExCal.DynamicInvoke(ex)), null); else throw ex; return; } } finally { syncStop(); } connection.setSessionIdentifier(response); connection.throwExceptionIfNeeded(response); if (!isThereOnlyOneStreamInOutput(command.getParameters())) { string resultString = null; using (StreamReader rdr = new StreamReader(response.GetResponseStream())) { resultString = rdr.ReadToEnd(); rdr.Close(); } response.Close(); try { JObject obj = JObject.Parse(resultString); JArray arr = obj.Value<JArray>("result"); int returnParIndex = 0; foreach (DSRESTParameter param in command.getParameters()) { if ((param.Direction == DSRESTParamDirection.ReturnValue) || (param.Direction == DSRESTParamDirection.InputOutput) || (param.Direction == DSRESTParamDirection.Output)) { DBXJSONTools.JSONtoDBX(arr[returnParIndex], param.getValue(), param.TypeName); returnParIndex++; } // if } // for } catch (DBXException e) { throw new DBXException(e.Message); } if (!(_TimedOut)) connection.syncContext.Send(new SendOrPostCallback(x => callback.DynamicInvoke()), null); } else { Stream inputstream = response.GetResponseStream(); byte[] b1 = DBXTools.streamToByteArray(inputstream); inputstream.Close(); response.Close(); TStream ins = new TStream(b1); foreach (DSRESTParameter param in command.getParameters()) { if ((param.Direction == DSRESTParamDirection.ReturnValue) || (param.Direction == DSRESTParamDirection.InputOutput) || (param.Direction == DSRESTParamDirection.Output)) { if (param.TypeName.StartsWith("TDBX") && param.TypeName.EndsWith("Value")) { param.getValue().GetAsDBXValue().SetAsStream(ins); } else { param.getValue().SetAsStream(ins); } if (!(_TimedOut)) connection.syncContext.Send(new SendOrPostCallback(x => callback.DynamicInvoke()), null); } } }; }, Client); }, Client); start(); }
public override void execute() { Client.BeginGetResponse((IAsyncResult asynchResult) => { HttpWebRequest request = (HttpWebRequest)asynchResult.AsyncState; HttpWebResponse response = null; try { response = (HttpWebResponse)request.EndGetResponse(asynchResult); } catch (WebException e) { try { Stream s = ((HttpWebResponse)e.Response).GetResponseStream(); TextReader txt = new StreamReader(s); if (s.Length > 0) { connection.throwExceptionIfNeeded(JObject.Parse(txt.ReadToEnd())); } else { throw new WebException(e.Message); } } catch (Exception ex) { if (EXCallback != null) connection.syncContext.Send(new SendOrPostCallback(x => EXCallback.DynamicInvoke(ex)), null); else connection.syncContext.Send(new SendOrPostCallback(x => Sender.BaseExCal.DynamicInvoke(ex)), null); return; } } finally { syncStop(); } connection.throwExceptionIfNeeded(response); connection.setSessionIdentifier(response); if (!isThereOnlyOneStreamInOutput(command.getParameters())) { string resultString = null; using (StreamReader rdr = new StreamReader(response.GetResponseStream())) resultString = rdr.ReadToEnd(); try { JObject obj = JObject.Parse(resultString); JArray arr = obj.Value<JArray>("result"); int returnParIndex = 0; foreach (DSRESTParameter param in command.getParameters()) { if ((param.Direction == DSRESTParamDirection.ReturnValue) || (param.Direction == DSRESTParamDirection.InputOutput) || (param.Direction == DSRESTParamDirection.Output)) { DBXJSONTools.JSONtoDBX(arr[returnParIndex], param.getValue(), param.TypeName); returnParIndex++; } // if } // for } catch (DBXException e) { throw new DBXException(e.Message); } if (!(_TimedOut)) connection.syncContext.Send(new SendOrPostCallback(x => callback.DynamicInvoke()), null); } else { Stream inputstream = response.GetResponseStream(); byte[] b1 = DBXTools.streamToByteArray(inputstream); TStream ins = new TStream(b1); foreach (DSRESTParameter param in command.getParameters()) { if ((param.Direction == DSRESTParamDirection.ReturnValue) || (param.Direction == DSRESTParamDirection.InputOutput) || (param.Direction == DSRESTParamDirection.Output)) { param.getValue().SetAsStream(ins); if (!(_TimedOut)) connection.syncContext.Send(new SendOrPostCallback(x => callback.DynamicInvoke()), null); } } } }, Client); start(); }
/** * Create a TStream from a JArray * @param value * @return TStream */ public static TStream JSONToStream(TJSONArray value) { return(TStream.CreateFrom(value)); }
public override void execute() { if (_parameters == null) { throw new DBXException( "Parameters cannot be null in a POST request"); } TJSONObject body = new TJSONObject(); body.addPairs("_parameters", _parameters); Client.BeginGetRequestStream((IAsyncResult asynchronousResult) => { Stream postStream = Client.EndGetRequestStream(asynchronousResult); byte[] postBytes = Encoding.UTF8.GetBytes(body.ToString()); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); Client.BeginGetResponse((IAsyncResult asynchResult) => { HttpWebRequest request = (HttpWebRequest)asynchResult.AsyncState; HttpWebResponse response = null; try { response = (HttpWebResponse)request.EndGetResponse(asynchResult); } catch (WebException e) { try { Stream s = ((HttpWebResponse)e.Response).GetResponseStream(); TextReader txt = new StreamReader(s); if (s.Length > 0) { connection.throwExceptionIfNeeded(JObject.Parse(txt.ReadToEnd())); } else { throw new DBXException(e.Message); } } catch (Exception ex) { if (EXCallback != null) { connection.syncContext.Send(new SendOrPostCallback(x => EXCallback.DynamicInvoke(ex)), null); } else if (Sender.BaseExCal != null) { connection.syncContext.Send(new SendOrPostCallback(x => Sender.BaseExCal.DynamicInvoke(ex)), null); } else { throw ex; } return; } } finally { syncStop(); } connection.setSessionIdentifier(response); connection.throwExceptionIfNeeded(response); if (!isThereOnlyOneStreamInOutput(command.getParameters())) { string resultString = null; using (StreamReader rdr = new StreamReader(response.GetResponseStream())) { resultString = rdr.ReadToEnd(); rdr.Close(); } response.Close(); try { JObject obj = JObject.Parse(resultString); JArray arr = obj.Value <JArray>("result"); int returnParIndex = 0; foreach (DSRESTParameter param in command.getParameters()) { if ((param.Direction == DSRESTParamDirection.ReturnValue) || (param.Direction == DSRESTParamDirection.InputOutput) || (param.Direction == DSRESTParamDirection.Output)) { DBXJSONTools.JSONtoDBX(arr[returnParIndex], param.getValue(), param.TypeName); returnParIndex++; } // if } // for } catch (DBXException e) { throw new DBXException(e.Message); } if (!(_TimedOut)) { connection.syncContext.Send(new SendOrPostCallback(x => callback.DynamicInvoke()), null); } } else { Stream inputstream = response.GetResponseStream(); byte[] b1 = DBXTools.streamToByteArray(inputstream); inputstream.Close(); response.Close(); TStream ins = new TStream(b1); foreach (DSRESTParameter param in command.getParameters()) { if ((param.Direction == DSRESTParamDirection.ReturnValue) || (param.Direction == DSRESTParamDirection.InputOutput) || (param.Direction == DSRESTParamDirection.Output)) { if (param.TypeName.StartsWith("TDBX") && param.TypeName.EndsWith("Value")) { param.getValue().GetAsDBXValue().SetAsStream(ins); } else { param.getValue().SetAsStream(ins); } if (!(_TimedOut)) { connection.syncContext.Send(new SendOrPostCallback(x => callback.DynamicInvoke()), null); } } } }; }, Client); }, Client); start(); }