Esempio n. 1
0
        /// <inheritdoc />
        public override async Task <DeleteResult> DeleteAsync(CancellationToken cancellationToken)
        {
            if (InMemoryFileSystem.IsReadOnly)
            {
                throw new UnauthorizedAccessException("Failed to modify a read-only file system");
            }

            if (InMemoryParent == null)
            {
                throw new InvalidOperationException("The document must belong to a collection");
            }

            if (InMemoryParent.Remove(Name))
            {
                var propStore = FileSystem.PropertyStore;
                if (propStore != null)
                {
                    await propStore.RemoveAsync(this, cancellationToken).ConfigureAwait(false);
                }

                return(new DeleteResult(WebDavStatusCode.OK, null));
            }

            return(new DeleteResult(WebDavStatusCode.NotFound, this));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task <IDocument> MoveToAsync(ICollection collection, string name, CancellationToken cancellationToken)
        {
            if (InMemoryFileSystem.IsReadOnly)
            {
                throw new UnauthorizedAccessException("Failed to modify a read-only file system");
            }

            var sourcePropStore = FileSystem.PropertyStore;
            var destPropStore   = collection.FileSystem.PropertyStore;

            IReadOnlyCollection <XElement> sourceProps;

            if (sourcePropStore != null && destPropStore != null)
            {
                sourceProps = await sourcePropStore.GetAsync(this, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                sourceProps = null;
            }

            var coll = (InMemoryDirectory)collection;
            var doc  = (InMemoryFile)await coll.CreateDocumentAsync(name, cancellationToken).ConfigureAwait(false);

            doc.Data             = new MemoryStream(Data.ToArray());
            doc.CreationTimeUtc  = CreationTimeUtc;
            doc.LastWriteTimeUtc = LastWriteTimeUtc;
            doc.ETag             = ETag;
            Debug.Assert(InMemoryParent != null, "InMemoryParent != null");
            if (InMemoryParent == null)
            {
                throw new InvalidOperationException("The document must belong to a collection");
            }
            if (!InMemoryParent.Remove(Name))
            {
                throw new InvalidOperationException("Failed to remove the document from the source collection.");
            }

            if (destPropStore != null)
            {
                await destPropStore.RemoveAsync(doc, cancellationToken).ConfigureAwait(false);

                if (sourceProps != null)
                {
                    await destPropStore.SetAsync(doc, sourceProps, cancellationToken).ConfigureAwait(false);
                }
            }

            return(doc);
        }