Example #1
0
        private void ApplyDelimiterFilter(S3ObjectSearchRequest searchRequest, S3ObjectSearchResponse searchResponse)
        {
            IList<string> prefixStrings = new List<string>();
              IList<S3Object> objectsToRemove = new List<S3Object>();
              foreach (var s3Object in searchResponse.S3Objects)
              {
            var match = Regex.Match(s3Object.Key,
                                string.Format("({0}.*?{1}).*?", searchRequest.Prefix, searchRequest.Delimiter));
            if (!match.Success) continue;

            var @group = match.Groups[0].Value;
            if (!prefixStrings.Contains(@group))
            {
              prefixStrings.Add(@group);
            }
            objectsToRemove.Add(s3Object);
              }

              foreach (var s3Object in objectsToRemove)
              {
            searchResponse.S3Objects.Remove(s3Object);
              }

              searchResponse.Prefixes = prefixStrings;
        }
Example #2
0
        private void QueryS3Objects(S3ObjectSearchRequest searchRequest, S3ObjectSearchResponse searchResponse)
        {
            using (var session = documentStore.OpenSession())
              {
            var query = string.IsNullOrWhiteSpace(searchRequest.Prefix) ? string.Format("Bucket:{0}", searchRequest.BucketName) :
                                                                      string.Format("Bucket:{0} AND Key:{1}*", searchRequest.BucketName, searchRequest.Prefix);

            searchResponse.S3Objects = session.Advanced
                                          .LuceneQuery<S3Object, S3Object_Search>()
                                          .Where(query)
                                          .Take(searchRequest.MaxKeys ?? 1000)
                                          .WaitForNonStaleResultsAsOfNow()
                                          .ToList();
              }

              if (!string.IsNullOrWhiteSpace(searchRequest.Delimiter))
              {
            ApplyDelimiterFilter(searchRequest, searchResponse);
              }
        }
Example #3
0
        public S3ObjectSearchResponse GetObjects(S3ObjectSearchRequest searchRequest)
        {
            var searchResponse = new S3ObjectSearchResponse
              {
            BucketName = searchRequest.BucketName,
            Delimiter = searchRequest.Delimiter,
            Marker = searchRequest.Marker,
            MaxKeys = searchRequest.MaxKeys,
            Prefix = searchRequest.Prefix,
            IsTruncated = false,
            S3Objects = new List<S3Object>(),
            Prefixes = new List<string>()
              };

              var bucket = GetBucket(searchRequest.BucketName);
              if (bucket == null)
              {
            return searchResponse;
              }

              QueryS3Objects(searchRequest, searchResponse);

              return searchResponse;
        }