Ejemplo n.º 1
0
        public void Execute(Api.Requests.RequestBase apiRequest, ClientArgs args)
        {
            Http.Request httpRequest;
            DateTime start = DateTime.Now;
            Tcp.Params.Buffer receiveBufferSettings, sendBufferSettings;
            Http.HttpConnection.ConnectionDelegate onDisconnect = null, onTimeout = null, onConnect = null;
            Http.HttpConnection.CompletionDelegate onComplete = null;
            Http.HttpConnection.ErrorDelegate onError = null;
            Http.HttpConnection.ProgressDelegate onProgress = null;

            httpRequest = apiRequest.CreateRequest(args.Uri, args.ContentType);

            receiveBufferSettings = new Tcp.Params.Buffer() { Size = args.ReceiveBufferSize, Timeout = args.ReceiveTimeout };
            sendBufferSettings = new Tcp.Params.Buffer() { Size = args.SendBufferSize, Timeout = args.SendTimeout };
            
            onConnect += delegate(Http.HttpConnection sender)
            {
                if (args.OnConnect != null) args.OnConnect(this, sender, DateTime.Now - start);
            };
            onDisconnect += delegate(Http.HttpConnection sender)
            {
                if (args.OnDisconnect != null) args.OnDisconnect(this, sender, DateTime.Now - start);
            };
            onTimeout += delegate(Http.HttpConnection sender)
            {
                if (args.OnTimeout != null) args.OnTimeout(this, sender, DateTime.Now - start);
            };
            onComplete += delegate(Http.HttpConnection sender, Http.Response response)
            {
                Api.Responses.ResponseBase apiResponse = null;

                if (apiRequest.Type == typeof(Api.Requests.Ping))
                {
                    apiResponse = Api.Responses.Pong.BuildFrom(apiRequest);
                }
                else if (apiRequest.Type == typeof(Api.Requests.Authentication))
                {
                    throw new NotImplementedException();
                }

                if (args.OnComplete != null) args.OnComplete(this, sender, response, apiResponse, DateTime.Now - start);
            };
            onError += delegate(Http.HttpConnection sender, string message, Exception exception)
            {
                if (args.OnError != null) args.OnError(this, sender, message, exception, DateTime.Now - start);
            };
            onProgress += delegate(Http.HttpConnection sender, Tcp.DirectionType direction, int packetSize, decimal requestPercentSent, decimal responsePercentReceived)
            {
                if (args.OnProgress != null) args.OnProgress(this, sender, direction, packetSize, DateTime.Now - start, requestPercentSent, responsePercentReceived);
            };

            _client = new Http.Client();

            start = DateTime.Now;
            _client.Execute(httpRequest, receiveBufferSettings, sendBufferSettings, onConnect, onDisconnect, onError, onProgress, onTimeout, onComplete);
        }
