public GetSharesAsyncCollection(
     ShareServiceClient client,
     ShareTraits traits = ShareTraits.None,
     ShareStates states = ShareStates.None,
     string prefix      = default)
 {
     _client = client;
     _traits = traits;
     _states = states;
     _prefix = prefix;
 }
        /// <summary>
        /// The <see cref="GetSharesInternal"/> operation returns a
        /// single segment of shares in the storage account, starting
        /// from the specified <paramref name="marker"/>.  Use an empty
        /// <paramref name="marker"/> to start enumeration from the beginning
        /// and the <see cref="SharesSegment.NextMarker"/> if it's not
        /// empty to make subsequent calls to <see cref="GetSharesAsync"/>
        /// to continue enumerating the shares segment by segment.
        ///
        /// For more information, <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares"/>.
        /// </summary>
        /// <param name="marker">
        /// An optional string value that identifies the segment of the list
        /// of shares to be returned with the next listing operation.  The
        /// operation returns a non-empty <see cref="SharesSegment.NextMarker"/>
        /// if the listing operation did not return all shares remaining
        /// to be listed with the current segment.  The NextMarker value can
        /// be used as the value for the <paramref name="marker"/> parameter
        /// in a subsequent call to request the next segment of list items.
        /// </param>
        /// <param name="traits">
        /// Specifies traits to include in the <see cref="ShareItem"/>s.
        /// </param>
        /// <param name="states">
        /// Specifies states to include when listing shares.
        /// </param>
        /// <param name="prefix">
        /// String that filters the results to return only shares whose name
        /// begins with the specified prefix.
        /// </param>
        /// <param name="pageSizeHint">
        /// Gets or sets a value indicating the size of the page that should be
        /// requested.
        /// </param>
        /// <param name="async">
        /// Whether to invoke the operation asynchronously.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate
        /// notifications that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// A <see cref="Response{SharesSegment}"/> describing a
        /// segment of the shares in the storage account.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure occurs.
        /// </remarks>
        internal async Task <Response <SharesSegment> > GetSharesInternal(
            string marker,
            ShareTraits traits,
            ShareStates states,
            string prefix,
            int?pageSizeHint,
            bool async,
            CancellationToken cancellationToken)
        {
            using (Pipeline.BeginLoggingScope(nameof(ShareServiceClient)))
            {
                Pipeline.LogMethodEnter(
                    nameof(ShareServiceClient),
                    message:
                    $"{nameof(Uri)}: {Uri}\n" +
                    $"{nameof(marker)}: {marker}");
                try
                {
                    Response <SharesSegment> response = await FileRestClient.Service.ListSharesSegmentAsync(
                        ClientDiagnostics,
                        Pipeline,
                        Uri,
                        version : Version.ToVersionString(),
                        marker : marker,
                        prefix : prefix,
                        maxresults : pageSizeHint,
                        include : ShareExtensions.AsIncludeItems(traits, states),
                        async : async,
                        cancellationToken : cancellationToken)
                                                        .ConfigureAwait(false);

                    if ((traits & ShareTraits.Metadata) != ShareTraits.Metadata)
                    {
                        IEnumerable <ShareItem> shareItems = response.Value.ShareItems;
                        foreach (ShareItem shareItem in shareItems)
                        {
                            shareItem.Properties.Metadata = null;
                        }
                    }
                    return(response);
                }
                catch (Exception ex)
                {
                    Pipeline.LogException(ex);
                    throw;
                }
                finally
                {
                    Pipeline.LogMethodExit(nameof(ShareServiceClient));
                }
            }
        }
