예제 #1
0
 public virtual Task <ShareStats> GetStatsAsync(FileRequestOptions options, OperationContext operationContext)
 {
     return(this.GetStatsAsync(options, operationContext, CancellationToken.None));
 }
예제 #2
0
 public virtual Task SetPropertiesAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     throw new System.NotImplementedException();
 }
예제 #3
0
 public virtual Task SetMetadataAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
예제 #4
0
 public virtual Task CreateAsync(long size, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
예제 #5
0
 public virtual Task <bool> DeleteIfExistsAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
예제 #6
0
 public virtual Task DownloadToStreamAsync(Stream target, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     throw new System.NotImplementedException();
 }
예제 #7
0
 public virtual Task DownloadRangeToStreamAsync(Stream target, long?offset, long?length, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
예제 #8
0
        /// <summary>
        /// Implementation for the SetProperties method.
        /// </summary>
        /// <param name="accessCondition">An object that represents the access conditions for the share. If null, no condition is used.</param>
        /// <param name="options">An object that specifies additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand"/> that sets the metadata.</returns>
        private RESTCommand <NullType> SetPropertiesImpl(AccessCondition accessCondition, FileRequestOptions options)
        {
            RESTCommand <NullType> putCmd = new RESTCommand <NullType>(this.ServiceClient.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(putCmd);
            putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) =>
            {
                StorageRequestMessage msg = ShareHttpRequestMessageFactory.SetProperties(uri, serverTimeout, this.Properties, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials);
                ShareHttpRequestMessageFactory.AddMetadata(msg, this.Metadata);
                return(msg);
            };
            putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
            {
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, NullType.Value, cmd, ex);
                this.UpdateETagAndLastModified(resp);
                return(NullType.Value);
            };

            return(putCmd);
        }
예제 #9
0
 public virtual Task <bool> CreateIfNotExistsAsync(FileRequestOptions options, OperationContext operationContext)
 {
     return(this.CreateIfNotExistsAsync(options, operationContext, CancellationToken.None));
 }
예제 #10
0
        /// <summary>
        /// Implementation for the SetPermissions method.
        /// </summary>
        /// <param name="acl">The permissions to set.</param>
        /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the share. If <c>null</c>, no condition is used.</param>
        /// <param name="options">A <see cref="FileRequestOptions"/> object that specifies additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns>
        private RESTCommand <NullType> SetPermissionsImpl(FileSharePermissions acl, AccessCondition accessCondition, FileRequestOptions options)
        {
            MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));

            FileRequest.WriteSharedAccessIdentifiers(acl.SharedAccessPolicies, memoryStream);

            RESTCommand <NullType> putCmd = new RESTCommand <NullType>(this.ServiceClient.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(putCmd);
            putCmd.BuildRequest       = (cmd, uri, builder, cnt, serverTimeout, ctx) => ShareHttpRequestMessageFactory.SetAcl(uri, serverTimeout, FileSharePublicAccessType.Off, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials);
            putCmd.BuildContent       = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx);
            putCmd.StreamToDispose    = memoryStream;
            putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
            {
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, NullType.Value, cmd, ex);
                this.UpdateETagAndLastModified(resp);
                return(NullType.Value);
            };

            return(putCmd);
        }
