public async Task UpdateDirAsync() { SubDirs.Clear(); S3Objs.Clear(); var S3ListFiles = await _is3.ListFilesAsync(CurrentDir.FullPathName); IEnumerable <S3Object> diststrs = S3ListFiles.Where((s) => { return(s.Key.StartsWith(CurrentDir.FullPathName)); }).DistinctBy((s) => { string[] ar2 = s.Key.Split('/'); return(ar2[Level]); }); foreach (var s in diststrs) { string[] ar2 = s.Key.Split('/'); if (ar2[Level] != "") { if (ar2.Length - 1 == Level) { S3Objs.Add(new S3FileObject { Name = ar2[Level], DirPath = CurrentDir.FullPathName, FullPathName = s.Key, Owner = s.Owner, Size = s.Size, LastModified = s.LastModified, ETag = s.ETag, StorageClass = s.StorageClass.Value }); } else { SubDirs.Add(new S3DirObject { FullPathName = String.Join("/", ar2.Take(Level + 1)), Name = ar2[Level] }); } } } //foreach (var dir in SubDirs) //{ // Console.WriteLine("======== Name = {0} | FullName = {1}", // dir.Name, dir.FullPathName); //} }
/// <summary> /// Looks for dirs and files that exist in the other directory but not in this. Files inside missing dirs are not listed. /// </summary> /// <param name="other"></param> /// <returns></returns> public IEnumerable <string> Missing(Dir other) { // Iterate the other collection to find items unique to it. var missingFiles = other.Files.Where(a => !Files.Any(b => a.Name == b.Name)); var missingDirs = other.SubDirs.Where(a => !SubDirs.Any(b => a.Name == b.Name)); var output = missingFiles.Select(a => a.Path); output = output.Concat(missingDirs.Select(a => a.Path)); // Iterate through this collection so the we can look for matches. foreach (Dir dir in SubDirs) { var match = other.SubDirs.FirstOrDefault(a => a.Name == dir.Name); if (null != match) { // If the dir exists, look for missing subdirs recursively. output = output.Concat(dir.Missing(match)); } } return(output); }