コード例 #1
0
        public AttachmentName[] GetNames(object entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (DocumentsByEntity.TryGetValue(entity, out var document) == false)
            {
                ThrowEntityNotInSession(entity);
            }

            if (document.Metadata.TryGet(Constants.Documents.Metadata.Attachments, out BlittableJsonReaderArray attachments) == false)
            {
                return(Array.Empty <AttachmentName>());
            }

            var results = new AttachmentName[attachments.Length];

            for (var i = 0; i < attachments.Length; i++)
            {
                var attachment = (BlittableJsonReaderObject)attachments[i];
                results[i] = JsonDeserializationClient.AttachmentName(attachment);
            }
            return(results);
        }
コード例 #2
0
        public void Store(object entity, string name, Stream stream, string contentType = null)
        {
            if (DocumentsByEntity.TryGetValue(entity, out var document) == false)
            {
                ThrowEntityNotInSession(entity);
            }

            Store(document.Id, name, stream, contentType);
        }
コード例 #3
0
        public void Delete(object entity, string name)
        {
            if (DocumentsByEntity.TryGetValue(entity, out var document) == false)
            {
                ThrowEntityNotInSession(entity);
            }

            Delete(document.Id, name);
        }
コード例 #4
0
        public AttachmentResult GetAttachment(object entity, string name)
        {
            if (DocumentsByEntity.TryGetValue(entity, out DocumentInfo document) == false)
            {
                ThrowEntityNotInSession(entity);
            }

            var operation = new GetAttachmentOperation(document.Id, name, AttachmentType.Document, null);

            return(DocumentStore.Operations.Send(operation, SessionInfo));
        }
コード例 #5
0
        public async Task <AttachmentResult> GetAsync(object entity, string name)
        {
            if (DocumentsByEntity.TryGetValue(entity, out DocumentInfo document) == false)
            {
                ThrowEntityNotInSession(entity);
            }

            var operation = new GetAttachmentOperation(document.Id, name, AttachmentType.Document, null);

            return(await DocumentStore.Operations.SendAsync(operation, sessionInfo : SessionInfo).ConfigureAwait(false));
        }
コード例 #6
0
        /// <summary>
        /// Gets the document URL for the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public string GetDocumentUrl(object entity)
        {
            DocumentInfo document;

            if (DocumentsByEntity.TryGetValue(entity, out document) == false)
            {
                throw new InvalidOperationException("Could not figure out identifier for transient instance");
            }

            return(RequestExecuter.UrlFor(document.Id));
        }
コード例 #7
0
        public Task <AttachmentResult> GetAsync(object entity, string name, CancellationToken token = default)
        {
            if (DocumentsByEntity.TryGetValue(entity, out DocumentInfo document) == false)
            {
                ThrowEntityNotInSessionOrMissingId(entity);
            }

            var operation = new GetAttachmentOperation(document.Id, name, AttachmentType.Document, null);

            return(Session.Operations.SendAsync(operation, sessionInfo: SessionInfo, token));
        }
コード例 #8
0
        public void ForceRevisionCreationFor <T>(T entity, ForceRevisionStrategy strategy = ForceRevisionStrategy.Before)
        {
            if (ReferenceEquals(entity, null))
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (DocumentsByEntity.TryGetValue(entity, out DocumentInfo documentInfo) == false)
            {
                throw new InvalidOperationException("Cannot create a revision for the requested entity because it is Not tracked by the session");
            }

            AddIdToList(documentInfo.Id, strategy);
        }
コード例 #9
0
        public async Task RefreshAsync <T>(T entity, CancellationToken token = default(CancellationToken))
        {
            DocumentInfo documentInfo;

            if (DocumentsByEntity.TryGetValue(entity, out documentInfo) == false)
            {
                throw new InvalidOperationException("Cannot refresh a transient instance");
            }
            IncrementRequestCount();

            var command = new GetDocumentsCommand(new[] { documentInfo.Id }, includes: null, metadataOnly: false);
            await RequestExecutor.ExecuteAsync(command, Context, SessionInfo, token).ConfigureAwait(false);

            RefreshInternal(entity, command, documentInfo);
        }
コード例 #10
0
        /// <summary>
        /// Refreshes the specified entity from Raven server.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">The entity.</param>
        public void Refresh <T>(T entity)
        {
            DocumentInfo documentInfo;

            if (DocumentsByEntity.TryGetValue(entity, out documentInfo) == false)
            {
                throw new InvalidOperationException("Cannot refresh a transient instance");
            }
            IncrementRequestCount();

            var command = new GetDocumentsCommand(new[] { documentInfo.Id }, includes: null, metadataOnly: false);

            RequestExecutor.Execute(command, Context, sessionInfo: SessionInfo);

            RefreshInternal(entity, command, documentInfo);
        }
コード例 #11
0
        public AttachmentName[] GetNames(object entity)
        {
            if (entity == null ||
                DocumentsByEntity.TryGetValue(entity, out DocumentInfo document) == false ||
                document.Metadata.TryGet(Constants.Documents.Metadata.Attachments, out BlittableJsonReaderArray attachments) == false)
            {
                return(Array.Empty <AttachmentName>());
            }

            var results = new AttachmentName[attachments.Length];

            for (var i = 0; i < attachments.Length; i++)
            {
                var attachment = (BlittableJsonReaderObject)attachments[i];
                results[i] = JsonDeserializationClient.AttachmentName(attachment);
            }
            return(results);
        }
コード例 #12
0
        public async Task RefreshAsync <T>(T entity, CancellationToken token = default(CancellationToken))
        {
            DocumentInfo documentInfo;

            if (DocumentsByEntity.TryGetValue(entity, out documentInfo) == false)
            {
                throw new InvalidOperationException("Cannot refresh a transient instance");
            }
            IncrementRequestCount();

            var command = new GetDocumentCommand
            {
                Ids     = new[] { documentInfo.Id },
                Context = this.Context
            };
            await RequestExecuter.ExecuteAsync(command, Context, token);

            RefreshInternal(entity, command, documentInfo);
        }
コード例 #13
0
        /// <summary>
        /// Refreshes the specified entity from Raven server.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">The entity.</param>
        public void Refresh <T>(T entity)
        {
            DocumentInfo documentInfo;

            if (DocumentsByEntity.TryGetValue(entity, out documentInfo) == false)
            {
                throw new InvalidOperationException("Cannot refresh a transient instance");
            }
            IncrementRequestCount();

            var command = new GetDocumentCommand
            {
                Ids     = new[] { documentInfo.Id },
                Context = this.Context
            };

            RequestExecuter.Execute(command, Context);

            RefreshInternal(entity, command, documentInfo);
        }
コード例 #14
0
        public void Copy(object sourceEntity, string sourceName, object destinationEntity, string destinationName)
        {
            if (sourceEntity == null)
            {
                throw new ArgumentNullException(nameof(sourceEntity));
            }
            if (destinationEntity == null)
            {
                throw new ArgumentNullException(nameof(destinationEntity));
            }

            if (DocumentsByEntity.TryGetValue(sourceEntity, out DocumentInfo sourceDocument) == false)
            {
                ThrowEntityNotInSession(sourceEntity);
            }

            if (DocumentsByEntity.TryGetValue(destinationEntity, out DocumentInfo destinationDocument) == false)
            {
                ThrowEntityNotInSession(destinationEntity);
            }

            Copy(sourceDocument.Id, sourceName, destinationDocument.Id, destinationName);
        }