コード例 #1
0
        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 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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        public virtual Entity UseRetrieve(string entityName, Guid id, ColumnSet columnSet)
        {
            if (DeletedEntities.Contains(id))
            {
                throw new Exception("The record was previously removed");
            }

            var entity = Entities.FirstOrDefault(e => e.Id == id);

            if (entity == null)
            {
                throw new Exception($"Record \"{entityName}\" with ID = {id} is not found");
            }
            return(entity);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
        }