public void HandleResponse(GetResponse response)
        {
            var getDocumentResult = JsonDeserializationClient.GetDocumentsResult((BlittableJsonReaderObject)response.Result);

            var finalResults = new Dictionary <string, T>(StringComparer.OrdinalIgnoreCase);

            foreach (BlittableJsonReaderObject document in getDocumentResult.Results)
            {
                var newDocumentInfo = DocumentInfo.GetNewDocumentInfo(document);
                _sessionOperations.DocumentsById.Add(newDocumentInfo);
                if (newDocumentInfo.Id == null)
                {
                    continue; // is this possible?
                }
                if (_sessionOperations.IsDeleted(newDocumentInfo.Id))
                {
                    finalResults[newDocumentInfo.Id] = default(T);
                    continue;
                }
                DocumentInfo doc;
                if (_sessionOperations.DocumentsById.TryGetValue(newDocumentInfo.Id, out doc))
                {
                    finalResults[newDocumentInfo.Id] = _sessionOperations.TrackEntity <T>(doc);
                    continue;
                }

                finalResults[newDocumentInfo.Id] = default(T);
            }

            Result = finalResults;
        }
        public void HandleResponse(GetResponse response)
        {
            if (response.ForceRetry)
            {
                Result        = null;
                RequiresRetry = true;
                return;
            }

            switch (response.StatusCode)
            {
            case HttpStatusCode.NotModified:
                Result = (default(T), _changeVector);     // value not changed
                return;

            case HttpStatusCode.NotFound:
                _session.RegisterMissing(_id);
                Result = default((T, string));
                return;
            }

            if (response.Result != null)
            {
                var etag         = response.Headers[Constants.Headers.Etag];
                var res          = JsonDeserializationClient.ConditionalGetResult((BlittableJsonReaderObject)response.Result);
                var documentInfo = DocumentInfo.GetNewDocumentInfo((BlittableJsonReaderObject)res.Results[0]);
                var r            = _session.TrackEntity <T>(documentInfo);

                Result = (r, etag);
                return;
            }

            Result = null;
            _session.RegisterMissing(_id);
        }
Beispiel #3
0
 public void SetResult(GetDocumentResult result)
 {
     foreach (BlittableJsonReaderObject document in result.Results)
     {
         var newDocumentInfo = DocumentInfo.GetNewDocumentInfo(document);
         _session.DocumentsById.Add(newDocumentInfo);
         _returnedIds.Add(newDocumentInfo.Id);
     }
 }
Beispiel #4
0
        public IList <T> Complete <T>()
        {
            var queryResult = _currentQueryResults.CreateSnapshot();

            foreach (BlittableJsonReaderObject include in queryResult.Includes)
            {
                var newDocumentInfo = DocumentInfo.GetNewDocumentInfo(include);
                _session.includedDocumentsByKey[newDocumentInfo.Id] = newDocumentInfo;
            }

            var usedTransformer = string.IsNullOrEmpty(_indexQuery.Transformer) == false;
            var list            = new List <T>();

            foreach (BlittableJsonReaderObject document in queryResult.Results)
            {
                if (usedTransformer)
                {
                    BlittableJsonReaderArray values;
                    if (document.TryGet("$values", out values) == false)
                    {
                        throw new InvalidOperationException("Transformed document must have a $values property");
                    }

                    list.AddRange(TransformerHelpers.ParseValuesFromBlittableArray <T>(_session, values));

                    continue;
                }

                BlittableJsonReaderObject metadata;
                string id;
                if (document.TryGet(Constants.Metadata.Key, out metadata) == false)
                {
                    throw new InvalidOperationException("Document must have a metadata");
                }
                if (metadata.TryGet(Constants.Metadata.Id, out id) == false)
                {
                    throw new InvalidOperationException("Document must have an id");
                }

                list.Add(_session.TrackEntity <T>(id, document, metadata, _disableEntitiesTracking));
            }

            if (_disableEntitiesTracking == false)
            {
                _session.RegisterMissingIncludes(queryResult.Results, _includes);
            }

            if (_transformResults == null)
            {
                return(list);
            }

            return(_transformResults(_indexQuery, list.Cast <object>()).Cast <T>().ToList());
        }
        public void SetResult(GetDocumentResult result)
        {
            // We don't want to track transformed entities.
            if (_transformer != null)
            {
                return;
            }

            foreach (BlittableJsonReaderObject document in result.Results)
            {
                var newDocumentInfo = DocumentInfo.GetNewDocumentInfo(document);
                _session.DocumentsById[newDocumentInfo.Id] = newDocumentInfo;
                _returnedIds.Add(newDocumentInfo.Id);
            }
        }
        public void SetResult(GetDocumentResult result)
        {
            if (result.Includes != null)
            {
                foreach (BlittableJsonReaderObject include in result.Includes)
                {
                    var newDocumentInfo = DocumentInfo.GetNewDocumentInfo(include);
                    _session.includedDocumentsByKey[newDocumentInfo.Id] = newDocumentInfo;
                }
            }

            if (_includes != null && _includes.Length > 0)
            {
                _session.RegisterMissingIncludes(result.Results, _includes);
            }
        }
Beispiel #7
0
        public void SetResult(GetDocumentResult result)
        {
            if (result == null)
            {
                return;
            }

            _session.RegisterIncludes(result.Includes);

            foreach (BlittableJsonReaderObject document in result.Results)
            {
                if (document == null)
                {
                    continue;
                }

                var newDocumentInfo = DocumentInfo.GetNewDocumentInfo(document);
                _session.DocumentsById.Add(newDocumentInfo);
            }

            _session.RegisterMissingIncludes(result.Results, result.Includes, _includes);
        }