OCISDK/OCISDK/ObjectStorage/IO/ObjectStorageDirectoryInfo.cs
/// <summary>
/// Get the object in the bucket.
/// </summary>
/// <param name="prefix"></param>
/// <param name="searchOption"></param>
/// <param name="nextStartWith"></param>
/// <returns></returns>
Get the object in the bucket.
Get the object in the bucket .
private List<ObjectSummary> GetOciObjects(string prefix, SearchOption searchOption, int maxCount, string nextStartWith = "")
        {
            var res = new List<ObjectSummary>();
            if (maxCount == -1)
                maxCount = GET_OBJECT_LIMIT;
            string delimiter = "";
            var prefixReg = ObjectStorageHelper.EncodeKey(prefix);
            if (prefixReg.Contains("/"))
            {
                delimiter = "/";
            }
            var listObjectsRequest = new ListObjectsRequest()
            {
                NamespaceName = NamespaceName,
                BucketName = BucketName,
                Start = nextStartWith,
                Delimiter = delimiter,
                Prefix = prefixReg,
                Fields = new List<string> { "name", "size", "timeCreated", "md5" },
                Limit = maxCount
            };
            var objects = Client.ListObjects(listObjectsRequest);
            if (searchOption == SearchOption.TopDirectoryOnly)
            {
                foreach (var o in objects.ListObjects.Objects)
                {
                    if (CheckAddObject(o, prefixReg, searchOption))
                    {
                        res.Add(o);
                    }
                }
            }
            else
            {
                foreach (var o in objects.ListObjects.Objects)
                {
                    if (CheckAddObject(o, prefixReg, searchOption))
                    {
                        res.Add(o);
                    }
                }
            }
            NextPageId = objects.ListObjects.NextStartWith;
            if (!string.IsNullOrEmpty(objects.ListObjects.NextStartWith))
            {
                if (maxCount == -1)
                    res.AddRange(GetOciObjects(ObjectStorageHelper.DecodeKey(prefix), searchOption, maxCount, objects.ListObjects.NextStartWith));
            }
            if (objects.ListObjects.Prefixes != null && objects.ListObjects.Prefixes.Count > 0)
            {
                if (searchOption == SearchOption.AllDirectories)
                {
                    foreach (var pre in objects.ListObjects.Prefixes)
                    {
                        res.AddRange(GetOciObjects(pre, searchOption, maxCount));
                    }
                }
                else
                {
                    var newPrefix = objects.ListObjects.Prefixes.Where(p => p == prefixReg + "/");
                    if (newPrefix != null && newPrefix.Count() > 0)
                    {
                        foreach (var pre in newPrefix)
                        {
                            res.AddRange(GetOciObjects(pre, searchOption, maxCount));
                        }
                    }
                }
            }
            return res;
        }
private List < ObjectSummary > GetOciObjects ( string prefix , SearchOption searchOption , int maxCount , string nextStartWith = " " ) { var res = new List < ObjectSummary > ( ) ; if ( maxCount == - 1 ) maxCount = GET_OBJECT_LIMIT ; string delimiter = " " ; var prefixReg = ObjectStorageHelper . EncodeKey ( prefix ) ; if ( prefixReg . Contains ( " " ) ) { delimiter = " " ; } var listObjectsRequest = new ListObjectsRequest ( ) { NamespaceName = NamespaceName , BucketName = BucketName , Start = nextStartWith , Delimiter = delimiter , Prefix = prefixReg , Fields = new List < string > { " " , " " , " " , " " } , Limit = maxCount } ; var objects = Client . ListObjects ( listObjectsRequest ) ; if ( searchOption == SearchOption . TopDirectoryOnly ) { foreach ( var o in objects . ListObjects . Objects ) { if ( CheckAddObject ( o , prefixReg , searchOption ) ) { res . Add ( o ) ; } } } else { foreach ( var o in objects . ListObjects . Objects ) { if ( CheckAddObject ( o , prefixReg , searchOption ) ) { res . Add ( o ) ; } } } NextPageId = objects . ListObjects . NextStartWith ; if ( ! string . IsNullOrEmpty ( objects . ListObjects . NextStartWith ) ) { if ( maxCount == - 1 ) res . AddRange ( GetOciObjects ( ObjectStorageHelper . DecodeKey ( prefix ) , searchOption , maxCount , objects . ListObjects . NextStartWith ) ) ; } if ( objects . ListObjects . Prefixes != null && objects . ListObjects . Prefixes . Count > 0 ) { if ( searchOption == SearchOption . AllDirectories ) { foreach ( var pre in objects . ListObjects . Prefixes ) { res . AddRange ( GetOciObjects ( pre , searchOption , maxCount ) ) ; } } else { var newPrefix = objects . ListObjects . Prefixes . Where ( p => p == prefixReg + " " ) ; if ( newPrefix != null && newPrefix . Count ( ) > 0 ) { foreach ( var pre in newPrefix ) { res . AddRange ( GetOciObjects ( pre , searchOption , maxCount ) ) ; } } } } return res ; }
Get the object in the bucket.
Get the object in the bucket .
// next check // all sub prefix
None
prefix
string
None
searchOption
SearchOption
None
maxCount
int
nextStartWith
string
None