コード例 #1
0
ファイル: DSProxy.cs プロジェクト: moto4321/Master201907
            public void LoginUser(String UserName, LoginUserCallback callback = null, ExceptionCallback ExCal = null)
            {
                DSRESTCommand cmd = getConnection().CreateCommand();

                cmd.setRequestType(DSHTTPRequestType.GET);
                cmd.setText("TCompanyTweet.LoginUser");
                cmd.prepare(get_TCompanyTweet_LoginUser_Metadata());
                InternalConnectionDelegate LoginUserDel = () =>
                {
                    if (callback != null)
                    {
                        try
                        {
                            LoginUserReturns ret = new LoginUserReturns();
                            ret.ReturnMessage = cmd.getParameter(1).getValue().GetAsString();
                            ret.returnValue   = cmd.getParameter(2).getValue().GetAsBoolean();
                            callback.DynamicInvoke(ret);
                        }
                        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().SetAsString(UserName);
                getConnection().execute(cmd, this, LoginUserDel, ExCal);
            }
コード例 #2
0
ファイル: DSProxy.cs プロジェクト: moto4321/Master201907
            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);
            }
コード例 #3
0
ファイル: DSProxy.cs プロジェクト: moto4321/Master201907
            public void Logout(LogoutCallback callback = null, ExceptionCallback ExCal = null)
            {
                DSRESTCommand cmd = getConnection().CreateCommand();

                cmd.setRequestType(DSHTTPRequestType.GET);
                cmd.setText("TCompanyTweet.Logout");
                cmd.prepare(get_TCompanyTweet_Logout_Metadata());
                InternalConnectionDelegate LogoutDel = () =>
                {
                    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);
                            }
                        }
                    }
                };

                getConnection().execute(cmd, this, LogoutDel, ExCal);
            }
コード例 #4
0
        /**
         * Collects all the informations contained in this object like the target
         * host, the protocol; the more information contained in
         * {@link DSRESTCommand} input parameter as the type of request, the method
         * to call then to return the url to run
         *
         *
         * @param the
         *            specific DSRESTCommand
         * @return a requested url
         */

        private String BuildRequestURL(DSRESTCommand command)
        {
            String LPathPrefix = getUrlPath();
            int    LPort       = getPort();
            String LHost       = getHost();
            String LMethodName = command.getText();
            String LProtocol   = getProtocol();

            if (LProtocol.Equals(""))
            {
                LProtocol = "http";
            }
            if (LHost.Equals(""))
            {
                LHost = "localhost";
            }
            if (!LPathPrefix.Equals(""))
            {
                LPathPrefix = "/" + LPathPrefix;
            }
            String LPortString = "";

            if (LPort > 0)
            {
                LPortString = ":" + Convert.ToInt32(LPort);
            }
            if (command.getRequestType() == DSHTTPRequestType.GET ||
                command.getRequestType() == DSHTTPRequestType.DELETE)
            {
                LMethodName = LMethodName.Substring(0, LMethodName.IndexOf(".")) + "/" + LMethodName.Substring(LMethodName.IndexOf(".") + 1);
                LMethodName = LMethodName.Replace("\"", "");
            }
            else
            {
                LMethodName = LMethodName.Substring(0, LMethodName.IndexOf(".")) + "/%22" + LMethodName.Substring(LMethodName.IndexOf(".") + 1) + "%22";
                LMethodName = LMethodName.Replace("\"", "%22");
            }
            String LContext = getContext();

            if (LContext.Equals(""))
            {
                LContext = "datasnap/";
            }
            String LUrl = LProtocol + "://" +
                          encodeURIComponent(LHost) + LPortString + LPathPrefix + "/" + LContext + "rest/" + LMethodName + "/";

            SessionID = getSessionID();
            return(LUrl);
        }