Ejemplo n.º 2
0
        public void Execute(Api.Requests.RequestBase apiRequest, ClientArgs args)
        {
            Http.Request httpRequest;
            DateTime     start = DateTime.Now;

            Tcp.Params.Buffer receiveBufferSettings, sendBufferSettings;
            Http.HttpConnection.ConnectionDelegate onDisconnect = null, onTimeout = null, onConnect = null;
            Http.HttpConnection.CompletionDelegate onComplete = null;
            Http.HttpConnection.ErrorDelegate      onError    = null;
            Http.HttpConnection.ProgressDelegate   onProgress = null;

            httpRequest = apiRequest.CreateRequest(args.Uri, args.ContentType);

            receiveBufferSettings = new Tcp.Params.Buffer()
            {
                Size = args.ReceiveBufferSize, Timeout = args.ReceiveTimeout
            };
            sendBufferSettings = new Tcp.Params.Buffer()
            {
                Size = args.SendBufferSize, Timeout = args.SendTimeout
            };

            onConnect += delegate(Http.HttpConnection sender)
            {
                if (args.OnConnect != null)
                {
                    args.OnConnect(this, sender, DateTime.Now - start);
                }
            };
            onDisconnect += delegate(Http.HttpConnection sender)
            {
                if (args.OnDisconnect != null)
                {
                    args.OnDisconnect(this, sender, DateTime.Now - start);
                }
            };
            onTimeout += delegate(Http.HttpConnection sender)
            {
                if (args.OnTimeout != null)
                {
                    args.OnTimeout(this, sender, DateTime.Now - start);
                }
            };
            onComplete += delegate(Http.HttpConnection sender, Http.Response response)
            {
                Api.Responses.ResponseBase apiResponse = null;

                if (apiRequest.Type == typeof(Api.Requests.Ping))
                {
                    apiResponse = Api.Responses.Pong.BuildFrom(apiRequest);
                }
                else if (apiRequest.Type == typeof(Api.Requests.Authentication))
                {
                    throw new NotImplementedException();
                }

                if (args.OnComplete != null)
                {
                    args.OnComplete(this, sender, response, apiResponse, DateTime.Now - start);
                }
            };
            onError += delegate(Http.HttpConnection sender, string message, Exception exception)
            {
                if (args.OnError != null)
                {
                    args.OnError(this, sender, message, exception, DateTime.Now - start);
                }
            };
            onProgress += delegate(Http.HttpConnection sender, Tcp.DirectionType direction, int packetSize, decimal requestPercentSent, decimal responsePercentReceived)
            {
                if (args.OnProgress != null)
                {
                    args.OnProgress(this, sender, direction, packetSize, DateTime.Now - start, requestPercentSent, responsePercentReceived);
                }
            };

            _client = new Http.Client();

            start = DateTime.Now;
            _client.Execute(httpRequest, receiveBufferSettings, sendBufferSettings, onConnect, onDisconnect, onError, onProgress, onTimeout, onComplete);
        }
Ejemplo n.º 3
0
 public Client()
 {
     _client = new Http.Client();
 }
Ejemplo n.º 4
0
 public Client()
 {
     _client = new Http.Client();
 }
Ejemplo n.º 5
0
        public virtual void Execute(int sendTimeout, int receiveTimeout, int sendBufferSize, int receiveBufferSize)
        {
            if (_httpRequest == null)
            {
                throw new InvalidOperationException("The HttpRequest has not been set.");
            }

            Http.HttpConnection.ConnectionDelegate onDisconnect = null, onTimeout = null, onConnect = null;
            Http.HttpConnection.CompletionDelegate onComplete = null;
            Http.HttpConnection.ErrorDelegate      onError    = null;
            Http.HttpConnection.ProgressDelegate   onProgress = null;

            _client = new Http.Client();

            onConnect += delegate(Http.HttpConnection sender)
            {
                Logger.Storage.Debug("Client connected.");
            };
            onDisconnect += delegate(Http.HttpConnection sender)
            {
                Logger.Storage.Debug("Client closed.");
                if (OnClose != null)
                {
                    OnClose(this, _client, sender);
                }
            };
            onTimeout += delegate(Http.HttpConnection sender)
            {
                Logger.Storage.Error("The command timed out.");
                if (OnTimeout != null)
                {
                    OnTimeout(this, _client, sender);
                }
                else
                {
                    throw new UnsupportedException("OnTimeout is not supported");
                }
            };
            onComplete += delegate(Http.HttpConnection sender, Http.Response response)
            {
                Logger.Storage.Debug("The command completed.");
                ReplyBase reply = null;

                try
                {
                    reply = MakeReply(response);
                }
                catch (Exception e)
                {
                    Logger.Storage.Error("An exception occurred while attempting to create the reply object.", e);
                    OnError(this, _client, "An exception occurred while attempting to create the reply object.", e);
                }

                if (reply != null)
                {
                    if (OnComplete != null)
                    {
                        OnComplete(this, _client, sender, reply);
                    }
                    else
                    {
                        throw new UnsupportedException("OnComplete is not supported");
                    }
                }
            };
            onError += delegate(Http.HttpConnection sender, string message, Exception exception)
            {
                Logger.Storage.Error("An error occurred while processing the command.  Message: " + message, exception);
                if (OnError != null)
                {
                    OnError(this, _client, message, exception);
                }
                else
                {
                    throw new UnsupportedException("OnError is not supported");
                }
            };
            onProgress += delegate(Http.HttpConnection sender, Tcp.DirectionType direction, int packetSize, decimal requestPercentSent, decimal responsePercentReceived)
            {
                Logger.Storage.Debug("Progress made on command (send at " + requestPercentSent.ToString() + "%, receive at " + responsePercentReceived.ToString() + "%)");
                if (OnProgress != null)
                {
                    OnProgress(this, _client, sender, direction, packetSize, requestPercentSent, responsePercentReceived);
                }
            };



            Logger.Storage.Debug("Begining command execution for " + GetType().FullName + "...");

            _client.Execute(_httpRequest, new Tcp.Params.Buffer()
            {
                Size = receiveBufferSize, Timeout = receiveTimeout
            },
                            new Tcp.Params.Buffer()
            {
                Size = sendBufferSize, Timeout = sendTimeout
            },
                            onConnect, onDisconnect, onError, onProgress, onTimeout, onComplete);
        }
