Esempio n. 1
0
        private async Task <IReadOnlyCollection <Blob> > EnumerateDirectoryAsync(
            string path,
            ListOptions options,
            UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID,
            CancellationToken cancelToken        = default)
        {
            var result = new List <Blob>();

            string listAfter = "";

            while (options.MaxResults == null || result.Count < options.MaxResults.Value)
            {
                List <DirectoryEntry> page =
                    await EnumerateDirectoryAsync(path, _listBatchSize, listAfter, "", userIdFormat, cancelToken).ConfigureAwait(false);

                //no more results
                if (page == null || page.Count == 0)
                {
                    break;
                }

                //set pointer to next page
                listAfter = page[page.Count - 1].Name;

                result.AddRange(page.Select(p => ToBlobId(path, p, options.IncludeAttributes)));
            }

            return(result);
        }
 /// <summary>
 /// Get Directory or file info
 /// </summary>
 /// <param name="path">Path of file or directory</param>
 /// <param name="userIdFormat">User or group Id format</param>
 /// <param name="cancelToken">Cancellation token</param>
 /// <returns></returns>
 public override DirectoryEntry GetDirectoryEntry(string path,
                                                  UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID,
                                                  CancellationToken cancelToken        = default(CancellationToken))
 {
     // Update the length here
     if (_directoryEntries.ContainsKey(path))
     {
         if (_directoryEntries[path].Entry.Type == DirectoryEntryType.FILE)
         {
             _directoryEntries[path].Entry.Length = _directoryEntries[path].DataStream.Length; // Update the stream length
         }
         return(new DirectoryEntry(_directoryEntries[path].Entry));                            // send deep copy
     }
     // The input path path can be a directory which is not in the dictionary
     foreach (var entries in _directoryEntries.Keys)
     {
         if (entries.StartsWith(path + "/")) // This has to be directory
         {
             return(new DirectoryEntry(path)
             {
                 Type = DirectoryEntryType.DIRECTORY,
                 Length = 0
             });
         }
     }
     throw new AdlsException("Not exist")
           {
               HttpStatus = HttpStatusCode.NotFound
           };
 }
Esempio n. 3
0
        /// <summary>
        /// Returns a list of entries contained under the given directory
        /// </summary>
        /// <param name="path">Path of directory or file</param>
        /// <param name="userIdFormat">User or group Id format</param>
        /// <param name="cancelToken">Cancellation token</param>
        /// <returns></returns>
        public override IEnumerable <DirectoryEntry> EnumerateDirectory(string path, UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID,
                                                                        CancellationToken cancelToken = default(CancellationToken))
        {
            if (!path.EndsWith("/"))
            {
                path = path + "/";
            }
            var listToReturn = new List <DirectoryEntry>();

            // This is not fully mocked. Very naive only works for directory that has files and empty directories
            foreach (var directoryEntriesKey in _directoryEntries.Keys)
            {
                if (directoryEntriesKey.StartsWith(path))
                {
                    listToReturn.Add(new DirectoryEntry(_directoryEntries[directoryEntriesKey].Entry));
                }
            }
            return(listToReturn);
        }
Esempio n. 4
0
        internal async Task <List <DirectoryEntry> > EnumerateDirectoryAsync(string path,
                                                                             int maxEntries, string listAfter, string listBefore, UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID, CancellationToken cancelToken = default)
        {
            //ADLS requires a root prefix
            path = StoragePath.Normalize(path);

            var resp = new OperationResponse();
            List <DirectoryEntry> page = await Core.ListStatusAsync(path, listAfter, listBefore, maxEntries, userIdFormat, _client,
                                                                    new RequestOptions(new ExponentialRetryPolicy(2, 1000)),
                                                                    resp).ConfigureAwait(false);

            return(page);
            //return new FileStatusOutput(listBefore, listAfter, maxEntries, userIdFormat, _client, path);
        }
Esempio n. 5
0
 /// <summary>
 /// Gets the ACL entry list, owner ID, group ID, octal permission and sticky bit (only for a directory) of the file/directory
 /// </summary>
 /// <param name="path">Path of the file or directory</param>
 /// <param name="userIdFormat">way to represent the user/group object</param>
 /// <param name="cancelToken">CancellationToken to cancel the request</param>
 public override AclStatus GetAclStatus(string path, UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID, CancellationToken cancelToken = default(CancellationToken))
 {
     return(GetAclStatusAsync(path, userIdFormat, cancelToken).GetAwaiter().GetResult());
 }
Esempio n. 6
0
 /// <summary>
 /// Gets the ACL entry list, owner ID, group ID, octal permission and sticky bit (only for a directory) of the file/directory
 /// </summary>
 /// <param name="path">Path of the file or directory</param>
 /// <param name="userIdFormat">way to represent the user/group object</param>
 /// <param name="cancelToken">CancellationToken to cancel the request</param>
 public override async Task <AclStatus> GetAclStatusAsync(string path, UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID, CancellationToken cancelToken = default(CancellationToken))
 {
     return(await Task.Run(() => new AclStatus(_directoryEntries[path].AclData), cancelToken));
 }
Esempio n. 7
0
        internal async Task <List <DirectoryEntry> > EnumerateDirectoryAsync(string path,
                                                                             int maxEntries, string listAfter, string listBefore, UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID, CancellationToken cancelToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("Path is null");
            }

            var resp = new OperationResponse();
            List <DirectoryEntry> page = await Core.ListStatusAsync(path, listAfter, listBefore, maxEntries, userIdFormat, _client,
                                                                    new RequestOptions(new ExponentialRetryPolicy()),
                                                                    resp);

            return(page);
            //return new FileStatusOutput(listBefore, listAfter, maxEntries, userIdFormat, _client, path);
        }
 /// <summary>
 /// Gets the ACL entry list, owner ID, group ID, octal permission and sticky bit (only for a directory) of the file/directory
 /// </summary>
 /// <param name="path">Path of the file or directory</param>
 /// <param name="userIdFormat">way to represent the user/group object</param>
 /// <param name="cancelToken">CancellationToken to cancel the request</param>
 public override AclStatus GetAclStatus(string path, UserGroupRepresentation userIdFormat = UserGroupRepresentation.ObjectID, CancellationToken cancelToken = default(CancellationToken))
 {
     return(new AclStatus(_directoryEntries[path].AclData));
 }