コード例 #5
0
            protected HTTPExecutor(DSRESTConnection connection, HttpWebRequest Client, DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback)
            {
                this.connection = connection;
                this.Client     = Client;
                this.command    = command;
                this.Sender     = Sender;
                this.callback   = callback;
                this.EXCallback = EXCallback;
                this._TimedOut  = false;
                this._Timer     = null;

                //don't enable timeout if the request is for a heavyweight callback. Heavyweight callbacks should be timed out
                //with custom code, which uses a call to close the channel with the server when the timeout happens.
                if (connection.getConnectionTimeout() > 0 && !isHeavyweightCallbackRequest(Client))
                {
                    connection.syncContext.Send(new SendOrPostCallback(x => initTimer()), null);
                }
            }
コード例 #6
0
            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);
            }
コード例 #7
0
 public HTTPGETExecutor(DSRESTConnection connection, HttpWebRequest Client, DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback)
     : base(connection, Client, command, Sender, callback, EXCallback)
 {
     Client.Method = "GET";
     SetUpHeaders(Client);
 }
コード例 #8
0
            protected HTTPExecutor(DSRESTConnection connection, HttpWebRequest Client, DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback)
            {
                this.connection = connection;
                this.Client = Client;
                this.command = command;
                this.Sender = Sender;
                this.callback = callback;
                this.EXCallback = EXCallback;
                this._TimedOut = false;
                this._Timer = null;

                //don't enable timeout if the request is for a heavyweight callback. Heavyweight callbacks should be timed out
                //with custom code, which uses a call to close the channel with the server when the timeout happens.
                if (connection.getConnectionTimeout() > 0 && !isHeavyweightCallbackRequest(Client))
                {
                    connection.syncContext.Send(new SendOrPostCallback(x => initTimer()), null);
                }
            }
コード例 #9
0
 /**
   	 * Collects all the informations contained in this object like the target
   	 * host, the protocol; the more information contained in
   	 * {@link DSRESTCommand} input parameter as the type of request, the method
   	 * to call then to return the url to run
   	 *
   	 *
   	 * @param the
   	 *            specific DSRESTCommand
   	 * @return a requested url
   	 */
 private String BuildRequestURL(DSRESTCommand command)
 {
     String LPathPrefix = getUrlPath();
     int LPort = getPort();
     String LHost = getHost();
     String LMethodName = command.getText();
     String LProtocol = getProtocol();
     if (LProtocol.Equals(""))
         LProtocol = "http";
     if (LHost.Equals(""))
         LHost = "localhost";
     if (!LPathPrefix.Equals(""))
         LPathPrefix = "/" + LPathPrefix;
     String LPortString = "";
     if (LPort > 0)
         LPortString = ":" + Convert.ToInt32(LPort);
     if (command.getRequestType() == DSHTTPRequestType.GET
         || command.getRequestType() == DSHTTPRequestType.DELETE)
     {
         LMethodName = LMethodName.Substring(0, LMethodName.IndexOf(".")) + "/" + LMethodName.Substring(LMethodName.IndexOf(".") + 1);
         LMethodName = LMethodName.Replace("\"", "");
     }
     else
     {
         LMethodName = LMethodName.Substring(0, LMethodName.IndexOf(".")) + "/%22" + LMethodName.Substring(LMethodName.IndexOf(".") + 1) + "%22";
         LMethodName = LMethodName.Replace("\"", "%22");
     }
     String LContext = getContext();
     if (LContext.Equals(""))
         LContext = "datasnap/";
     String LUrl = LProtocol + "://" +
             encodeURIComponent(LHost) + LPortString + LPathPrefix + "/" + LContext + "rest/" + LMethodName + "/";
     SessionID = getSessionID();
     return LUrl;
 }
コード例 #10
0
        /**
         * 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);
            }
        }
コード例 #11
0
            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);
            }
コード例 #12
0
 public HTTPGETExecutor(DSRESTConnection connection, HttpWebRequest Client, DSRESTCommand command, DSAdmin Sender, Delegate callback, Delegate EXCallback)
     : base(connection, Client, command, Sender, callback, EXCallback)
 {
     Client.Method = "GET";
     SetUpHeaders(Client);
 }
コード例 #13
0
        /**
         * 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);
            }
        }