public int Scan() { ServerConfiguration serverConfiguration = LoadServerConfiguration(); if (serverConfiguration == null) { return(1); } string databaseFilePath = serverConfiguration.DatabaseFilePath; if (String.IsNullOrWhiteSpace(databaseFilePath)) { Console.WriteLine("Database file path is not set in the server configuration file."); return(2); } if (!File.Exists(databaseFilePath)) { Console.WriteLine($"Couldn't fine the database file at {databaseFilePath}"); return(3); } Console.WriteLine($"Opening database \"{databaseFilePath}\"..."); LocalDatabase localDatabase = LocalDatabase.OpenDatabase(databaseFilePath); List <LibraryFile> foundFiles; switch (scanLibrary) { case ScanLibrary.LIBGEN_NONFICTION: foundFiles = Scan(localDatabase.CountNonFictionBooks(), localDatabase.GetNonFictionBookByMd5Hash); break; case ScanLibrary.LIBGEN_FICTION: foundFiles = Scan(localDatabase.CountFictionBooks(), localDatabase.GetFictionBookByMd5Hash); break; case ScanLibrary.LIBGEN_SCIMAG: foundFiles = Scan(localDatabase.CountSciMagArticles(), localDatabase.GetSciMagArticleByMd5Hash); break; default: throw new ArgumentException($"Unknown library: {scanLibrary}."); } if (foundFiles.Any()) { Console.WriteLine("Adding files to the library..."); localDatabase.AddFiles(foundFiles); Console.WriteLine("Files have been successfully added to the library."); } else { Console.WriteLine("No files to add to the library."); } return(0); }