Exemplo n.º 1
0
 public override void SendHashData(HashFunctionResult res)
 {
     if (!conOpt.Hide)
     {
         Console.WriteLine(res);
     }
 }
Exemplo n.º 2
0
 public override void SendHashData(HashFunctionResult data)
 {
     if (options.Verbose)
     {
         Console.WriteLine($"Trying to send new data to {tableName.ToUpper()}:\n" +
                           $"DATA: {data}");
     }
     TrySendHashData(data);
 }
Exemplo n.º 3
0
 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);
             }
     }
 }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
 public abstract void SendHashData(HashFunctionResult res);
Exemplo n.º 6
0
 public DuplicateDataException(HashFunctionResult result)
     :base ($"Found duplicate: {result}")
 {
 }
Exemplo n.º 7
0
 public override void SendHashData(HashFunctionResult res)
 {
     outputFile.WriteLine(res.ToString());
 }