public async Task CloudFileClientListSharesSegmentedAsync() { string name = GetRandomShareName(); List <string> shareNames = new List <string>(); DelegatingHandlerImpl delegatingHandlerImpl = new DelegatingHandlerImpl(new DelegatingHandlerImpl()); CloudFileClient fileClient = GenerateCloudFileClient(delegatingHandlerImpl); for (int i = 0; i < 3; i++) { string shareName = name + i.ToString(); shareNames.Add(shareName); await fileClient.GetShareReference(shareName).CreateAsync(); } List <string> listedShareNames = new List <string>(); FileContinuationToken token = null; do { ShareResultSegment resultSegment = await fileClient.ListSharesSegmentedAsync(token); token = resultSegment.ContinuationToken; foreach (CloudFileShare share in resultSegment.Results) { Assert.IsTrue(fileClient.GetShareReference(share.Name).StorageUri.Equals(share.StorageUri)); listedShareNames.Add(share.Name); } }while (token != null); foreach (string shareName in listedShareNames) { if (shareNames.Remove(shareName)) { await fileClient.GetShareReference(shareName).DeleteAsync(); } } Assert.AreEqual(0, shareNames.Count); Assert.AreNotEqual(0, delegatingHandlerImpl.CallCount); }
public async Task CloudFileClientListSharesSegmentedWithPrefixAsync() { string name = GetRandomShareName(); List <string> shareNames = new List <string>(); CloudFileClient fileClient = GenerateCloudFileClient(); for (int i = 0; i < 3; i++) { string shareName = name + i.ToString(); shareNames.Add(shareName); await fileClient.GetShareReference(shareName).CreateAsync(); } List <string> listedShareNames = new List <string>(); FileContinuationToken token = null; do { ShareResultSegment resultSegment = await fileClient.ListSharesSegmentedAsync(name, ShareListingDetails.None, 1, token, null, null); token = resultSegment.ContinuationToken; int count = 0; foreach (CloudFileShare share in resultSegment.Results) { count++; listedShareNames.Add(share.Name); } Assert.IsTrue(count <= 1); }while (token != null); Assert.AreEqual(shareNames.Count, listedShareNames.Count); foreach (string shareName in listedShareNames) { Assert.IsTrue(shareNames.Remove(shareName)); await fileClient.GetShareReference(shareName).DeleteAsync(); } }
/// <summary> /// Core implementation of the ListFilesAndDirectories method. /// </summary> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the /// per-operation limit of 5000. If this value is zero, the maximum possible number of results will be returned, up to 5000.</param> /// <param name="options">An object that specifies additional options for the request.</param> /// <param name="currentToken">The continuation token.</param> /// <param name="prefix">A string containing the file or directory name prefix.</param> /// <returns>A <see cref="RESTCommand"/> that lists the files.</returns> private RESTCommand <ResultSegment <IListFileItem> > ListFilesAndDirectoriesImpl(int?maxResults, FileRequestOptions options, FileContinuationToken currentToken, string prefix) { FileListingContext listingContext = new FileListingContext(maxResults) { Marker = currentToken != null ? currentToken.NextMarker : null, Prefix = string.IsNullOrEmpty(prefix) ? null : prefix }; RESTCommand <ResultSegment <IListFileItem> > getCmd = new RESTCommand <ResultSegment <IListFileItem> >(this.ServiceClient.Credentials, this.StorageUri, this.ServiceClient.HttpClient); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken); getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => DirectoryHttpRequestMessageFactory.List(uri, serverTimeout, this.Share.SnapshotTime, listingContext, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponseAsync = async(cmd, resp, ctx, ct) => { ListFilesAndDirectoriesResponse listFilesResponse = await ListFilesAndDirectoriesResponse.ParseAsync(cmd.ResponseStream, ct).ConfigureAwait(false); List <IListFileItem> fileList = listFilesResponse.Files.Select(item => this.SelectListFileItem(item)).ToList(); FileContinuationToken continuationToken = null; if (listFilesResponse.NextMarker != null) { continuationToken = new FileContinuationToken() { NextMarker = listFilesResponse.NextMarker, TargetLocation = cmd.CurrentResult.TargetLocation, }; } return(new ResultSegment <IListFileItem>(fileList) { ContinuationToken = continuationToken, }); }; return(getCmd); }
/// <summary> /// Core implementation for the ListShares method. /// </summary> /// <param name="prefix">The share prefix.</param> /// <param name="detailsIncluded">The details included.</param> /// <param name="currentToken">The continuation token.</param> /// <param name="pagination">The pagination.</param> /// <param name="setResult">The result report delegate.</param> /// <returns>A <see cref="TaskSequence"/> that lists the shares.</returns> private RESTCommand <ResultSegment <CloudFileShare> > ListSharesImpl(string prefix, ShareListingDetails detailsIncluded, FileContinuationToken currentToken, int?maxResults, FileRequestOptions options) { ListingContext listingContext = new ListingContext(prefix, maxResults) { Marker = currentToken != null ? currentToken.NextMarker : null }; RESTCommand <ResultSegment <CloudFileShare> > getCmd = new RESTCommand <ResultSegment <CloudFileShare> >(this.Credentials, this.StorageUri, this.HttpClient); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken); getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => ShareHttpRequestMessageFactory.List(uri, serverTimeout, listingContext, detailsIncluded, cnt, ctx, this.GetCanonicalizer(), this.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null, cmd, ex); getCmd.PostProcessResponseAsync = async(cmd, resp, ctx, ct) => { ListSharesResponse listSharesResponse = await ListSharesResponse.ParseAsync(cmd.ResponseStream, ct).ConfigureAwait(false); List <CloudFileShare> sharesList = listSharesResponse.Shares.Select(item => new CloudFileShare(item.Properties, item.Metadata, item.Name, item.SnapshotTime, this)).ToList(); FileContinuationToken continuationToken = null; if (listSharesResponse.NextMarker != null) { continuationToken = new FileContinuationToken() { NextMarker = listSharesResponse.NextMarker, TargetLocation = cmd.CurrentResult.TargetLocation, }; } return(new ResultSegment <CloudFileShare>(sharesList) { ContinuationToken = continuationToken, }); }; return(getCmd); }
public virtual Task <CloseFileHandleResultSegment> CloseHandleSegmentedAsync(string handleId, FileContinuationToken token, bool?recursive = null, AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null, CancellationToken?cancellationToken = null) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient); return(Executor.ExecuteAsync( this.CloseHandleImpl(token, handleId, recursive, accessCondition, modifiedOptions), modifiedOptions.RetryPolicy, operationContext, cancellationToken ?? CancellationToken.None)); }
public virtual async Task <FileResultSegment> ListFilesAndDirectoriesSegmentedAsync(string prefix, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient); ResultSegment <IListFileItem> resultSegment = await Executor.ExecuteAsync( this.ListFilesAndDirectoriesImpl(maxResults, modifiedOptions, currentToken, prefix), modifiedOptions.RetryPolicy, operationContext, cancellationToken).ConfigureAwait(false); return(new FileResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken)); }
public virtual Task <FileResultSegment> ListFilesAndDirectoriesSegmentedAsync(int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { return(this.ListFilesAndDirectoriesSegmentedAsync(null /* prefix */, maxResults, currentToken, options, operationContext, CancellationToken.None)); }
public virtual Task <FileResultSegment> ListFilesAndDirectoriesSegmentedAsync(FileContinuationToken currentToken) { return(this.ListFilesAndDirectoriesSegmentedAsync(null /* prefix */, null /* maxResults */, currentToken, null /* options */, null /* operationContext */)); }
/// <summary> /// Creates in instance of FileResultSegment. /// </summary> /// <param name="files">An enumerable collection of <see cref="IListFileItem"/> objects.</param> /// <param name="continuationToken">The <see cref="FileContinuationToken"/> used to retrieve the next segment of <see cref="IListFileItem"/> results.</param> public FileResultSegment(IEnumerable <IListFileItem> files, FileContinuationToken continuationToken) { this.Results = files; this.ContinuationToken = continuationToken; }
/// <summary> /// Returns a result segment containing a collection of shares /// whose names begin with the specified prefix. /// </summary> /// <param name="prefix">The share name prefix.</param> /// <param name="detailsIncluded">A value that indicates whether to return share metadata with the listing.</param> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned /// in the result segment, up to the per-operation limit of 5000. If this value is null, the maximum possible number of results will be returned, up to 5000.</param> /// <param name="currentToken">A continuation token returned by a previous listing operation.</param> /// <param name="options">A <see cref="FileRequestOptions"/> 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> /// <returns>A result segment of shares.</returns> private ResultSegment <CloudFileShare> ListSharesSegmentedCore(string prefix, ShareListingDetails detailsIncluded, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext) { return(Executor.ExecuteSync( this.ListSharesImpl(prefix, detailsIncluded, currentToken, maxResults, options), options.RetryPolicy, operationContext)); }
public virtual ICancellableAsyncResult BeginListSharesSegmented(string prefix, ShareListingDetails detailsIncluded, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this); return(CancellableAsyncResultTaskWrapper.Create(token => this.ListSharesSegmentedAsync(prefix, detailsIncluded, maxResults, currentToken, modifiedOptions, operationContext), callback, state)); }
public virtual Task <CloseFileHandleResultSegment> CloseHandleSegmentedAsync(ulong handleId, FileContinuationToken token = null, bool?recursive = null, AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null, CancellationToken?cancellationToken = null) { return(this.CloseHandleSegmentedAsync(handleId.ToString(), token, recursive, accessCondition, options, operationContext, cancellationToken)); }
public virtual ShareResultSegment ListSharesSegmented(FileContinuationToken currentToken) { return(this.ListSharesSegmented(null, ShareListingDetails.None, null, currentToken, null, null)); }
public virtual Task <ShareResultSegment> ListSharesSegmentedAsync(string prefix, FileContinuationToken currentToken, CancellationToken cancellationToken) { return(this.ListSharesSegmentedAsync(prefix, default(ShareListingDetails), default(int?) /*maxResults*/, currentToken, default(FileRequestOptions), default(OperationContext), cancellationToken)); }
public virtual Task <ShareResultSegment> ListSharesSegmentedAsync(string prefix, FileContinuationToken currentToken) { return(this.ListSharesSegmentedAsync(prefix, currentToken, CancellationToken.None)); }
public virtual Task <ShareResultSegment> ListSharesSegmentedAsync(FileContinuationToken currentToken, CancellationToken cancellationToken) { return(ListSharesSegmentedAsync(default(string) /*prefix*/, currentToken, cancellationToken)); }
public virtual Task <ShareResultSegment> ListSharesSegmentedAsync(string prefix, ShareListingDetails detailsIncluded, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext) { return(this.ListSharesSegmentedAsync(prefix, detailsIncluded, maxResults, currentToken, options, operationContext, CancellationToken.None)); }
public virtual async Task <ShareResultSegment> ListSharesSegmentedAsync(string prefix, ShareListingDetails detailsIncluded, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this); ResultSegment <CloudFileShare> resultSegment = await Executor.ExecuteAsync( this.ListSharesImpl(prefix, detailsIncluded, currentToken, maxResults, modifiedOptions), modifiedOptions.RetryPolicy, operationContext, cancellationToken).ConfigureAwait(false); return(new ShareResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken)); }
public virtual ICancellableAsyncResult BeginListSharesSegmented(string prefix, FileContinuationToken currentToken, AsyncCallback callback, object state) { return(this.BeginListSharesSegmented(prefix, ShareListingDetails.None, null, currentToken, null, null, callback, state)); }
public virtual Task <ShareResultSegment> ListSharesSegmentedAsync(string prefix, FileContinuationToken currentToken) { return(this.ListSharesSegmentedAsync(prefix, ShareListingDetails.None, null, currentToken, null, null)); }
public async Task CloudFileListSharesWithSnapshotAsync() { CloudFileShare share = GetRandomShareReference(); await share.CreateAsync(); share.Metadata["key1"] = "value1"; await share.SetMetadataAsync(); CloudFileShare snapshot = await share.SnapshotAsync(); share.Metadata["key2"] = "value2"; await share.SetMetadataAsync(); CloudFileClient client = GenerateCloudFileClient(); List <CloudFileShare> listedShares = new List <CloudFileShare>(); FileContinuationToken token = null; do { ShareResultSegment resultSegment = await client.ListSharesSegmentedAsync(share.Name, ShareListingDetails.All, null, token, null, null); token = resultSegment.ContinuationToken; foreach (CloudFileShare listResultShare in resultSegment.Results) { listedShares.Add(listResultShare); } }while (token != null); int count = 0; bool originalFound = false; bool snapshotFound = false; foreach (CloudFileShare listShareItem in listedShares) { if (listShareItem.Name.Equals(share.Name) && !listShareItem.IsSnapshot && !originalFound) { count++; originalFound = true; Assert.AreEqual(2, listShareItem.Metadata.Count); Assert.AreEqual("value2", listShareItem.Metadata["key2"]); // Metadata keys should be case-insensitive Assert.AreEqual("value2", listShareItem.Metadata["KEY2"]); Assert.AreEqual("value1", listShareItem.Metadata["key1"]); Assert.AreEqual(share.StorageUri, listShareItem.StorageUri); } else if (listShareItem.Name.Equals(share.Name) && listShareItem.IsSnapshot && !snapshotFound) { count++; snapshotFound = true; Assert.AreEqual(1, listShareItem.Metadata.Count); Assert.AreEqual("value1", listShareItem.Metadata["key1"]); Assert.AreEqual(snapshot.StorageUri, listShareItem.StorageUri); } } Assert.AreEqual(2, count); await snapshot.DeleteAsync(); await share.DeleteAsync(); }
/// <summary> /// Creates an instance of ShareResultSegment. /// </summary> /// <param name="shares">An enumerable collection of <see cref="CloudFileShare"/> objects.</param> /// <param name="continuationToken">The <see cref="FileContinuationToken"/> used to retrieve the next segment of <see cref="CloudFileShare"/> results.</param> public ShareResultSegment(IEnumerable <CloudFileShare> shares, FileContinuationToken continuationToken) { this.Results = shares; this.ContinuationToken = continuationToken; }
public virtual ShareResultSegment ListSharesSegmented(string prefix, ShareListingDetails detailsIncluded, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options = null, OperationContext operationContext = null) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this); ResultSegment <CloudFileShare> resultSegment = this.ListSharesSegmentedCore(prefix, detailsIncluded, maxResults, currentToken, modifiedOptions, operationContext); return(new ShareResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken)); }