public void Delete(string documentId, string name)
        {
            if (string.IsNullOrWhiteSpace(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.DELETE, null)) ||
                DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentDELETE, name)))
            {
                return; // no-op
            }
            if (DocumentsById.TryGetValue(documentId, out DocumentInfo documentInfo) &&
                DeletedEntities.Contains(documentInfo.Entity))
            {
                return; // no-op
            }
            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentPUT, name)))
            {
                ThrowOtherDeferredCommandException(documentId, name, "delete", "create");
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentMOVE, name)))
            {
                ThrowOtherDeferredCommandException(documentId, name, "delete", "rename");
            }

            Defer(new DeleteAttachmentCommandData(documentId, name, null));
        }
示例#2
0
        public async Task <bool> ExistsAsync(string id, CancellationToken token = default)
        {
            using (AsyncTaskHolder())
            {
                if (id == null)
                {
                    throw new ArgumentNullException(nameof(id));
                }

                if (_knownMissingIds.Contains(id))
                {
                    return(false);
                }

                if (DocumentsById.TryGetValue(id, out _))
                {
                    return(true);
                }

                var command = new HeadDocumentCommand(id, null);
                await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : _sessionInfo, token : token).ConfigureAwait(false);

                return(command.Result != null);
            }
        }
        public void Store(string documentId, string name, Stream stream, string contentType = null)
        {
            if (string.IsNullOrWhiteSpace(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.DELETE, null)))
            {
                throw new InvalidOperationException($"Can't store attachment {name} of document {documentId}, there is a deferred command registered for this document to be deleted.");
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentPUT, name)))
            {
                throw new InvalidOperationException($"Can't store attachment {name} of document {documentId}, there is a deferred command registered to create an attachment with the same name.");
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentDELETE, name)))
            {
                throw new InvalidOperationException($"Can't store attachment {name} of document {documentId}, there is a deferred command registered to delete an attachment with the same name.");
            }

            if (DocumentsById.TryGetValue(documentId, out DocumentInfo documentInfo) &&
                DeletedEntities.Contains(documentInfo.Entity))
            {
                throw new InvalidOperationException($"Can't store attachment {name} of document {documentId}, the document was already deleted in this session.");
            }

            Defer(new PutAttachmentCommandData(documentId, name, stream, contentType, null));
        }
        public void Delete(string documentId, string name)
        {
            if (string.IsNullOrWhiteSpace(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.DELETE, null)) ||
                DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentDELETE, name)))
            {
                return; // no-op
            }
            if (DocumentsById.TryGetValue(documentId, out DocumentInfo documentInfo) &&
                DeletedEntities.Contains(documentInfo.Entity))
            {
                return; // no-op
            }
            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentPUT, name)))
            {
                throw new InvalidOperationException($"Can't delete attachment {name} of document {documentId}, there is a deferred command registered to create an attachment with the same name.");
            }

            Defer(new DeleteAttachmentCommandData(documentId, name, null));
        }
        public void Copy(string sourceDocumentId, string sourceName, string destinationDocumentId, string destinationName)
        {
            if (string.IsNullOrWhiteSpace(sourceDocumentId))
            {
                throw new ArgumentNullException(nameof(sourceDocumentId));
            }
            if (string.IsNullOrWhiteSpace(sourceName))
            {
                throw new ArgumentNullException(nameof(sourceName));
            }
            if (string.IsNullOrWhiteSpace(destinationDocumentId))
            {
                throw new ArgumentNullException(nameof(destinationDocumentId));
            }
            if (string.IsNullOrWhiteSpace(destinationName))
            {
                throw new ArgumentNullException(nameof(destinationName));
            }

            if (string.Equals(sourceDocumentId, destinationDocumentId, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(sourceName, destinationName))
            {
                return; // no-op
            }
            if (DocumentsById.TryGetValue(sourceDocumentId, out DocumentInfo sourceDocument) && DeletedEntities.Contains(sourceDocument.Entity))
            {
                ThrowDocumentAlreadyDeleted(sourceDocumentId, sourceName, "copy", destinationDocumentId, sourceDocumentId);
            }

            if (DocumentsById.TryGetValue(destinationDocumentId, out DocumentInfo destinationDocument) && DeletedEntities.Contains(destinationDocument.Entity))
            {
                ThrowDocumentAlreadyDeleted(sourceDocumentId, sourceName, "copy", destinationDocumentId, destinationDocumentId);
            }

            if (DeferredCommandsDictionary.ContainsKey((sourceDocumentId, CommandType.AttachmentDELETE, sourceName)))
            {
                ThrowOtherDeferredCommandException(sourceDocumentId, sourceName, "copy", "delete");
            }

            if (DeferredCommandsDictionary.ContainsKey((sourceDocumentId, CommandType.AttachmentMOVE, sourceName)))
            {
                ThrowOtherDeferredCommandException(sourceDocumentId, sourceName, "copy", "rename");
            }

            if (DeferredCommandsDictionary.ContainsKey((destinationDocumentId, CommandType.AttachmentDELETE, destinationName)))
            {
                ThrowOtherDeferredCommandException(destinationDocumentId, destinationName, "copy", "delete");
            }

            if (DeferredCommandsDictionary.ContainsKey((destinationDocumentId, CommandType.AttachmentMOVE, destinationName)))
            {
                ThrowOtherDeferredCommandException(destinationDocumentId, destinationName, "copy", "rename");
            }

            Defer(new CopyAttachmentCommandData(sourceDocumentId, sourceName, destinationDocumentId, destinationName, null));
        }
示例#6
0
        public async Task <bool> ExistsAsync(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (DocumentsById.TryGetValue(id, out _))
            {
                return(true);
            }

            var command = new HeadDocumentCommand(id, null);
            await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo).ConfigureAwait(false);

            return(command.Result != null);
        }
示例#7
0
        /// <summary>
        /// Check if document exists without loading it
        /// </summary>
        /// <param name="id">Document id.</param>
        /// <returns></returns>
        public bool Exists(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (DocumentsById.TryGetValue(id, out _))
            {
                return(true);
            }

            var command = new HeadDocumentCommand(id, null);

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

            return(command.Result != null);
        }
        public void Store(string documentId, string name, Stream stream, string contentType = null)
        {
            if (string.IsNullOrWhiteSpace(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.DELETE, null)))
            {
                ThrowOtherDeferredCommandException(documentId, name, "store", "delete");
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentPUT, name)))
            {
                ThrowOtherDeferredCommandException(documentId, name, "store", "create");
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentDELETE, name)))
            {
                ThrowOtherDeferredCommandException(documentId, name, "store", "delete");
            }

            if (DeferredCommandsDictionary.ContainsKey((documentId, CommandType.AttachmentMOVE, name)))
            {
                ThrowOtherDeferredCommandException(documentId, name, "store", "rename");
            }

            if (DocumentsById.TryGetValue(documentId, out DocumentInfo documentInfo) &&
                DeletedEntities.Contains(documentInfo.Entity))
            {
                ThrowDocumentAlreadyDeleted(documentId, name, "store", null, documentId);
            }

            Defer(new PutAttachmentCommandData(documentId, name, stream, contentType, null));
        }