/// <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>
        /// 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);
        }