예제 #1
0
 public static TDBXReader createFrom(TJSONObject value)
 {
     TParams parameters = TParams.CreateParametersFromMetadata(value
             .getJSONArray("table"));
     TDBXReader rdr = new TDBXReader(parameters, value);
     return rdr;
 }
예제 #2
0
        /**
         * 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);
        }
예제 #3
0
        /**
         * Loads parameter values from a json object specifying the offset
         * @param params
         * @param value
         * @param Offset
         * @return bool
         */
        public static bool LoadParametersValues(TParams parameters,
                                                TJSONObject value, int Offset)
        {
            JArray       parValue;
            JObject      jvalue = (JObject)value.getInternalObject();
            DBXParameter par;

            if (parameters.size() <= 0)
            {
                return(false);
            }
            for (int i = 0; i < parameters.size(); i++)
            {
                par      = parameters.getParameter(i);
                parValue = jvalue.Value <JArray>(par.getName());
                if (parValue.Count < Offset + 1)
                {
                    return(false);
                }
                if (parValue[Offset] is JArray)
                {
                    DBXJSONTools.JSONtoDBX(parValue[Offset].Value <JArray>(), par.getValue(), "");
                }
                else
                {
                    DBXJSONTools.JSONtoDBX(parValue[Offset].Value <object>(), par.getValue(), "");
                }
            }
            return(true);
        }
예제 #4
0
 /**
  *
  * @param value
  *            a compatible JSONObject that describe a DBXParameters
  * @return a fully configured DBXParameters
  */
 public static TParams CreateFrom(TJSONObject value)
 {
     TParams parameters = CreateParametersFromMetadata(value
             .getJSONArray("table"));
     LoadParametersValues(parameters, value);
     return parameters;
 }
예제 #5
0
        /**
         *
         * @param value
         *            a compatible JSONObject that describe a DBXParameters
         * @return a fully configured DBXParameters
         */
        public static TParams CreateFrom(TJSONObject value)
        {
            TParams parameters = CreateParametersFromMetadata(value
                                                              .getJSONArray("table"));

            LoadParametersValues(parameters, value);
            return(parameters);
        }
예제 #6
0
        public static TDBXReader createFrom(TJSONObject value)
        {
            TParams parameters = TParams.CreateParametersFromMetadata(value
                                                                      .getJSONArray("table"));
            TDBXReader rdr = new TDBXReader(parameters, value);

            return(rdr);
        }
예제 #7
0
        /**
         * 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;
        }
예제 #8
0
        public TJSONObject asJSONObject()
        {
            TJSONObject result       = null;
            long        lastPosition = currentPosition;

            try {
                reset();
                result = DBXJSONTools.DBXReaderToJSONObject(this);
            } finally {
                currentPosition = lastPosition;
            }
            return(result);
        }
예제 #9
0
 /**
  * invokes LoadParametersValues with offset setting to 0.
  * @param params
  * @param value
  */
 public static void LoadParametersValues(TParams parameters, TJSONObject value)
 {
     LoadParametersValues(parameters, value, 0);
 }
예제 #10
0
 public TDBXReader(TParams parameters, TJSONObject value)
     : base()
 {
     internalDataStore = value;
     setParameters(parameters);
 }
예제 #11
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();
 }
예제 #12
0
        /**
         * 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);
        }
예제 #13
0
 public void NotifyObject(String ClientId, String CallbackId, TJSONObject Msg, NotifyObjectCallback callback = null, ExceptionCallback ExCal = null)
 {
     DSRESTCommand cmd = getConnection().CreateCommand();
     cmd.setRequestType(DSHTTPRequestType.POST);
     cmd.setText("DSAdmin.NotifyObject");
     cmd.prepare(get_DSAdmin_NotifyObject_Metadata());
     NotifyObjectDelegate NotifyObjectDel = () => {
       if (callback != null)
       {
     NotifyObjectReturns ret = new NotifyObjectReturns();
     ret.Response = (TJSONObject)cmd.getParameter(3).getValue().GetAsJSONValue();
     ret.returnValue = cmd.getParameter(4).getValue().GetAsBoolean();
     callback.DynamicInvoke(ret);
       }
     };
     cmd.getParameter(0).getValue().SetAsString(ClientId);
     cmd.getParameter(1).getValue().SetAsString(CallbackId);
     cmd.getParameter(2).getValue().SetAsJSONValue(Msg);
     getConnection().execute(cmd, this, NotifyObjectDel, ExCal);
 }
예제 #14
0
 public void BroadcastObjectToChannel(String ChannelName, TJSONObject Msg, BroadcastObjectToChannelCallback callback = null, ExceptionCallback ExCal = null)
 {
     DSRESTCommand cmd = getConnection().CreateCommand();
     cmd.setRequestType(DSHTTPRequestType.POST);
     cmd.setText("DSAdmin.BroadcastObjectToChannel");
     cmd.prepare(get_DSAdmin_BroadcastObjectToChannel_Metadata());
     BroadcastObjectToChannelDelegate BroadcastObjectToChannelDel = () => {
       if (callback != null)
       {
     callback.DynamicInvoke(cmd.getParameter(2).getValue().GetAsBoolean());
       }
     };
     cmd.getParameter(0).getValue().SetAsString(ChannelName);
     cmd.getParameter(1).getValue().SetAsJSONValue(Msg);
     getConnection().execute(cmd, this, BroadcastObjectToChannelDel, ExCal);
 }
예제 #15
0
 /**
  * invokes LoadParametersValues with offset setting to 0.
  * @param params
  * @param value
  */
 public static void LoadParametersValues(TParams parameters, TJSONObject value)
 {
     LoadParametersValues(parameters, value, 0);
 }
예제 #16
0
        /**
         * Loads parameter values from a json object specifying the offset
         * @param params
         * @param value
         * @param Offset
         * @return bool
         */
        public static bool LoadParametersValues(TParams parameters,
			    TJSONObject value, int Offset)
        {
            JArray parValue;
            JObject jvalue = (JObject)value.getInternalObject();
            DBXParameter par;
            if (parameters.size() <= 0) {
                return false;
            }
            for (int i = 0; i < parameters.size(); i++) {
                par = parameters.getParameter(i);
                parValue = jvalue.Value<JArray>(par.getName());
                if (parValue.Count < Offset + 1)
                    return false;
                if (parValue[Offset] is JArray)
                    DBXJSONTools.JSONtoDBX(parValue[Offset].Value<JArray>(), par.getValue(), "");
                else
                    DBXJSONTools.JSONtoDBX(parValue[Offset].Value<object>(), par.getValue(), "");
            }
            return true;
        }
예제 #17
0
 public TDBXReader(TParams parameters, TJSONObject value) : base()
 {
     internalDataStore = value;
     setParameters(parameters);
 }
예제 #18
0
        /**
          	 * 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;
        }
예제 #19
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();
            }