예제 #11
0
        /// <summary>
        /// Implementation for the GetPermissions method.
        /// </summary>
        /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the share. If <c>null</c>, no condition is used.</param>
        /// <param name="options">A <see cref="FileRequestOptions"/> object that specifies additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns>
        private RESTCommand <FileSharePermissions> GetPermissionsImpl(AccessCondition accessCondition, FileRequestOptions options)
        {
            FileSharePermissions shareAcl = null;

            RESTCommand <FileSharePermissions> getCmd = new RESTCommand <FileSharePermissions>(this.ServiceClient.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(getCmd);
            getCmd.CommandLocationMode    = CommandLocationMode.PrimaryOrSecondary;
            getCmd.RetrieveResponseStream = true;
            getCmd.BuildRequest           = (cmd, uri, builder, cnt, serverTimeout, ctx) => ShareHttpRequestMessageFactory.GetAcl(uri, serverTimeout, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials);
            getCmd.PreProcessResponse     = (cmd, resp, ex, ctx) =>
            {
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex);
                shareAcl = new FileSharePermissions();
                return(shareAcl);
            };
            getCmd.PostProcessResponse = (cmd, resp, ctx) =>
            {
                this.UpdateETagAndLastModified(resp);
                return(Task.Factory.StartNew(() =>
                {
                    ShareHttpResponseParsers.ReadSharedAccessIdentifiers(cmd.ResponseStream, shareAcl);
                    return shareAcl;
                }));
            };

            return(getCmd);
        }
예제 #12
0
        /// <summary>
        /// Implementation for the FetchAttributes method.
        /// </summary>
        /// <param name="accessCondition">An object that represents the access conditions for the share. If null, no condition is used.</param>
        /// <param name="options">An object that specifies additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand"/> that fetches the attributes.</returns>
        private RESTCommand <NullType> FetchAttributesImpl(AccessCondition accessCondition, FileRequestOptions options)
        {
            RESTCommand <NullType> getCmd = new RESTCommand <NullType>(this.ServiceClient.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(getCmd);
            getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary;
            getCmd.BuildRequest        = (cmd, uri, builder, cnt, serverTimeout, ctx) => ShareHttpRequestMessageFactory.GetProperties(uri, serverTimeout, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials);
            getCmd.PreProcessResponse  = (cmd, resp, ex, ctx) =>
            {
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, NullType.Value, cmd, ex);
                this.Properties = ShareHttpResponseParsers.GetProperties(resp);
                this.Metadata   = ShareHttpResponseParsers.GetMetadata(resp);
                return(NullType.Value);
            };

            return(getCmd);
        }
예제 #13
0
        /// <summary>
        /// Implementation for the Delete method.
        /// </summary>
        /// <param name="accessCondition">An object that represents the access conditions for the share. If null, no condition is used.</param>
        /// <param name="options">An object that specifies additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand"/> that deletes the share.</returns>
        private RESTCommand <NullType> DeleteShareImpl(AccessCondition accessCondition, FileRequestOptions options)
        {
            RESTCommand <NullType> deleteCmd = new RESTCommand <NullType>(this.ServiceClient.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(deleteCmd);
            deleteCmd.BuildRequest       = (cmd, uri, builder, cnt, serverTimeout, ctx) => ShareHttpRequestMessageFactory.Delete(uri, serverTimeout, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials);
            deleteCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex);

            return(deleteCmd);
        }
예제 #14
0
 public virtual Task SetMetadataAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     return(this.SetMetadataAsync(accessCondition, options, operationContext, CancellationToken.None));
 }
