コード例 #1
0
        public async Task <FileHeader> Execute(IAsyncFilesSession session)
        {
            var commands = session.Commands;

            var pipe = new BlockingStream(10);

            Task.Run(() => StreamWriter(pipe))
            .ContinueWith(x => pipe.CompleteWriting())
            .ConfigureAwait(false);

            if (sessionOperations.EntityChanged(Filename))
            {
                if (!sessionOperations.IsDeleted(Filename))
                {
                    var fileHeaderInCache = await session.LoadFileAsync(Filename);

                    Metadata = fileHeaderInCache.Metadata;
                }
            }

            await commands.UploadAsync(Filename, pipe, Metadata, Size, null)
            .ConfigureAwait(false);

            var metadata = await commands.GetMetadataForAsync(Filename);

            if (metadata == null)
            {
                return(null);
            }

            return(new FileHeader(Filename, metadata));
        }
コード例 #2
0
        public async Task <FileHeader> Execute(IAsyncFilesSession session)
        {
            var commands = session.Commands;

            if (sessionOperations.EntityChanged(FileName))
            {
                if (!sessionOperations.IsDeleted(FileName))
                {
                    var fileHeaderInCache = await session.LoadFileAsync(FileName).ConfigureAwait(false);

                    Metadata = fileHeaderInCache.Metadata;
                }
            }

            if (Stream != null)
            {
                await commands.UploadAsync(FileName, Stream, Metadata, Etag)
                .ConfigureAwait(false);
            }
            else if (StreamWriter != null)
            {
                await commands.UploadAsync(FileName, StreamWriter, null, Size, Metadata, Etag)
                .ConfigureAwait(false);
            }
            else
            {
                throw new InvalidOperationException("Neither stream not stream writer was specified");
            }

            var metadata = await commands.GetMetadataForAsync(FileName).ConfigureAwait(false);

            if (metadata == null)
            {
                return(null);
            }

            return(new FileHeader(FileName, metadata));
        }