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); }
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); }
public void Delete(object entity, string name) { if (DocumentsByEntity.TryGetValue(entity, out var document) == false) { ThrowEntityNotInSession(entity); } Delete(document.Id, name); }
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)); }
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)); }
/// <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)); }
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)); }
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); }
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); }
/// <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); }
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); }
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); }
/// <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); }
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); }