public override async Task RestoreDeletedItemsAsync()

in AdlsDotNetSDK/MockAdlsFileSystem/MockAdlsClient.cs [420:482]


        public override async Task RestoreDeletedItemsAsync(string pathOfFileToRestoreInTrash, string restoreDestination, string type, string restoreAction = "", CancellationToken cancelToken = default(CancellationToken))
        {
            await Task.Run(() =>
            {
                // convert FsUrls back to relative paths
                pathOfFileToRestoreInTrash = pathOfFileToRestoreInTrash.Substring(("adl://" + accountName).Length);
                restoreDestination = restoreDestination.Substring(("adl://" + accountName).Length);
 
                if (!_trashDirectoryEntries.Keys.Contains(pathOfFileToRestoreInTrash))
                {
                    throw new ArgumentException();
                }

                var enumerator = _trashDirectoryEntries.GetEnumerator();
                while(enumerator.MoveNext())
                {
                    if(enumerator.Current.Key.Equals(pathOfFileToRestoreInTrash))
                    {
                        var deletedEntry = _trashDirectoryEntries[pathOfFileToRestoreInTrash];
                        var entryType = deletedEntry.Entry.Type;

                        if(String.IsNullOrEmpty(type) || !(type.Equals("file") || type.Equals("folder")))
                        {
                            throw new ArgumentException();
                        }

                        if((type.Equals("file") ? DirectoryEntryType.FILE : DirectoryEntryType.DIRECTORY) != entryType)
                        {
                            throw new ArgumentException();
                        }

                        // Make sure there is no conflict
                        if (_directoryEntries.ContainsKey(restoreDestination))
                        {
                            if (String.Equals(restoreAction, "copy", StringComparison.OrdinalIgnoreCase))
                            {
                                restoreDestination += "_" + random.Next(10000000);
                            }
                            else if (String.Equals(restoreAction, "overwrite", StringComparison.OrdinalIgnoreCase)) // TODO: type is stream
                            {
                                if (String.Equals(type, "folder", StringComparison.OrdinalIgnoreCase))
                                {
                                    throw new ArgumentException();
                                }
                            }
                        }

                        // Start the restore;
                        deletedEntry.Entry.FullName = restoreDestination;
                        deletedEntry.Entry.Name = restoreDestination.Substring(restoreDestination.LastIndexOf("/") + 1); // TODO: fix name
                        
                        // Add it back
                        _directoryEntries.Add(restoreDestination, deletedEntry);

                        // Remove it from trash items
                        _trashDirectoryEntries.Remove(pathOfFileToRestoreInTrash);
                        break;
                    }
                }

                return;
            }, cancelToken);
        }