예제 #15
0
 public virtual Task UploadFromStreamAsync(Stream source, long length, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
        public async Task FileWriteStreamBasicTestAsync()
        {
            byte[] buffer = GetRandomBuffer(6 * 512);

#if NETCORE
            MD5 hasher = MD5.Create();
#else
            CryptographicHash hasher = HashAlgorithmProvider.OpenAlgorithm("MD5").CreateHash();
#endif
            CloudFileShare share = GetRandomShareReference();
            share.ServiceClient.DefaultRequestOptions.ParallelOperationThreadCount = 2;

            try
            {
                await share.CreateAsync();

                CloudFile file = share.GetRootDirectoryReference().GetFileReference("file1");
                file.StreamWriteSizeInBytes = 8 * 512;

                using (MemoryStream wholeFile = new MemoryStream())
                {
                    FileRequestOptions options = new FileRequestOptions()
                    {
                        StoreFileContentMD5 = true,
                    };
                    using (var writeStream = await file.OpenWriteAsync(buffer.Length * 3, null, options, null))
                    {
                        Stream fileStream = writeStream;

                        for (int i = 0; i < 3; i++)
                        {
                            await fileStream.WriteAsync(buffer, 0, buffer.Length);

                            await wholeFile.WriteAsync(buffer, 0, buffer.Length);

                            Assert.AreEqual(wholeFile.Position, fileStream.Position);
#if !NETCORE
                            hasher.Append(buffer.AsBuffer());
#endif
                        }

                        await fileStream.FlushAsync();
                    }

#if NETCORE
                    string md5 = Convert.ToBase64String(hasher.ComputeHash(wholeFile.ToArray()));
#else
                    string md5 = CryptographicBuffer.EncodeToBase64String(hasher.GetValueAndReset());
#endif
                    await file.FetchAttributesAsync();

                    Assert.AreEqual(md5, file.Properties.ContentMD5);

                    using (MemoryOutputStream downloadedFile = new MemoryOutputStream())
                    {
                        await file.DownloadToStreamAsync(downloadedFile);

                        TestHelper.AssertStreamsAreEqual(wholeFile, downloadedFile.UnderlyingStream);
                    }

                    await TestHelper.ExpectedExceptionAsync <ArgumentException>(
                        async() => await file.OpenWriteAsync(null, null, options, null),
                        "OpenWrite with StoreFileContentMD5 on an existing file should fail");

                    using (var writeStream = await file.OpenWriteAsync(null))
                    {
                        Stream fileStream = writeStream;
                        fileStream.Seek(buffer.Length / 2, SeekOrigin.Begin);
                        wholeFile.Seek(buffer.Length / 2, SeekOrigin.Begin);

                        for (int i = 0; i < 2; i++)
                        {
                            fileStream.Write(buffer, 0, buffer.Length);
                            wholeFile.Write(buffer, 0, buffer.Length);
                            Assert.AreEqual(wholeFile.Position, fileStream.Position);
                        }

                        await fileStream.FlushAsync();
                    }

                    await file.FetchAttributesAsync();

                    Assert.AreEqual(md5, file.Properties.ContentMD5);

                    using (MemoryOutputStream downloadedFile = new MemoryOutputStream())
                    {
                        options.DisableContentMD5Validation = true;
                        await file.DownloadToStreamAsync(downloadedFile, null, options, null);

                        TestHelper.AssertStreamsAreEqual(wholeFile, downloadedFile.UnderlyingStream);
                    }
                }
            }
            finally
            {
                share.DeleteAsync().Wait();
            }
        }
예제 #17
0
 public virtual Task UploadFromByteArrayAsync(byte[] buffer, int index, int count, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
        public async Task FileWriteStreamFlushTestAsync()
        {
            byte[] buffer = GetRandomBuffer(512);

            CloudFileShare share = GetRandomShareReference();

            try
            {
                await share.CreateAsync();

                CloudFile file = share.GetRootDirectoryReference().GetFileReference("file1");
                file.StreamWriteSizeInBytes = 1024;
                using (MemoryStream wholeFile = new MemoryStream())
                {
                    FileRequestOptions options = new FileRequestOptions()
                    {
                        StoreFileContentMD5 = true
                    };
                    OperationContext opContext = new OperationContext();
                    using (var fileStream = await file.OpenWriteAsync(4 * 512, null, options, opContext))
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            await fileStream.WriteAsync(buffer, 0, buffer.Length);

                            await wholeFile.WriteAsync(buffer, 0, buffer.Length);
                        }

#if NETCORE
                        // todo: Make some other better logic for this test to be reliable.
                        System.Threading.Thread.Sleep(500);
#endif

                        Assert.AreEqual(2, opContext.RequestResults.Count);

                        await fileStream.FlushAsync();

                        Assert.AreEqual(3, opContext.RequestResults.Count);

                        await fileStream.FlushAsync();

                        Assert.AreEqual(3, opContext.RequestResults.Count);

                        await fileStream.WriteAsync(buffer, 0, buffer.Length);

                        await wholeFile.WriteAsync(buffer, 0, buffer.Length);

                        Assert.AreEqual(3, opContext.RequestResults.Count);

                        await fileStream.CommitAsync();

                        Assert.AreEqual(5, opContext.RequestResults.Count);
                    }

                    Assert.AreEqual(5, opContext.RequestResults.Count);

                    using (MemoryOutputStream downloadedFile = new MemoryOutputStream())
                    {
                        await file.DownloadToStreamAsync(downloadedFile);

                        TestHelper.AssertStreamsAreEqual(wholeFile, downloadedFile.UnderlyingStream);
                    }
                }
            }
            finally
            {
                share.DeleteIfExistsAsync().Wait();
            }
        }
