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)); }
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)); }
/// <summary> /// Удаление записи сущности. /// </summary> /// <param name="entityName">Имя сущности.</param> /// <param name="id">Идентификатор сущности.</param> /// <remarks> /// Метод записывает данные сущности в окно трассировки. /// </remarks> public void Delete(string entityName, Guid id) { var sb = new StringBuilder(); sb.AppendLine("Delete entity"); sb.AppendLine($"EntityName = {entityName}"); sb.AppendLine($"ID = {id}"); System.Diagnostics.Trace.WriteLine(sb.ToString()); DeletedEntities.Add(id); }
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); }
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)); }
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)); }
public bool Any() { return(InsertedEntities.Any() || UpdatedEntities.Any() || DeletedEntities.Any()); }
public CommitExecutedEntities <T> Entity <T>() where T : class { return(new CommitExecutedEntities <T>(InsertedEntities.OfType <T>().ToList(), UpdatedEntities.OfType <T>().ToList(), DeletedEntities.OfType <T>().ToList())); }
public virtual void Delete(TEntity entity) { Entities.Remove(entity); DeletedEntities.Add(entity); }