protected virtual void OnSuccessfulResponse(DocumentResponse response, HttpResponseMessage httpResponse)
        {
            using (var content = httpResponse.Content.ReadAsStream())
            {
                if (ContentShouldHaveIdAndRev(httpResponse.RequestMessage))
                    PopulateDocumentHeaderFromResponseStream(response, content);
                else
                {
                    PopulateMissingIdFromRequestUri(response, httpResponse);
                    PopulateMissingRevFromRequestHeaders(response, httpResponse);
                }

                content.Position = 0;

                var sb = new StringBuilder();
                using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding))
                {
                    while (!reader.EndOfStream)
                    {
                        sb.Append(reader.ReadLine());
                    }
                }
                response.Content = sb.ToString();
                sb.Clear();
            }
        }
        public virtual async void Materialize(DocumentResponse response, HttpResponseMessage httpResponse)
        {
            if(response.RequestMethod != HttpMethod.Get)
                throw new ArgumentException(GetType().Name + " only supports materializing GET responses for raw documents.");

            using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait())
            {
                response.Content = content.ReadAsString();

                content.Position = 0;
                var t = Serializer.Deserialize<Temp>(content);
                response.Id = t._id;
                response.Rev = t._rev;
                response.Conflicts = t._conflicts;

                SetMissingIdFromRequestUri(response, httpResponse.RequestMessage);
                SetMissingRevFromRequestHeaders(response, httpResponse.Headers);
            }
        }
        protected virtual void OnSuccessfulDocumentResponseContentMaterializer(HttpResponseMessage response, DocumentResponse result)
        {
            using (var content = response.Content.ReadAsStream())
            {
                if (ContentShouldHaveIdAndRev(response.RequestMessage))
                    ResponseMaterializer.PopulateDocumentHeaderResponse(result, content);
                else
                {
                    AssignMissingIdFromRequestUri(response, result);
                    AssignMissingRevFromRequestHeaders(response, result);
                }

                content.Position = 0;
                using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding))
                {
                    result.Content = reader.ReadToEnd();
                }
            }
        }
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        /// <summary>
        /// Actiunea ce intoarce un fisier XML, avand ca date rezumatul documentului impreuna cu alte
        /// informatii generate asupra documentului.
        /// </summary>
        /// <param name="id">Id-ul documentului.</param>
        public ActionResult Summary(int? id)
        {
            /*verificam daca a fost specificat documentul*/
            if (id == null)
                return View("Index", "Home");

            /*documentul propriuzis*/
            DocumentResponse doc = new DocumentResponse();

            /*luam documentul cautat*/
            try
            {
                doc.Content = this._documentManager.GetDocument(id ?? 0, DocumentManager.TypeSummary);
                doc.State = (doc.Content != null) ? DocumentResponse.Status.Finished : DocumentResponse.Status.Parsing;
            }
            catch (DocumentException)
            {
                doc.State = DocumentResponse.Status.NotFound;
            }

            return new XmlResult(doc);
        }
 protected virtual void SetMissingRevFromRequestHeaders(DocumentResponse response, HttpResponseHeaders responseHeaders)
 {
     if (string.IsNullOrWhiteSpace(response.Rev))
         response.Rev = responseHeaders.GetETag();
 }
 protected virtual void SetMissingIdFromRequestUri(DocumentResponse response, HttpRequestMessage request)
 {
     if (string.IsNullOrWhiteSpace(response.Id) && request.Method != HttpMethod.Post)
         response.Id = request.ExtractIdFromUri(false);
 }