Container for the parameters to the ListObjects operation.

Returns some or all (up to 1000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket.

Inheritance: Amazon.Runtime.AmazonWebServiceRequest
        public async Task<IEnumerable<StorageProviderItem>> GetChildrenByParentItem(StorageProviderItem parent)
        {
            using (var api = AmazonS3Helper.GetApi(_account))
            {
                if (parent.Id == "/")
                {
                    var response = await api.ListBucketsAsync();
                    
                    var items = response.Buckets.Select(_ => new StorageProviderItem
                    {
                        Id = _.BucketName,
                        Name = _.BucketName,
                        Type = StorageProviderItemType.Folder,
                        ParentReferenceId = parent.Id
                    });

                    return items.ToArray();
                }
                else
                {
                    string bucket;
                    string filename;
                    GetBucketAndKey(parent.Id, out bucket, out filename);
                    var filenameLength = string.IsNullOrEmpty(filename) ? 0 : filename.Length;

                    var request = new ListObjectsV2Request
                    {
                        BucketName = bucket,
                        Prefix = filename,
                    };

                    var items = new List<StorageProviderItem>();
                    ListObjectsV2Response response;
                    var finished = false;

                    do
                    {
                        response = await api.ListObjectsV2Async(request);
                        foreach (var o in response.S3Objects)
                        {
                            var normalized = o.Key.Substring(filenameLength);
                            if (string.IsNullOrEmpty(normalized))
                                continue;

                            if (normalized.EndsWith("/"))
                            {
                                normalized = normalized.Remove(normalized.Length - 1);
                            }


                            if (normalized.Contains('/'))
                            {
                                finished = true;
                                break;
                            }

                            items.Add(new StorageProviderItem
                            {
                                Id = bucket + "/" + o.Key,
                                Name = normalized,
                                Type = o.Size > 0 ? StorageProviderItemType.File : StorageProviderItemType.Folder,
                                ParentReferenceId = parent.Id,
                            });
                        }

                        if (finished)
                            break;

                        request.ContinuationToken = response.NextContinuationToken;

                    } while (response.IsTruncated);

                    return items.ToArray();
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Initiates the asynchronous execution of the ListObjectsV2 operation.
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the ListObjectsV2 operation on AmazonS3Client.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void ListObjectsV2Async(ListObjectsV2Request request, AmazonServiceCallback<ListObjectsV2Request, ListObjectsV2Response> callback, AsyncOptions options = null)
 {
     options = options == null?new AsyncOptions():options;
     var marshaller = new ListObjectsV2RequestMarshaller();
     var unmarshaller = ListObjectsV2ResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<ListObjectsV2Request,ListObjectsV2Response> responseObject 
                     = new AmazonServiceResult<ListObjectsV2Request,ListObjectsV2Response>((ListObjectsV2Request)req, (ListObjectsV2Response)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<ListObjectsV2Request>(request, marshaller, unmarshaller, options, callbackHelper);
 }
Exemple #3
0
        /// <summary>
        /// Initiates the asynchronous execution of the ListObjectsV2 operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the ListObjectsV2 operation on AmazonS3Client.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndListObjectsV2
        ///         operation.</returns>
        public IAsyncResult BeginListObjectsV2(ListObjectsV2Request request, AsyncCallback callback, object state)
        {
            var marshaller = new ListObjectsV2RequestMarshaller();
            var unmarshaller = ListObjectsV2ResponseUnmarshaller.Instance;

            return BeginInvoke<ListObjectsV2Request>(request, marshaller, unmarshaller,
                callback, state);
        }
 private Amazon.S3.Model.ListObjectsV2Response CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.ListObjectsV2Request request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Storage Service (S3)", "ListObjectsV2");
     try
     {
         #if DESKTOP
         return(client.ListObjectsV2(request));
         #elif CORECLR
         return(client.ListObjectsV2Async(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
Exemple #5
0
        /// <summary>
        /// Returns some or all (up to 1000) of the objects in a bucket. You can use the request
        /// parameters as selection criteria to return a subset of the objects in a bucket. Note:
        /// ListObjectsV2 is the revised List Objects API and we recommend you use this revised
        /// API for new application development.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the ListObjectsV2 service method.</param>
        /// 
        /// <returns>The response from the ListObjectsV2 service method, as returned by S3.</returns>
        public ListObjectsV2Response ListObjectsV2(ListObjectsV2Request request)
        {
            var marshaller = new ListObjectsV2RequestMarshaller();
            var unmarshaller = ListObjectsV2ResponseUnmarshaller.Instance;

            return Invoke<ListObjectsV2Request,ListObjectsV2Response>(request, marshaller, unmarshaller);
        }
        public object Execute(ExecutorContext context)
        {
            var cmdletContext      = context as CmdletContext;
            var useParameterSelect = this.Select.StartsWith("^") || this.PassThru.IsPresent;

            // create request and set iteration invariants
            var request = new Amazon.S3.Model.ListObjectsV2Request();

            if (cmdletContext.BucketName != null)
            {
                request.BucketName = cmdletContext.BucketName;
            }
            if (cmdletContext.Delimiter != null)
            {
                request.Delimiter = cmdletContext.Delimiter;
            }
            if (cmdletContext.Encoding != null)
            {
                request.Encoding = cmdletContext.Encoding;
            }
            if (cmdletContext.ExpectedBucketOwner != null)
            {
                request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner;
            }
            if (cmdletContext.FetchOwner != null)
            {
                request.FetchOwner = cmdletContext.FetchOwner.Value;
            }
            if (cmdletContext.Prefix != null)
            {
                request.Prefix = cmdletContext.Prefix;
            }
            if (cmdletContext.RequestPayer != null)
            {
                request.RequestPayer = cmdletContext.RequestPayer;
            }
            if (cmdletContext.StartAfter != null)
            {
                request.StartAfter = cmdletContext.StartAfter;
            }

            // Initialize loop variants and commence piping
            System.String _nextToken      = null;
            int?          _emitLimit      = null;
            int           _retrievedSoFar = 0;

            if (AutoIterationHelpers.HasValue(cmdletContext.ContinuationToken))
            {
                _nextToken = cmdletContext.ContinuationToken;
            }
            if (cmdletContext.MaxKey.HasValue)
            {
                // The service has a maximum page size of 1000. If the user has
                // asked for more items than page max, and there is no page size
                // configured, we rely on the service ignoring the set maximum
                // and giving us 1000 items back. If a page size is set, that will
                // be used to configure the pagination.
                // We'll make further calls to satisfy the user's request.
                _emitLimit = cmdletContext.MaxKey;
            }
            var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.ContinuationToken));

            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            do
            {
                request.ContinuationToken = _nextToken;
                if (_emitLimit.HasValue)
                {
                    int correctPageSize = Math.Min(1000, _emitLimit.Value);
                    request.MaxKeys = AutoIterationHelpers.ConvertEmitLimitToInt32(correctPageSize);
                }

                CmdletOutput output;

                try
                {
                    var    response       = CallAWSServiceOperation(client, request);
                    object pipelineOutput = null;
                    if (!useParameterSelect)
                    {
                        pipelineOutput = cmdletContext.Select(response, this);
                    }
                    output = new CmdletOutput
                    {
                        PipelineOutput  = pipelineOutput,
                        ServiceResponse = response
                    };
                    int _receivedThisCall = response.S3Objects.Count;

                    _nextToken       = response.NextContinuationToken;
                    _retrievedSoFar += _receivedThisCall;
                    if (_emitLimit.HasValue)
                    {
                        _emitLimit -= _receivedThisCall;
                    }
                }
                catch (Exception e)
                {
                    if (_retrievedSoFar == 0 || !_emitLimit.HasValue)
                    {
                        output = new CmdletOutput {
                            ErrorResponse = e
                        };
                    }
                    else
                    {
                        break;
                    }
                }

                ProcessOutput(output);
            } while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextToken) && (!_emitLimit.HasValue || _emitLimit.Value >= 1));


            if (useParameterSelect)
            {
                WriteObject(cmdletContext.Select(null, this));
            }


            return(null);
        }
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;

            #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
            var useParameterSelect = this.Select.StartsWith("^") || this.PassThru.IsPresent;
            #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute

            // create request and set iteration invariants
            var request = new Amazon.S3.Model.ListObjectsV2Request();

            if (cmdletContext.BucketName != null)
            {
                request.BucketName = cmdletContext.BucketName;
            }
            if (cmdletContext.Delimiter != null)
            {
                request.Delimiter = cmdletContext.Delimiter;
            }
            if (cmdletContext.Encoding != null)
            {
                request.Encoding = cmdletContext.Encoding;
            }
            if (cmdletContext.ExpectedBucketOwner != null)
            {
                request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner;
            }
            if (cmdletContext.FetchOwner != null)
            {
                request.FetchOwner = cmdletContext.FetchOwner.Value;
            }
            if (cmdletContext.MaxKey != null)
            {
                request.MaxKeys = AutoIterationHelpers.ConvertEmitLimitToServiceTypeInt32(cmdletContext.MaxKey.Value);
            }
            if (cmdletContext.Prefix != null)
            {
                request.Prefix = cmdletContext.Prefix;
            }
            if (cmdletContext.RequestPayer != null)
            {
                request.RequestPayer = cmdletContext.RequestPayer;
            }
            if (cmdletContext.StartAfter != null)
            {
                request.StartAfter = cmdletContext.StartAfter;
            }

            // Initialize loop variant and commence piping
            var _nextToken             = cmdletContext.ContinuationToken;
            var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.ContinuationToken));

            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
            do
            {
                request.ContinuationToken = _nextToken;

                CmdletOutput output;

                try
                {
                    var response = CallAWSServiceOperation(client, request);

                    object pipelineOutput = null;
                    if (!useParameterSelect)
                    {
                        pipelineOutput = cmdletContext.Select(response, this);
                    }
                    output = new CmdletOutput
                    {
                        PipelineOutput  = pipelineOutput,
                        ServiceResponse = response
                    };

                    _nextToken = response.NextContinuationToken;
                }
                catch (Exception e)
                {
                    output = new CmdletOutput {
                        ErrorResponse = e
                    };
                }

                ProcessOutput(output);
            } while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextToken));

            if (useParameterSelect)
            {
                WriteObject(cmdletContext.Select(null, this));
            }


            return(null);
        }
Exemple #8
0
        /// <summary>
        /// Initiates the asynchronous execution of the ListObjectsV2 operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the ListObjectsV2 operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<ListObjectsV2Response> ListObjectsV2Async(ListObjectsV2Request request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new ListObjectsV2RequestMarshaller();
            var unmarshaller = ListObjectsV2ResponseUnmarshaller.Instance;

            return InvokeAsync<ListObjectsV2Request,ListObjectsV2Response>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
 internal ListObjectsV2Paginator(IAmazonS3 client, ListObjectsV2Request request)
 {
     this._client  = client;
     this._request = request;
 }
 /// <summary>
 /// Paginator for ListObjectsV2 operation
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public IListObjectsV2Paginator ListObjectsV2(ListObjectsV2Request request)
 {
     return(new ListObjectsV2Paginator(this._client, request));
 }