private static void ProcessDirectory(S3DirectoryInfo dir) { sdd = new ScannedDirectoryData(dir.FullName); WriteLine($"\r\nProcessing directory: {dir.FullName}"); ScanDirectory(dir); SubmitBatch(); DisplayResults(); processedDirectories.Add(sdd); }
static void Main(string[] args) { stopwatch.Start(); WriteLine("\r\n\r\n***** " + DateTime.Now + " *****\r\n"); getPrefs(args); while (!authorized) { GetCredentials(); // scan S3 using (var client = new AmazonS3Client(accessKey, secretKey, RegionEndpoint.USEast1)) { try { S3DirectoryInfo root = new S3DirectoryInfo(client, bucket, key); S3DirectoryInfo[] dirs = root.EnumerateDirectories().ToArray(); authorized = true; bool run = true; while (run) { DisplayDirectories(dirs); WriteLine("\r\nEnter directory number to process directory, or enter 0 to process all."); string response = Console.ReadLine(); bool success = int.TryParse(response, out dirNum); while (!success || dirNum < 0 || dirNum > dirs.Length) { WriteLine("\r\nInvalid entry. Enter 0 or a directory number:"); response = Console.ReadLine(); success = int.TryParse(response, out dirNum); } if (dirNum == 0) { sdd = new ScannedDirectoryData(root.FullName); // process files in root directory WriteLine($"Scanning files in {root.FullName}..."); foreach (S3FileInfo f in root.EnumerateFiles()) { try { ScanFile(f); } catch (Exception e) { LogError(e.Message); } } db.AWSS3Objects.InsertAllOnSubmit(insertionList); SubmitBatch(); // process each sub directory recursively and submit foreach (S3DirectoryInfo d in dirs) { ProcessDirectory(d); } run = false; } else { ProcessDirectory(dirs[dirNum - 1]); WriteLine($"\r\nDo you want to scan another directory? (Y/N)"); response = Console.ReadLine(); while (response.ToUpper() != "Y" && response.ToUpper() != "N") { WriteLine("\r\nInvalid response. Enter Y or N:"); response = Console.ReadLine(); } run = response.ToUpper() == "Y"; } } DisplayTotals(); stopwatch.Stop(); WriteLine($"\r\nTime elapsed: {stopwatch.Elapsed}"); } catch (Exception e) { LogError("UNAUTHORIZED"); } } } Console.ReadKey(); }