Esempio n. 1
0
        public ExplainResult Explain(ISearch search, string type, string id)
        {
            IJsonRequest request = CommandContext.RequestFactory.CreateRequest(GetUrl(type, id), HttpVerbs.Post, ExplicitRequestTimeout);

            try
            {
                var context = new SearchContext();
                search.ApplyActions(context);
                string requestBody = CommandContext.Serializer.Serialize(context.RequestBody);
                request.WriteBody(requestBody);
                using (var stringReader = new StringReader(request.GetResponse()))
                {
                    ExplainResult explain = CommandContext.Serializer.Deserialize <ExplainResult>(new JsonTextReader(stringReader));
                    return(explain);
                }
            }
            catch (WebException ex)
            {
                string message = ex.Message;
                if (ex.Response.IsNotNull())
                {
                    string end = new StreamReader(ex.Response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
                    message = message + Environment.NewLine + end;
                }
                throw new WebException(message, ex);
            }
        }