Skip to content

HW4 SimpleFTP#5

Open
khusainovilas wants to merge 9 commits intomainfrom
task4-simple-ftp
Open

HW4 SimpleFTP#5
khusainovilas wants to merge 9 commits intomainfrom
task4-simple-ftp

Conversation

@khusainovilas
Copy link
Owner

No description provided.

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

О, я Вам, оказывается, ревью не отправил, а Вы и не спросили про замечания :)

},
};

this.server.Start();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сурово. Можно было создать объект-сервер в этом же процессе, они бы нормально общались с клиентом по сети. Хотя так более показательно, так что можно не править

public void Cleanup()
{
var dir = TestContext.CurrentContext.TestDirectory;
foreach (var file in new[] { "file.txt", "pin.jpg", "123.docx", "111.txt" })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foreach (var file in new[] { "file.txt", "pin.jpg", "123.docx", "111.txt" })
foreach (var file in ["file.txt", "pin.jpg", "123.docx", "111.txt"])

RunClient("2 ./Test/file.txt");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "file.txt");
Assert.That(File.Exists(path), Is.True, "file.txt did not download!");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стоило проверить и его содержимое, вдруг там пустой файл просто создаётся

Assert.Multiple(() =>
{
Assert.That(File.Exists(downloaded), Is.True, "pin.jpg did not download!");
Assert.That(GetSha256(downloaded), Is.EqualTo(originalHash));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +8 to +9
const string host = "127.0.0.1";
const int port = 12345;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы это принимал аргументом командной строки

while (true)
{
Console.Write("\n> ");
var input = Console.ReadLine()?.Trim();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И я бы ожидал от таких инструментов меньше интерактива — всё передаём из командной строки, получаем вывод в stdout, с пользователем не общаемся. Так в скриптах удобнее (например, wget так работает, поэтому вполне может вызываться, например, посреди сборки в CI).

}

throw new IOException("Unexpected end of stream while reading file size");
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это какой-то Python-стайл — всё в одном файле, ничего не переиспользуемо, UI и бизнес-логика в одну кучу. На C# так не принято писать, хочется тут отдельный класс, который можно было бы использовать в CLI и тестировать, и если мы захотим вдруг написать UI или веб-обёртку над всем этим, мы бы могли легко и без модификаций кода это сделать.

{
var client = await listener.AcceptTcpClientAsync();
_ = Task.Run(() => HandleClientAsync(client));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут надо предусмотреть механизм корректного выключения сервера. Ну и в целом, все асинхронные операции по-хорошему должны быть прерываемыми, и если они прерываемые, дать пользователю их прервать из CLI.

{
var rel = Path.GetRelativePath(root, fullPath).Replace('\\', '/');
return rel == "." ? "." : rel.StartsWith("./") ? rel : "./" + rel;
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже, Python-стайл какой-то. От Вас в курсе по C# ожидаются переиспользуемые компоненты, оформленные по возможности в соответствии с гайдлайнами по написанию библиотек, принятых в C#. Тут хочется архитектурный рефакторинг.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants