private Task <ElasticsearchResponse <Stream> > CallIntoConnectionAsync <T>(TransportRequestState <T> requestState) { var uri = requestState.CreatePathOnCurrentNode(); var postData = requestState.PostData; var requestConfiguration = requestState.RequestConfiguration; var method = requestState.Method.ToLowerInvariant(); try { switch (method) { case "head": return(this.Connection.Head(uri, requestConfiguration)); case "get": return(this.Connection.Get(uri, requestConfiguration)); case "post": return(this.Connection.Post(uri, postData, requestConfiguration)); case "put": return(this.Connection.Put(uri, postData, requestConfiguration)); case "delete": return(postData == null || postData.Length == 0 ? this.Connection.Delete(uri, requestConfiguration) : this.Connection.Delete(uri, postData, requestConfiguration)); default: throw new Exception("Unknown HTTP method " + requestState.Method); } } catch (Exception e) { var tcs = new TaskCompletionSource <ElasticsearchResponse <Stream> >(); tcs.SetException(e); return(tcs.Task); } }
private ElasticsearchResponse <Stream> CallInToConnection <T>(TransportRequestState <T> requestState) { var uri = requestState.CreatePathOnCurrentNode(); var postData = requestState.PostData; var requestConfiguration = requestState.RequestConfiguration; switch (requestState.Method.ToLowerInvariant()) { case "post": return(this.Connection.PostSync(uri, postData, requestConfiguration)); case "put": return(this.Connection.PutSync(uri, postData, requestConfiguration)); case "head": return(this.Connection.HeadSync(uri, requestConfiguration)); case "get": return(this.Connection.GetSync(uri, requestConfiguration)); case "delete": return(postData == null || postData.Length == 0 ? this.Connection.DeleteSync(uri, requestConfiguration) : this.Connection.DeleteSync(uri, postData, requestConfiguration)); } throw new Exception("Unknown HTTP method " + requestState.Method); }