private RESTCommand <NullType> SetServicePropertiesImpl(FileServiceProperties properties, FileRequestOptions requestOptions) { MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); try { properties.WriteServiceProperties(memoryStream); } catch (InvalidOperationException invalidOpException) { throw new ArgumentException(invalidOpException.Message, "properties"); } RESTCommand <NullType> retCmd = new RESTCommand <NullType>(this.Credentials, this.StorageUri, this.HttpClient); requestOptions.ApplyToStorageCommand(retCmd); retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => FileHttpRequestMessageFactory.SetServiceProperties(uri, serverTimeout, cnt, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, Checksum.None, cmd, ctx); retCmd.StreamToDispose = memoryStream; retCmd.RetrieveResponseStream = true; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex); requestOptions.ApplyToStorageCommand(retCmd); return(retCmd); }
/// <summary> /// Gets the list handles implementation. /// </summary> /// <param name="token">Continuation token for paged responses.</param> /// <param name="maxResults">The maximum number of results to be returned by the server.</param> /// <param name="recursive">Whether to recurse through this directory's files and subfolders.</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> /// <returns>A <see cref="RESTCommand{T}"/> for getting the handles.</returns> private RESTCommand <FileHandleResultSegment> ListHandlesImpl(FileContinuationToken token, int?maxResults, bool?recursive, AccessCondition accessCondition, FileRequestOptions options) { RESTCommand <FileHandleResultSegment> getCmd = new RESTCommand <FileHandleResultSegment>(this.ServiceClient.Credentials, this.StorageUri, this.ServiceClient.HttpClient); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => { StorageRequestMessage msg = FileHttpRequestMessageFactory.ListHandles(uri, serverTimeout, maxResults, recursive, token, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); FileHttpRequestMessageFactory.AddMetadata(msg, this.Metadata); return(msg); }; getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponseAsync = (cmd, resp, ctx, ct) => { ListHandlesResponse listHandlesResponse = new ListHandlesResponse(cmd.ResponseStream); return(Task.FromResult(new FileHandleResultSegment() { Results = listHandlesResponse.Handles, ContinuationToken = new FileContinuationToken() { NextMarker = listHandlesResponse.NextMarker } })); }; return(getCmd); }
/// <summary> /// Implementation for the Delete method. /// </summary> /// <param name="accessCondition">An object that represents the access conditions for the directory. 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 directory.</returns> private RESTCommand <NullType> DeleteDirectoryImpl(AccessCondition accessCondition, FileRequestOptions options) { RESTCommand <NullType> putCmd = new RESTCommand <NullType>(this.ServiceClient.Credentials, this.StorageUri, this.ServiceClient.HttpClient); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => DirectoryHttpRequestMessageFactory.Delete(uri, serverTimeout, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex); return(putCmd); }
private RESTCommand <FileServiceProperties> GetServicePropertiesImpl(FileRequestOptions requestOptions) { RESTCommand <FileServiceProperties> retCmd = new RESTCommand <FileServiceProperties>(this.Credentials, this.StorageUri, this.HttpClient); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => FileHttpRequestMessageFactory.GetServiceProperties(uri, serverTimeout, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.RetrieveResponseStream = true; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponseAsync = (cmd, resp, ctx, ct) => FileHttpResponseParsers.ReadServicePropertiesAsync(cmd.ResponseStream, ct); requestOptions.ApplyToStorageCommand(retCmd); return(retCmd); }
/// <summary> /// Implements the FetchAttributes method. The attributes are updated immediately. /// </summary> /// <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> /// <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, this.ServiceClient.HttpClient); options.ApplyToStorageCommand(getCmd); getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => DirectoryHttpRequestMessageFactory.GetProperties(uri, serverTimeout, this.Share.SnapshotTime, 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 = DirectoryHttpResponseParsers.GetProperties(resp); this.Metadata = DirectoryHttpResponseParsers.GetMetadata(resp); return(NullType.Value); }; return(getCmd); }
/// <summary> /// Gets the close handles implementation. /// </summary> /// <param name="token">Continuation token for closing many files.</param> /// <param name="handleId">Id of the handle, "*" if all handles on the file.</param> /// <param name="recursive">Whether to recurse through this directory's files and subfolders.</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> /// <returns>A <see cref="RESTCommand{T}"/> for closing the handles.</returns> private RESTCommand <CloseFileHandleResultSegment> CloseHandleImpl(FileContinuationToken token, string handleId, bool?recursive, AccessCondition accessCondition, FileRequestOptions options) { RESTCommand <CloseFileHandleResultSegment> putCmd = new RESTCommand <CloseFileHandleResultSegment>(this.ServiceClient.Credentials, this.StorageUri, this.ServiceClient.HttpClient); options.ApplyToStorageCommand(putCmd); putCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; putCmd.RetrieveResponseStream = true; putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => { StorageRequestMessage msg = FileHttpRequestMessageFactory.CloseHandle(uri, serverTimeout, handleId, recursive, token, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); FileHttpRequestMessageFactory.AddMetadata(msg, this.Metadata); return(msg); }; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { CloseFileHandleResultSegment res = HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); int handlesClosed; if (!int.TryParse(resp.Headers.GetHeaderSingleValueOrDefault(Constants.HeaderConstants.NumHandlesClosed), out handlesClosed)) { handlesClosed = -1; } FileContinuationToken continuation = null; string marker; if ((marker = resp.Headers.GetHeaderSingleValueOrDefault(Constants.HeaderConstants.Marker)) != "") { continuation = new FileContinuationToken() { NextMarker = marker }; } return(new CloseFileHandleResultSegment() { NumHandlesClosed = handlesClosed, ContinuationToken = continuation }); }; return(putCmd); }
/// <summary> /// Implementation for the SetMetadata method. /// </summary> /// <param name="accessCondition">An object that represents the access conditions for the directory. 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> SetMetadataImpl(AccessCondition accessCondition, FileRequestOptions options) { RESTCommand <NullType> putCmd = new RESTCommand <NullType>(this.ServiceClient.Credentials, this.StorageUri, this.ServiceClient.HttpClient); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => { StorageRequestMessage msg = DirectoryHttpRequestMessageFactory.SetMetadata(uri, serverTimeout, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); DirectoryHttpRequestMessageFactory.AddMetadata(msg, this.Metadata); return(msg); }; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, NullType.Value, cmd, ex); this.UpdateETagAndLastModified(resp); cmd.CurrentResult.IsRequestServerEncrypted = HttpResponseParsers.ParseServerRequestEncrypted(resp); return(NullType.Value); }; return(putCmd); }
/// <summary> /// Implementation for the Exists method. /// </summary> /// <param name="options">An object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that checks existence.</returns> private RESTCommand <bool> ExistsImpl(FileRequestOptions options) { RESTCommand <bool> getCmd = new RESTCommand <bool>(this.ServiceClient.Credentials, this.StorageUri, this.ServiceClient.HttpClient); options.ApplyToStorageCommand(getCmd); getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => DirectoryHttpRequestMessageFactory.GetProperties(uri, serverTimeout, this.Share.SnapshotTime, null, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { if (resp.StatusCode == HttpStatusCode.NotFound) { return(false); } HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, true, cmd, ex); this.Properties = DirectoryHttpResponseParsers.GetProperties(resp); this.Metadata = DirectoryHttpResponseParsers.GetMetadata(resp); return(true); }; return(getCmd); }
/// <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); }