diff --git a/src/Chksum/chksum.cs b/src/Chksum/chksum.cs index 38fe66e..8f0f1a6 100644 --- a/src/Chksum/chksum.cs +++ b/src/Chksum/chksum.cs @@ -208,9 +208,10 @@ public class ChksumUtils { } } - private List getFilehashesOfOriginDatabase() { - List filehashesOfOriginDatabase = new List(); - using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadOnly")) { + private List getFilehashesFromDatabase(string connectionString) { + List filehashesFromDatabase = new List(); + + using (var connection = new SqliteConnection(connectionString)) { string filehash = string.Empty; connection.Open(); @@ -224,40 +225,16 @@ public class ChksumUtils { using (var reader = selectCommand.ExecuteReader()) { while (reader.Read()) { filehash = reader.GetString(0); - filehashesOfOriginDatabase.Add(filehash); + filehashesFromDatabase.Add(filehash); } } } - return filehashesOfOriginDatabase; - } - - private List getFilehashesOfRemoteDatabase(string filePathToOtherDatabase) { - List filehashesOfRemoteDatabase = new List(); - using (var connection = new SqliteConnection("Data Source=" + filePathToOtherDatabase + ";Mode=ReadOnly")) { - string filehash = string.Empty; - - connection.Open(); - - var selectCommand = connection.CreateCommand(); - selectCommand.CommandText = - @" - Select filehash FROM file - "; - - using (var reader = selectCommand.ExecuteReader()) { - while (reader.Read()) { - filehash = reader.GetString(0); - filehashesOfRemoteDatabase.Add(filehash); - } - } - } - - return filehashesOfRemoteDatabase; + return filehashesFromDatabase; } public void compareDatabases(string filePathToOtherDatabase) { - List filesThatDoNotExistsInTheRemote = getFilehashesOfOriginDatabase().Except(getFilehashesOfRemoteDatabase(filePathToOtherDatabase)).ToList(); + List filesThatDoNotExistsInTheRemote = getFilehashesFromDatabase("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadOnly").Except(getFilehashesFromDatabase("Data Source=" + filePathToOtherDatabase + ";Mode=ReadOnly")).ToList(); //List filesThatDoNotExistsInTheOrigin = filehashesOfRemoteDatabase.Except(filehashesOfOriginDatabase).ToList(); foreach (string file in filesThatDoNotExistsInTheRemote) {