コード例 #1
0
        /// <summary>
        /// Deserialize a request to a JsonDocument
        /// </summary>
        public static JsonDocumentMetadata DeserializeJsonDocumentMetadata(string key,
                                                                           NameValueCollection headers,
                                                                           HttpStatusCode statusCode)
        {
            RavenJObject meta = null;

            try
            {
                meta = headers.FilterHeaders();
            }
            catch (JsonReaderException jre)
            {
                throw new JsonReaderException("Invalid Json Response", jre);
            }
            var    etag             = headers["ETag"];
            string lastModified     = headers[Constants.RavenLastModified] ?? headers[Constants.LastModified];
            var    dateTime         = DateTime.ParseExact(lastModified, new[] { "o", "r" }, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
            var    lastModifiedDate = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);

            return(new JsonDocumentMetadata
            {
                NonAuthoritativeInformation = statusCode == HttpStatusCode.NonAuthoritativeInformation,
                Key = key,
                Etag = HttpExtensions.EtagHeaderToGuid(etag),
                LastModified = lastModifiedDate,
                Metadata = meta
            });
        }
コード例 #2
0
        ///<summary>
        /// Translate a collection of RavenJObject to JsonDocuments
        ///</summary>
        public static IEnumerable <JsonDocument> RavenJObjectsToJsonDocuments(IEnumerable <RavenJObject> responses)
        {
            var list = new List <JsonDocument>();

            foreach (var doc in responses)
            {
                if (doc == null)
                {
                    list.Add(null);
                    continue;
                }
                var metadata = (RavenJObject)doc["@metadata"];
                doc.Remove("@metadata");
                var key = Extract(metadata, "@id", string.Empty);

                var lastModified = GetLastModified(metadata);

                var etag = Extract(metadata, "@etag", Guid.Empty, (string g) => HttpExtensions.EtagHeaderToGuid(g));
                var nai  = Extract(metadata, "Non-Authoritative-Information", false, (string b) => Convert.ToBoolean(b));
                list.Add(new JsonDocument
                {
                    Key            = key,
                    LastModified   = lastModified,
                    Etag           = etag,
                    TempIndexScore = metadata == null ? null : metadata.Value <float?>(Constants.TemporaryScoreValue),
                    NonAuthoritativeInformation = nai,
                    Metadata   = metadata.FilterHeaders(),
                    DataAsJson = doc,
                });
            }
            return(list);
        }
コード例 #3
0
        /// <summary>
        /// Deserialize a request to a JsonDocument
        /// </summary>
        public static JsonDocument DeserializeJsonDocument(string key, RavenJToken requestJson,
                                                           NameValueCollection headers,
                                                           HttpStatusCode statusCode)
        {
            var jsonData = (RavenJObject)requestJson;
            var meta     = headers.FilterHeaders();

            var etag = headers["ETag"];

            return(new JsonDocument
            {
                DataAsJson = jsonData,
                NonAuthoritativeInformation = statusCode == HttpStatusCode.NonAuthoritativeInformation,
                Key = key,
                Etag = HttpExtensions.EtagHeaderToGuid(etag),
                LastModified = GetLastModifiedDate(headers),
                Metadata = meta
            });
        }