예제 #19
0
 public virtual Task <int> DownloadToByteArrayAsync(byte[] target, int index, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     throw new System.NotImplementedException();
 }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the FileWriteStreamBase class for a file.
 /// </summary>
 /// <param name="file">File reference to write to.</param>
 /// <param name="fileSize">Size of the file.</param>
 /// <param name="createNew">Use <c>true</c> if the file is newly created, <c>false</c> otherwise.</param>
 /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the file. If <c>null</c>, no condition is used.</param>
 /// <param name="options">An <see cref="FileRequestOptions"/> object that specifies additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
 protected FileWriteStreamBase(CloudFile file, long fileSize, bool createNew, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
     : base()
 {
     this.internalBuffer = new MultiBufferMemoryStream(file.ServiceClient.BufferManager);
     this.currentOffset = 0;
     this.accessCondition = accessCondition;
     this.options = options;
     this.operationContext = operationContext;
     this.noPendingWritesEvent = new CounterEvent();
     this.fileMD5 = this.options.StoreFileContentMD5.Value ? new MD5Wrapper() : null;
     this.rangeMD5 = this.options.UseTransactionalMD5.Value ? new MD5Wrapper() : null;
     this.parallelOperationSemaphore = new AsyncSemaphore(options.ParallelOperationThreadCount.Value);
     this.lastException = null;
     this.committed = false;
     this.disposed = false;
     this.currentFileOffset = 0;
     this.file = file;
     this.fileSize = fileSize;
     this.streamWriteSizeInBytes = file.StreamWriteSizeInBytes;
     this.newFile = createNew;
 }
예제 #21
0
 public virtual Task <int> DownloadRangeToByteArrayAsync(byte[] target, int index, long?fileOffset, long?length, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FileReadStream"/> class.
 /// </summary>
 /// <param name="file">File reference to read from.</param>
 /// <param name="accessCondition">An object that represents the access conditions for the file. If null, no condition is used.</param>
 /// <param name="options">An object that specifies additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
 internal FileReadStream(CloudFile file, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
     : base(file, accessCondition, options, operationContext)
 {
 }
예제 #23
0
 public virtual Task <bool> ExistsAsync(FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
예제 #24
0
 public virtual Task <Stream> OpenReadAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     throw new System.NotImplementedException();
 }
예제 #25
0
 public virtual Task <IEnumerable <FileRange> > ListRangesAsync(long?offset, long?length, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
예제 #26
0
 public virtual Task <CloudFileStream> OpenWriteAsync(long?size, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     throw new System.NotImplementedException();
 }
예제 #27
0
 public virtual Task ResizeAsync(long size, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     throw new System.NotImplementedException();
 }
예제 #28
0
 public virtual Task UploadFromStreamAsync(Stream source, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     throw new System.NotImplementedException();
 }
예제 #29
0
 public virtual Task WriteRangeAsync(Stream rangeData, long startOffset, string contentMD5, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
예제 #30
0
        public virtual Task <FileSharePermissions> GetPermissionsAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
        {
            FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient);

            return(Task.Run(async() => await Executor.ExecuteAsync <FileSharePermissions>(
                                this.GetPermissionsImpl(accessCondition, modifiedOptions),
                                modifiedOptions.RetryPolicy,
                                operationContext,
                                cancellationToken), cancellationToken));
        }