Skip to content

Чикишев М.В. ПрИ-102 - #1

Draft
ylnt241 wants to merge 11 commits into
MindHardt:masterfrom
ylnt241:master
Draft

Чикишев М.В. ПрИ-102#1
ylnt241 wants to merge 11 commits into
MindHardt:masterfrom
ylnt241:master

Conversation

@ylnt241

@ylnt241 ylnt241 commented Dec 6, 2025

Copy link
Copy Markdown

"Please commit changes immediately asap"
- Сумасандаран Самаланбаман

trolleybus

Comment thread App/Input.cs
if (valid is false)
Console.Write("\nВведите нужные URL через пробел: ");
result = Console.ReadLine()!.Split();
var valid = result.Any(IsValidUrl);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Это некорректная валидация, в твоём коде главное чтобы был хотя бы 1 валидный урл, а остальные без разницы

Comment thread App/Input.cs
/// <returns>bool</returns>
private static bool IsValidUrl(string str)
{
string strRegex = @"((http|https)://)(www.)?" +

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Вообще тут не обязательно регекс, можно через System.Uri сделать чтобы не изобретать пеловисед

Comment thread App/Input.cs
{
Console.Write("Do you want to overwrite file? [y/n] ");
var pressedKey = Console.ReadKey(true);
while (pressedKey.Key is not (ConsoleKey.Y or ConsoleKey.N))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Тут нет смысла от while, всё равно это рекурсия

Это даже вредно потому что ты не возвращаешь результат рекурсивного метода, у тебя в итоге из цикла никогда не получится выйти (потому что условие while не меняется)

Comment thread App/Program.cs

var cts = new CancellationTokenSource();
Console.CancelKeyPress += (_, _) => cts.Cancel();
Console.CancelKeyPress += (_, _) => cts.Cancel(); // а что так можно было?!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Можно, это частая практика привязывать cts к ивентам

Comment thread App/Program.cs
Console.CancelKeyPress += (_, _) => cts.Cancel(); // а что так можно было?!

var uris = Input.GetUris();
var urls = Input.GetUrls();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

В данном случае, кстати, (как и почти всегда впринципе) разница между Uri и Url не важна, это почти что одно и то же

Comment thread App/Program.cs
try
{
if (ct.IsCancellationRequested)
ct.ThrowIfCancellationRequested();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Эта if проверка уже вложена в ThrowIfCancellationRequested. Вот бы у него в имени это было написано...

Comment thread App/Program.cs
{
if (ex is OperationCanceledException)
{
destStream.Close();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Лучше вызвать DisposeAsync, он сделает и Close и Flush и всё на свете

Comment thread App/Input.cs
{
var file = new FileInfo(Console.ReadLine()!);
if (file.Exists && (!ChooseToOverwrite()))
GetOutputFile();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Та же ошибка, ты не возвращаешь результат вызова рекурсивного метода

@MindHardt MindHardt left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

тренироваться

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