コード例 #1
0
ファイル: DBXTools.cs プロジェクト: pnwdelphi/December2012
 /**
   	 * @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 "";
     }
 }
コード例 #2
0
ファイル: DBXTools.cs プロジェクト: svn2github/rest-dataware
 /**
  * @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("");
     }
 }
コード例 #3
0
 /**
 * Set as BinaryBlobType
 */
 public override void SetAsStream(TStream Value)
 {
     streamValue = Value;
     setDBXType(DBXDataTypes.BinaryBlobType);
 }
コード例 #4
0
 /**
 * Set as BlobType
 */
 public override void SetAsBlob(TStream value)
 {
     this.objectValue = value;
     setDBXType(DBXDataTypes.BlobType);
 }
コード例 #5
0
ファイル: DBXValue.cs プロジェクト: svn2github/rest-dataware
 public virtual void SetAsBlob(TStream value)
 {
     throwInvalidAccess();
 }
コード例 #6
0
ファイル: DBXValue.cs プロジェクト: svn2github/rest-dataware
 public virtual void SetAsStream(TStream Value)
 {
     throwInvalidAccess();
 }
コード例 #7
0
 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();
 }
コード例 #8
0
 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();
 }
コード例 #9
0
 /**
  * Create a TStream from a JArray
  * @param value
  * @return TStream
  */
 public static TStream JSONToStream(TJSONArray value)
 {
     return(TStream.CreateFrom(value));
 }
コード例 #10
0
 /**
  * Set as BinaryBlobType
  */
 public override void SetAsStream(TStream Value)
 {
     streamValue = Value;
     setDBXType(DBXDataTypes.BinaryBlobType);
 }
コード例 #11
0
 /**
  * Set as BlobType
  */
 public override void SetAsBlob(TStream value)
 {
     this.objectValue = value;
     setDBXType(DBXDataTypes.BlobType);
 }
コード例 #12
0
            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();
            }
コード例 #13
0
ファイル: DBXValue.cs プロジェクト: pnwdelphi/December2012
 public virtual void SetAsStream(TStream Value)
 {
     throwInvalidAccess();
 }
コード例 #14
0
ファイル: DBXValue.cs プロジェクト: pnwdelphi/December2012
 public virtual void SetAsBlob(TStream value)
 {
     throwInvalidAccess();
 }