public override void SendHashData(HashFunctionResult res) { if (!conOpt.Hide) { Console.WriteLine(res); } }
public override void SendHashData(HashFunctionResult data) { if (options.Verbose) { Console.WriteLine($"Trying to send new data to {tableName.ToUpper()}:\n" + $"DATA: {data}"); } TrySendHashData(data); }
private void FindDuplicateAndThrowExc(HashFunctionResult result) { using (SqlCommand command = new SqlCommand( "SELECT * FROM HASHRESULTS " + "WHERE FileName = @FileName AND HashSum = @HashSum" + " AND Errors = @Errors", connection)) { command.Parameters.AddWithValue("@FileName", result.filePath); command.Parameters.AddWithValue("@HashSum", result.hashSum); command.Parameters.AddWithValue("@Errors", result.error.ErrorMessage); using (SqlDataReader reader = command.ExecuteReader()) while (reader.Read()) { reader.Close(); throw new DuplicateDataException(result); } } }
private void TrySendHashData(HashFunctionResult result) { try { FindDuplicateAndThrowExc(result); using (SqlCommand command = new SqlCommand( $"INSERT INTO {tableName} (FileName, HashSum, Errors) " + "VALUES(@FileName, @HashSum, @Errors)", connection)) { command.Parameters.Add(new SqlParameter("@FileName", result.filePath)); command.Parameters.Add(new SqlParameter("@HashSum", result.hashSum)); command.Parameters.Add(new SqlParameter("@Errors", SqlDbType.NVarChar) { Value = result.error.ErrorMessage }); command.ExecuteNonQuery(); } } catch (DuplicateDataException e) { if (options.Verbose) { Console.WriteLine(e.Message); } } catch (Exception e) { if (options.Verbose) { Console.WriteLine("Failed to send new data:\n" + $"TABLE NAME: {tableName}\n" + $"DATA: {result}"); } throw e; } }
public abstract void SendHashData(HashFunctionResult res);
public DuplicateDataException(HashFunctionResult result) :base ($"Found duplicate: {result}") { }
public override void SendHashData(HashFunctionResult res) { outputFile.WriteLine(res.ToString()); }