示例#1
0
        public void RaiseCallBack(Exception e)
        {
            var error = new ConnectionError(e);

            if (e is WebException)
            {
                error.Type = ConnectionErrorType.Server;
                var oe = (WebException)e;
                if (oe.Response != null)
                {
                    error.HttpStatusCode = ((System.Net.HttpWebResponse)(oe.Response)).StatusCode; }
                else
                {
                    error.ExceptionMessage = "Could not connect to server: " + Connection.Address.ToString();
                }
            }
            else if (e is Exception)
                error.Type = ConnectionErrorType.Client;

            if (!this.RaisedCallback)
            {
                this.RaisedCallback = true;
                if (this.Callback != null)
                    this.Callback(new ConnectionStatus(error) { Request = PostData });
            }
        }
示例#2
0
 public ConnectionStatus(ConnectionError error)
 {
     this.Success = false;
     if (error != null)
     {
         this.Error  = error;
         this.Result = this.Error.Response;
     }
 }
示例#3
0
 public ConnectionStatus(ConnectionError error)
 {
     this.Success = false;
     if (error != null)
     {
         this.Error = error;
         this.Result = this.Error.Response;
     }
 }
示例#4
0
 public ConnectionStatus(ConnectionError error)
 {
     this.Success = false;
     this.Error = error;
 }
示例#5
0
文件: Connection.cs 项目: rudimk/NEST
        private ConnectionError GetConnectionErrorFromWebException(WebException e, out string result)
        {
            result = "";
            using (var r = e.Response)
            {

                if (e.Response != null)
                {
                    using (var d = e.Response.GetResponseStream())
                    {
                        result = new StreamReader(d).ReadToEnd();
                    }
                }

                ConnectionError error;
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    error = new ConnectionError(e, result)
                    {
                        HttpStatusCode = HttpStatusCode.InternalServerError
                    };
                }
                else
                {
                    error = new ConnectionError(e, result);
                }
                return error;
            }
        }
示例#6
0
        private ConnectionStatus Execute(RestRequest restRequest)
        {
            //RestResponse result = GetClient().execute(restRequest);
            //

            if (!this._resourceLock.WaitOne(this._timeout))
            {
                var m = "Could not start the thrift operation before the timeout of " + this._timeout + "ms completed while waiting for the semaphore";
                return new ConnectionStatus(new TimeoutException(m));
            }
            try
            {
                Rest.Client client = null;
                if (!this._clients.TryDequeue(out client))
                {
                    var m = string.Format("Could dequeue a thrift client from internal socket pool of size {0}", this._poolSize);
                    var status = new ConnectionStatus(new Exception(m));
                    return status;
                }
                try
                {
                    if (!client.InputProtocol.Transport.IsOpen)
                        client.InputProtocol.Transport.Open();

                    var result = client.execute(restRequest);
                    if (result.Status == Status.OK || result.Status == Status.CREATED || result.Status == Status.ACCEPTED)
                        return new ConnectionStatus(DecodeStr(result.Body));
                    else
                    {
                        var connectionError = new ConnectionError(DecodeStr(result.Body), (int)result.Status)
                        {
                            ExceptionMessage = Enum.GetName(typeof (Status), result.Status)
                        };
                        return new ConnectionStatus(connectionError);
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    //make sure we make the client available again.
                    this._clients.Enqueue(client);
                }

            }
            catch (Exception e)
            {
                return new ConnectionStatus(e);
            }
            finally
            {
                this._resourceLock.Release();
            }
        }
示例#7
0
 public ConnectionStatus(ConnectionError error)
 {
     this.Success = false;
     this.Error   = error;
 }