Exemplo n.º 1
0
 public void SetResult(BlittableArrayResult result)
 {
 }
Exemplo n.º 2
0
        public void SetResult(BlittableArrayResult result)
        {
            if (result.Results == null) //precaution
            {
                ThrowOnNullResults();
                return;
            }

            for (var i = 0; i < _sessionCommandsCount; i++)
            {
                var batchResult = result.Results[i] as BlittableJsonReaderObject;
                if (batchResult == null)
                {
                    throw new ArgumentNullException();
                }

                batchResult.TryGet("Type", out string type);

                if (type != "PUT")
                {
                    continue;
                }

                var entity = _entities[i];
                if (_session.DocumentsByEntity.TryGetValue(entity, out DocumentInfo documentInfo) == false)
                {
                    continue;
                }

                if (batchResult.TryGet(Constants.Documents.Metadata.ChangeVector, out string changeVector) == false || changeVector == null)
                {
                    throw new InvalidOperationException("PUT response is invalid. @change-vector is missing on " + documentInfo.Id);
                }

                if (batchResult.TryGet(Constants.Documents.Metadata.Id, out string id) == false || id == null)
                {
                    throw new InvalidOperationException("PUT response is invalid. @id is missing on " + documentInfo.Id);
                }

                documentInfo.Metadata.Modifications = null;
                documentInfo.Metadata.Modifications = new DynamicJsonValue(documentInfo.Metadata);

                foreach (var propertyName in batchResult.GetPropertyNames())
                {
                    if (propertyName == "Type")
                    {
                        continue;
                    }

                    documentInfo.Metadata.Modifications[propertyName] = batchResult[propertyName];
                }

                documentInfo.Id                     = id;
                documentInfo.ChangeVector           = changeVector;
                documentInfo.Metadata               = _session.Context.ReadObject(documentInfo.Metadata, id);
                documentInfo.Document.Modifications = null;
                documentInfo.Document.Modifications = new DynamicJsonValue(documentInfo.Document)
                {
                    [Constants.Documents.Metadata.Key] = documentInfo.Metadata
                };
                documentInfo.Document         = _session.Context.ReadObject(documentInfo.Document, id);
                documentInfo.MetadataInstance = null;

                _session.DocumentsById.Add(documentInfo);
                _session.GenerateEntityIdOnTheClient.TrySetIdentity(entity, id);

                var afterSaveChangesEventArgs = new AfterSaveChangesEventArgs(_session, documentInfo.Id, documentInfo.Entity);
                _session.OnAfterSaveChangesInvoke(afterSaveChangesEventArgs);
            }
        }