Conversation
| using System.Text; | ||
| using System.Security.Cryptography; | ||
|
|
||
| namespace Md5; |
There was a problem hiding this comment.
Лучше неймспейс в самом начале файла (после шапки с лицензией)
|
|
||
| namespace Md5; | ||
|
|
||
| public class MultiThreadMD5 |
There was a problem hiding this comment.
- Самому классу тоже нужен комментарий
- Все методы static, значит и сам класс по логике вещей должен быть static
| { | ||
| throw new FileNotFoundException(); | ||
| } | ||
| var fstream = File.OpenRead(path); |
There was a problem hiding this comment.
| var fstream = File.OpenRead(path); | |
| using var fstream = File.OpenRead(path); |
| } | ||
| var fstream = File.OpenRead(path); | ||
| using var md5 = MD5.Create(); | ||
| byte[] buffer = new byte[fstream.Length]; |
There was a problem hiding this comment.
| byte[] buffer = new byte[fstream.Length]; | |
| var buffer = new byte[fstream.Length]; |
| var fstream = File.OpenRead(path); | ||
| using var md5 = MD5.Create(); | ||
| byte[] buffer = new byte[fstream.Length]; | ||
| await fstream.ReadAsync(buffer, 0, buffer.Length); |
There was a problem hiding this comment.
Зачитывать весь файл в массив может быть хорошей идеей, если мы знаем, что у нас ОЧЕНЬ маленькие файлы и ОЧЕНЬ много оперативки. Поэтому у ComputeHash есть перегрузка, принимающая Stream (она сама вычитывает файл порциями и считает хеш поблочно).
| { | ||
| Console.WriteLine("Далее будет выполнено сравнение Md5 hash с использованием многопоточности и без неё"); | ||
| Console.WriteLine("Введите путь до дирректории"); | ||
| var pathToDirrectory = Console.ReadLine(); |
There was a problem hiding this comment.
| var pathToDirrectory = Console.ReadLine(); | |
| var pathToDirectory = Console.ReadLine(); |
| var pathToDirrectory = Console.ReadLine(); | ||
| if (pathToDirrectory == null ) | ||
| { | ||
| throw new NullReferenceException(); |
There was a problem hiding this comment.
Никогда не кидайте NullReferenceException, оно всегда должно указывать на ошибку в коде (и кидаться .NET-машиной).
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| Stopwatch stopwatchForDirrectory = new Stopwatch(); |
There was a problem hiding this comment.
| Stopwatch stopwatchForDirrectory = new Stopwatch(); | |
| Stopwatch stopwatchForDirectory = new(); |
| } | ||
| var fstream = File.OpenRead(path); | ||
| using var md5 = MD5.Create(); | ||
| return md5.ComputeHash(fstream); |
There was a problem hiding this comment.
Кажется, это можно было бы переиспользовать и в многопоточном варианте.
| public void IsThrowExceptionWhenIncorrectPathFileInMultiThread() | ||
| { | ||
| Assert.ThrowsAsync<FileNotFoundException>(() => MultiThreadMD5.CalculateFile(pathDirectory + "/ttrt.txt")); | ||
| } |
There was a problem hiding this comment.
Можно было бы использовать TestCaseSource, чтобы избежать копипаста.
No description provided.