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 }); } }
public ConnectionStatus(ConnectionError error) { this.Success = false; if (error != null) { this.Error = error; this.Result = this.Error.Response; } }
public ConnectionStatus(ConnectionError error) { this.Success = false; this.Error = error; }
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; } }
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(); } }