Skip to content

Головнев Максим#223

Open
maximka200 wants to merge 7 commits intokontur-courses:masterfrom
maximka200:master
Open

Головнев Максим#223
maximka200 wants to merge 7 commits intokontur-courses:masterfrom
maximka200:master

Conversation

@maximka200
Copy link
Copy Markdown

No description provided.

@maximka200
Copy link
Copy Markdown
Author

@masssha1308

using TagsCloudContainer.Result;

namespace TagsCloudContainer.Core.Ranges;
public abstract class MaybeRange
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

зачем нужен maybeRange? По сути он дублирует логику result (способ выразить либо значение, либо отсутствие)

public static readonly MaybeRange Empty = new EmptyRange();
public static MaybeRange Range(int min, int max) => new ValueRange(min, max);

public abstract Result<(int Min, int Max)> GetOrYieldBreak();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В реализациях нет yield break


var freqRangeResult = FrequencyRange.TryGet(tagList).GetOrYieldBreak();
if (!freqRangeResult.IsSuccess)
return Result<IEnumerable<PositionedTag>>.Failure(freqRangeResult.Error ?? Result<IEnumerable<PositionedTag>>.UnknownError);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ошибку лучше устанавливать в FrequencyRange (даже если она неизвестна)

return Result<IEnumerable<PositionedTag>>.Failure("Tag list is empty.");

var freqRangeResult = FrequencyRange.TryGet(tagList).GetOrYieldBreak();
if (!freqRangeResult.IsSuccess)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хорошо бы избавиться от ручной проверки isSuccess и пробрасывания ошибок. Как вариант посмотреть в сторону Bind в Result


var ctxResult = BuildRenderContext(request, positionedTags);
if (!ctxResult.IsSuccess)
return Result<Image<Rgba32>>.Failure(ctxResult.Error);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ошибка может быть null?

private Result<ISet<string>> LoadStopWords()
{
if (string.IsNullOrEmpty(stopWordsPath) || !File.Exists(stopWordsPath))
Result<ISet<string>>.Failure($"Reading error: {stopWordsPath}");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return?


return Result<ISet<string>>.Success(
File
.ReadAllLines(stopWordsPath)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Кажется тут тоже может возникнуть исключение

private Result<ISet<string>> LoadStopWords()
{
if (string.IsNullOrEmpty(stopWordsPath) || !File.Exists(stopWordsPath))
Result<ISet<string>>.Failure($"Reading error: {stopWordsPath}");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

неинформативная ошибка

foreach (var s in fontChoiceStrategies)
dict.Add(s.Key, s);

dict.Add("", fontChoiceStrategies.First());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

может ли быть пустым?

public static IReadOnlyCollection<string> Choices =>
Strategies.Select(s => s.Key).ToArray();

public static Result<FontFamily> Resolve(string? choice)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

в каких случаях choice может быть null?

var font = SystemFonts.Collection.Families
.FirstOrDefault(f => string.Equals(f.Name, name, StringComparison.OrdinalIgnoreCase));

return Result<FontFamily>.Success(font);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а если шрифт не найден?

this.request = request ?? throw new ArgumentNullException(nameof(request));

public static Result<GenerationContext> Start(TagCloudGenerationRequest request)
=> Result<GenerationContext>.Success(new(request));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Всегда Success?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

чтобы была красивая цепочка Bind

if (!savingResult.IsSuccess)
return Result<GenerationContext>.Failure(savingResult.Error!);

image.Dispose();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

лучше использовать using, т.к. в случае если до этого будет исключение ресурс не освободится

{
var ffResult = FontFamilyResolver.Resolve(request.Font);
if (!ffResult.IsSuccess)
return Result<IReadOnlyCollection<PositionedTag>>.Failure(ffResult.Error ?? Result<IReadOnlyCollection<PositionedTag>>.UnknownError);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

если !IsSuccess, то ошибка не должна быть пустой


IWordsSource source = new DocxWordsSource();

var words = source.GetWords(path).Value.ToArray();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хорошо бы добавить проверку IsSuccess, т.к. в противном случае выпадет исключение и скроет реальную ошибку

"txt"
);

generator.Generate(request);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

хорошо бы проверить IsSuccess


var result = generator.Generate(request);

result.IsSuccess.Should().Be(false);
Copy link
Copy Markdown

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