Ejemplo n.º 6
0
        public virtual void Execute(int sendTimeout, int receiveTimeout, int sendBufferSize, int receiveBufferSize)
        {
            if (_httpRequest == null)
                throw new InvalidOperationException("The HttpRequest has not been set.");

            Http.HttpConnection.ConnectionDelegate onDisconnect = null, onTimeout = null, onConnect = null;
            Http.HttpConnection.CompletionDelegate onComplete = null;
            Http.HttpConnection.ErrorDelegate onError = null;
            Http.HttpConnection.ProgressDelegate onProgress = null;

            _client = new Http.Client();

            onConnect += delegate(Http.HttpConnection sender)
            {
                Logger.Storage.Debug("Client connected.");
            };
            onDisconnect += delegate(Http.HttpConnection sender)
            {
                Logger.Storage.Debug("Client closed.");
                if (OnClose != null) OnClose(this, _client, sender);
            };
            onTimeout += delegate(Http.HttpConnection sender)
            {
                Logger.Storage.Error("The command timed out.");
                if (OnTimeout != null) OnTimeout(this, _client, sender);
                else throw new UnsupportedException("OnTimeout is not supported");
            };
            onComplete += delegate(Http.HttpConnection sender, Http.Response response)
            {
                Logger.Storage.Debug("The command completed.");
                ReplyBase reply = null;

                try
                {
                    reply = MakeReply(response);
                }
                catch (Exception e)
                {
                    Logger.Storage.Error("An exception occurred while attempting to create the reply object.", e);
                    OnError(this, _client, "An exception occurred while attempting to create the reply object.", e);
                }

                if (reply != null)
                {
                    if (OnComplete != null) OnComplete(this, _client, sender, reply);
                    else throw new UnsupportedException("OnComplete is not supported");
                }
            };
            onError += delegate(Http.HttpConnection sender, string message, Exception exception)
            {
                Logger.Storage.Error("An error occurred while processing the command.  Message: " + message, exception);
                if (OnError != null) OnError(this, _client, message, exception);
                else throw new UnsupportedException("OnError is not supported");
            };
            onProgress += delegate(Http.HttpConnection sender, Tcp.DirectionType direction, int packetSize, decimal requestPercentSent, decimal responsePercentReceived)
            {
                Logger.Storage.Debug("Progress made on command (send at " + requestPercentSent.ToString() + "%, receive at " + responsePercentReceived.ToString() + "%)");
                if (OnProgress != null) OnProgress(this, _client, sender, direction, packetSize, requestPercentSent, responsePercentReceived);
            };



            Logger.Storage.Debug("Begining command execution for " + GetType().FullName + "...");

            _client.Execute(_httpRequest, new Tcp.Params.Buffer() { Size = receiveBufferSize, Timeout = receiveTimeout },
                new Tcp.Params.Buffer() { Size = sendBufferSize, Timeout = sendTimeout },
                onConnect, onDisconnect, onError, onProgress, onTimeout, onComplete);
        }