예제 #1
0
        private Task <ElasticsearchResponse <T> > SetResultOnRequestState <T>(Task <ElasticsearchResponse <T> > t, TransportRequestState <T> requestState)
        {
            var tcs = new TaskCompletionSource <ElasticsearchResponse <T> >();

            if (t.Exception != null)
            {
                var authenticationException = t.Exception.InnerException as ElasticsearchAuthenticationException;

                if (authenticationException != null)
                {
                    this.SetAuthenticationExceptionOnRequestState(requestState, authenticationException, tcs);
                }
                else
                {
                    tcs.SetException(t.Exception.Flatten());
                    requestState.SetResult(null);
                }
            }
            else
            {
                tcs.SetResult(t.Result);
                requestState.SetResult(t.Result);
            }
            return(tcs.Task);
        }
예제 #2
0
        /* ASYNC		*** ********************************************/

        public Task <ElasticsearchResponse <T> > DoRequestAsync <T>(string method, string path, object data = null, IRequestParameters requestParameters = null)
        {
            using (var requestState = new TransportRequestState <T>(this.Settings, requestParameters, method, path))
            {
                var bytes = PostData(data);
                requestState.TickSerialization(bytes);

                return(this.DoRequestAsync <T>(requestState)
                       .ContinueWith(t =>
                {
                    var tcs = new TaskCompletionSource <ElasticsearchResponse <T> >();
                    if (t.Exception != null)
                    {
                        tcs.SetException(t.Exception.Flatten());
                        requestState.SetResult(null);
                    }
                    else
                    {
                        tcs.SetResult(t.Result);
                        requestState.SetResult(t.Result);
                    }

                    return tcs.Task;
                }).Unwrap()
                       );
            }
        }
예제 #3
0
        protected void SetAuthenticationExceptionOnRequestState <T>(
            TransportRequestState <T> requestState,
            ElasticsearchAuthenticationException exception,
            TaskCompletionSource <ElasticsearchResponse <T> > tcs)
        {
            var result = this.HandleAuthenticationException(requestState, exception);

            tcs.SetResult(result);
            requestState.SetResult(result);
        }
예제 #4
0
        public OrientdbResponse <T> Request <T>(TransportRequestState <T> requestState, object data = null)
        {
            byte[] postData = PostData(data);
            requestState.TickSerialization(postData);

            OrientdbResponse <T> response = DoRequest(requestState);

            requestState.SetResult(response);
            return(response);
        }
예제 #5
0
        public ElasticsearchResponse <T> Request <T>(TransportRequestState <T> requestState, object data = null)
        {
            var postData = PostData(data);

            requestState.TickSerialization(postData);

            var response = this.DoRequest <T>(requestState);

            requestState.SetResult(response);
            return(response);
        }
예제 #6
0
        /* SYNC			*** ********************************************/

        public ElasticsearchResponse <T> DoRequest <T>(string method, string path, object data = null, IRequestParameters requestParameters = null)
        {
            using (var requestState = new TransportRequestState <T>(this.Settings, requestParameters, method, path))
            {
                var bytes = PostData(data);
                requestState.TickSerialization(bytes);

                var result = this.DoRequest <T>(requestState);

                requestState.SetResult(result);

                return(result);
            }
        }