Пример #3
0
 /// <summary>
 /// The <see cref="GetSharesInternal"/> operation returns a
 /// single segment of shares in the storage account, starting
 /// from the specified <paramref name="marker"/>.  Use an empty
 /// <paramref name="marker"/> to start enumeration from the beginning
 /// and the <see cref="SharesSegment.NextMarker"/> if it's not
 /// empty to make subsequent calls to <see cref="GetSharesAsync"/>
 /// to continue enumerating the shares segment by segment.
 ///
 /// For more information, <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares"/>.
 /// </summary>
 /// <param name="marker">
 /// An optional string value that identifies the segment of the list
 /// of shares to be returned with the next listing operation.  The
 /// operation returns a non-empty <see cref="SharesSegment.NextMarker"/>
 /// if the listing operation did not return all shares remaining
 /// to be listed with the current segment.  The NextMarker value can
 /// be used as the value for the <paramref name="marker"/> parameter
 /// in a subsequent call to request the next segment of list items.
 /// </param>
 /// <param name="traits">
 /// Specifies traits to include in the <see cref="ShareItem"/>s.
 /// </param>
 /// <param name="states">
 /// Specifies states to include when listing shares.
 /// </param>
 /// <param name="prefix">
 /// String that filters the results to return only shares whose name
 /// begins with the specified prefix.
 /// </param>
 /// <param name="pageSizeHint">
 /// Gets or sets a value indicating the size of the page that should be
 /// requested.
 /// </param>
 /// <param name="async">
 /// Whether to invoke the operation asynchronously.
 /// </param>
 /// <param name="cancellationToken">
 /// Optional <see cref="CancellationToken"/> to propagate
 /// notifications that the operation should be cancelled.
 /// </param>
 /// <returns>
 /// A <see cref="Response{SharesSegment}"/> describing a
 /// segment of the shares in the storage account.
 /// </returns>
 /// <remarks>
 /// A <see cref="RequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 internal async Task <Response <SharesSegment> > GetSharesInternal(
     string marker,
     ShareTraits traits,
     ShareStates states,
     string prefix,
     int?pageSizeHint,
     bool async,
     CancellationToken cancellationToken)
 {
     using (Pipeline.BeginLoggingScope(nameof(FileServiceClient)))
     {
         Pipeline.LogMethodEnter(
             nameof(FileServiceClient),
             message:
             $"{nameof(Uri)}: {Uri}\n" +
             $"{nameof(marker)}: {marker}");
         try
         {
             return(await FileRestClient.Service.ListSharesSegmentAsync(
                        ClientDiagnostics,
                        Pipeline,
                        Uri,
                        marker : marker,
                        prefix : prefix,
                        maxresults : pageSizeHint,
                        include : FileExtensions.AsIncludeItems(traits, states),
                        async : async,
                        cancellationToken : cancellationToken)
                    .ConfigureAwait(false));
         }
         catch (Exception ex)
         {
             Pipeline.LogException(ex);
             throw;
         }
         finally
         {
             Pipeline.LogMethodExit(nameof(FileServiceClient));
         }
     }
 }
        /// <summary>
        /// Convert the details into ListSharesIncludeType values.
        /// </summary>
        /// <returns>ListSharesIncludeType values</returns>
        internal static IEnumerable <ListSharesIncludeType> AsIncludeItems(ShareTraits traits, ShareStates states)
        {
            // NOTE: Multiple strings MUST be appended in alphabetic order or signing the string for authentication fails!
            // TODO: Remove this requirement by pushing it closer to header generation.
            var items = new List <ListSharesIncludeType>();

            if ((states & ShareStates.Deleted) == ShareStates.Deleted)
            {
                items.Add(ListSharesIncludeType.Deleted);
            }
            if ((traits & ShareTraits.Metadata) == ShareTraits.Metadata)
            {
                items.Add(ListSharesIncludeType.Metadata);
            }
            if ((states & ShareStates.Snapshots) == ShareStates.Snapshots)
            {
                items.Add(ListSharesIncludeType.Snapshots);
            }
            return(items.Count > 0 ? items : null);
        }
 /// <summary>
 /// The <see cref="GetSharesAsync"/> operation returns an async collection
 /// of the shares in the storage account.  Enumerating the shares may
 /// make multiple requests to the service while fetching all the
 /// values.
 ///
 /// For more information, <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares"/>.
 /// </summary>
 /// <param name="traits">
 /// Specifies traits to include in the <see cref="ShareItem"/>s.
 /// </param>
 /// <param name="states">
 /// Specifies states to include when listing shares.
 /// </param>
 /// <param name="prefix">
 /// String that filters the results to return only shares whose name
 /// begins with the specified prefix.
 /// </param>
 /// <param name="cancellationToken">
 /// Optional <see cref="CancellationToken"/> to propagate
 /// notifications that the operation should be cancelled.
 /// </param>
 /// <returns>
 /// A <see cref="AsyncPageable{T}"/> describing the shares in
 /// the storage account.
 /// </returns>
 /// <remarks>
 /// A <see cref="RequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 public virtual AsyncPageable <ShareItem> GetSharesAsync(
     ShareTraits traits = ShareTraits.None,
     ShareStates states = ShareStates.None,
     string prefix      = default,
     CancellationToken cancellationToken = default) =>
 new GetSharesAsyncCollection(this, traits, states, prefix).ToAsyncCollection(cancellationToken);