Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Заколюкин Степан #208

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
d16e31e
Добавил все необходимые проекты с прошлой задачи
StepanZakolukin Jan 15, 2025
22cbd2d
Перенес реализацию Result<T> из задания, выполненого на паре
StepanZakolukin Jan 15, 2025
7c7e953
Избавился от исключений в реализации библиотеки TagCloud с помощью па…
StepanZakolukin Jan 16, 2025
ffb7108
Переписал блок настроек TagCloud и применил соответствующие изменения…
StepanZakolukin Jan 24, 2025
f88693e
Исправил ошибку. Добавил проекты не ссылками на существующие, а копиями
StepanZakolukin Jan 25, 2025
682ae1e
Вытащил тесты на настройку шрифта в отдельный файл и добавил новые тесты
StepanZakolukin Jan 25, 2025
608710a
Выделил тесты на настройку коэффициента сжатия облака в отдельный кла…
StepanZakolukin Jan 25, 2025
e7d8f4f
Добавил дополнительные тесты на настройку шрифта
StepanZakolukin Jan 25, 2025
8b71def
Выделил тесты на натройку размера изоображения в отдельный файл
StepanZakolukin Jan 25, 2025
0ecc242
Вынес логику генерации тестовых данных в отдельный класс
StepanZakolukin Jan 25, 2025
f84c3cf
Поменял абсолютные пути в файле проекта на относительные
StepanZakolukin Jan 29, 2025
d3ffbc9
Удалил лишние строки из файла тестового проекта
StepanZakolukin Jan 29, 2025
325268c
Поменял абсолютный путь на относительный и удлил лишние строки в файл…
StepanZakolukin Jan 30, 2025
62e6187
Влил состояние из другой ветки
StepanZakolukin Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ErrorHandling/ActionStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace ErrorHandling;

public struct ActionStatus(string error)
Copy link

Choose a reason for hiding this comment

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

А чем это отличается от условного Result без параметра ? Зачем оно нужно

Copy link
Author

Choose a reason for hiding this comment

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

Ничем, просто класс Result без параметра не удается создать, т.к существует класс расширение с таким же названием

Copy link

Choose a reason for hiding this comment

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

nit: лучше тогда класс расширение переименовать, ибо в нём даже название нигде не будет фигурировать

{
public string Error { get; } = error;
public bool IsSuccess => Error == null;

public static ActionStatus Ok()
{
return new ActionStatus(null);
}

public static ActionStatus Fail(string e)
{
return new ActionStatus(e);
}
}
31 changes: 19 additions & 12 deletions ErrorHandling/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ private None()
}
}

public struct Result<T>
public struct Result<T>(string error, T value = default(T))
{
public Result(string error, T value = default(T))
{
Error = error;
Value = value;
}

public string Error { get; }
internal T Value { get; }
public string Error { get; } = error;
internal T Value { get; } = value;

public T GetValueOrThrow()
{
Expand Down Expand Up @@ -62,20 +56,33 @@ public static Result<TOutput> Then<TInput, TOutput>(
this Result<TInput> input,
Func<TInput, TOutput> continuation)
{
throw new NotImplementedException();
return input.Then(x => Of(() => continuation(x)));
}

public static Result<TOutput> Then<TInput, TOutput>(
this Result<TInput> input,
Func<TInput, Result<TOutput>> continuation)
{
throw new NotImplementedException();
return input.IsSuccess ? continuation(input.Value) : Fail<TOutput>(input.Error);
}

public static Result<TInput> OnFail<TInput>(
this Result<TInput> input,
Action<string> handleError)
{
throw new NotImplementedException();
if (input.IsSuccess) return new Result<TInput>(input.Error, input.Value);
handleError(input.Error);
return Fail<TInput>(input.Error);

}

public static Result<TInput> ReplaceError<TInput>(this Result<TInput> input, Func<string, string> replacement)
{
return input.IsSuccess ? input : Fail<TInput>(replacement(input.Error));
}

public static Result<TInput> RefineError<TInput>(this Result<TInput> input, string addition)
{
return input.ReplaceError(error => $"{addition}. {error}");
}
}
43 changes: 43 additions & 0 deletions TagCloud.GUI/Controls/DropdownList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace TagCloudGUI.Controls;

public class DropdownList : TagCloudTableLayoutPanel
{
private readonly TagCloudLabel _heading;
public event Action<object?, EventArgs>? TextHasBeenChanged;
public string SelectedText { get; private set; }
protected readonly TagCloudConfigurationForm ParentForm;
public readonly ErrorInformation ErrorMessage = new();

public DropdownList(string heading, IEnumerable<string> list, TagCloudConfigurationForm parentForm)
{
ParentForm = parentForm;
_heading = new TagCloudLabel(heading);
Margin = new Padding(0, 0, 0, 8);

DropDownList.Items.AddRange(list.ToArray());

ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
RowStyles.Add(new RowStyle(SizeType.Absolute, 35));
RowStyles.Add(new RowStyle(SizeType.Absolute, 35));
RowStyles.Add(new RowStyle(SizeType.Absolute, 20));

Controls.Add(_heading, 0, 0);
Controls.Add(DropDownList, 0, 1);
Controls.Add(ErrorMessage, 0, 2);

DropDownList.TextChanged += SelectionHasBeenChanged;
}

private void SelectionHasBeenChanged(object? sender, EventArgs args)
{
SelectedText = DropDownList.Text;
TextHasBeenChanged?.Invoke(sender, args);
}

protected ComboBox DropDownList { get; } = new()
{
Dock = DockStyle.Fill,
Margin = new Padding(0, 0, 0, 5),
Padding = new Padding(0),
};
}
14 changes: 14 additions & 0 deletions TagCloud.GUI/Controls/ErrorInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace TagCloudGUI.Controls;

public sealed class ErrorInformation : Label
{
public ErrorInformation()
{
ForeColor = Color.Red;
Dock = DockStyle.Fill;
Margin = new Padding(0);
Padding = new Padding(0);
BorderStyle = BorderStyle.Fixed3D;
Font = new Font(Font.FontFamily, 12, FontStyle.Bold, GraphicsUnit.Pixel);
}
}
14 changes: 14 additions & 0 deletions TagCloud.GUI/Controls/TagCloudButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace TagCloudGUI.Controls;

public sealed class TagCloudButton : Button
{
public TagCloudButton()
{
FlatStyle = FlatStyle.Flat;
Padding = new Padding(0);
Margin = new Padding(0);
Height = 40;
TextAlign = ContentAlignment.TopCenter;
Font = new Font(Font.FontFamily, 20, FontStyle.Bold, GraphicsUnit.Pixel);
}
}
11 changes: 11 additions & 0 deletions TagCloud.GUI/Controls/TagCloudLabel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TagCloudGUI.Controls;

public sealed class TagCloudLabel : Label
{
public TagCloudLabel(string text)
{
Text = text;
Dock = DockStyle.Fill;
Margin = new Padding(0, 0, 0, 5);
}
}
11 changes: 11 additions & 0 deletions TagCloud.GUI/Controls/TagCloudTableLayoutPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TagCloudGUI.Controls;

public class TagCloudTableLayoutPanel : TableLayoutPanel
{
public TagCloudTableLayoutPanel()
{
Dock = DockStyle.Fill;
Margin = new Padding(0);
Padding = new Padding(0);
}
}
12 changes: 12 additions & 0 deletions TagCloud.GUI/Controls/TagCloudTextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace TagCloudGUI.Controls;

public sealed class TagCloudTextBox : TextBox
{
public TagCloudTextBox()
{
Dock = DockStyle.Fill;
TextAlign = HorizontalAlignment.Center;
Margin = new Padding(0);
Padding = new Padding(0);
}
}
39 changes: 39 additions & 0 deletions TagCloud.GUI/Controls/TagCloudTreeView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace TagCloudGUI.Controls;

public class TagCloudTreeView : TagCloudTableLayoutPanel
{
private readonly TagCloudLabel _heading;

protected readonly TreeView TreeView = new()
{
Dock = DockStyle.Fill,
Margin = new Padding(0),
Padding = new Padding(0),
BorderStyle = BorderStyle.None,
CheckBoxes = true,
ShowLines = false
};

protected readonly TagCloudConfigurationForm ParentForm;

public TagCloudTreeView(string heading, TagCloudConfigurationForm parentForm)
{
Dock = DockStyle.Fill;
ParentForm = parentForm;
Margin = new Padding(0, 0, 0, 8);
this._heading = new TagCloudLabel(heading);
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
RowStyles.Add(new RowStyle(SizeType.Absolute, 30));
RowStyles.Add(new RowStyle(SizeType.Absolute, 270));

Controls.Add(this._heading, 0, 0);
Controls.Add(TreeView, 0, 1);
}

public IEnumerable<string> GetSelectedValues()
{
for (var i = 0; i < TreeView.Nodes.Count; i++)
if (TreeView.Nodes[i].Checked)
yield return TreeView.Nodes[i].Text;
}
}
24 changes: 24 additions & 0 deletions TagCloud.GUI/Layout/FirstColumn/ColorSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using TagCloudGUI.Controls;

namespace TagCloudGUI.Layout.FirstColumn;

public class ColorSettings : DropdownList
{
public ColorSettings(TagCloudConfigurationForm parentForm) : base(
"Алгоритм расцветки слов:",
parentForm.VisualizationProvider.Settings.ColoringAlgorithm.NamesOfColoringAlgorithms,
parentForm)
{
DropDownList.SelectedItem = parentForm.VisualizationProvider.Settings.ColoringAlgorithm.SelectedAlgorithm;
TextHasBeenChanged += ColoringAlgorithmsIsSelected;
parentForm.VisualizationProvider.Settings.ColoringAlgorithm.ValueChanged += (_, message) =>
{
ErrorMessage.Text = message;
};
}

private void ColoringAlgorithmsIsSelected(object? sender, EventArgs e)
{
ParentForm.VisualizationProvider.Settings.ColoringAlgorithm.SelectedAlgorithm = SelectedText;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using TagCloud.ImageGeneration;
using TagCloudGUI.Controls;

namespace TagCloudGUI.Layout.FirstColumn;

public class ConfiguringCloudCompressionRatio : TagCloudTableLayoutPanel
{
private readonly TagCloudTextBox _coefficient = new();

private readonly TagCloudLabel _heading = new("Коэф. сжатия облака:")
{
TextAlign = ContentAlignment.MiddleLeft
};

private readonly ErrorInformation _errorMessage = new();

private readonly IVisualizationProvider _visualizationProvider;

public ConfiguringCloudCompressionRatio(IVisualizationProvider visualizationProvider)
{
_visualizationProvider = visualizationProvider;
_coefficient.Text = $"{Math.Round(visualizationProvider.Settings.CompressionRatio.GetValueOrThrow(), 2)}";
_coefficient.TextChanged += CoefficientHasChanged;

RowStyles.Add(new RowStyle(SizeType.Absolute, 35));
RowStyles.Add(new RowStyle(SizeType.Absolute, 20));

Controls.Add(CreateControlGrid(), 0, 0);
Controls.Add(_errorMessage, 0, 1);

visualizationProvider.Settings.CompressionRatio.ValueChanged += (_, message) =>
{
_errorMessage.Text = message;
};
}

private TagCloudTableLayoutPanel CreateControlGrid()
{
var controlGrid = new TagCloudTableLayoutPanel
{
Margin = new Padding(0, 0, 0, 5)
};

controlGrid.RowStyles.Add(new RowStyle(SizeType.AutoSize));
controlGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 260));
controlGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 87));
controlGrid.Controls.Add(_heading, 0, 0);
controlGrid.Controls.Add(_coefficient, 1, 0);

return controlGrid;
}

private void CoefficientHasChanged(object? sender, EventArgs e)
{
_visualizationProvider.Settings.CompressionRatio.Value = _coefficient.Text;
}
}
25 changes: 25 additions & 0 deletions TagCloud.GUI/Layout/FirstColumn/FirstColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using TagCloud.ImageGeneration;
using TagCloudGUI.Controls;

namespace TagCloudGUI.Layout.FirstColumn;

public class FirstColumn : TagCloudTableLayoutPanel
{
public FirstColumn(IVisualizationProvider visualizationProvider, TagCloudConfigurationForm parentForm)
{
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
RowStyles.Add(new RowStyle(SizeType.Absolute, 133));
for (var i = 0; i < 4; i++)
RowStyles.Add(new RowStyle(SizeType.Absolute, 98));
RowStyles.Add(new RowStyle(SizeType.Absolute, 55));
RowStyles.Add(new RowStyle(SizeType.AutoSize));

Controls.Add(new ImageSizeSettings(visualizationProvider), 0, 0);
Controls.Add(new FontSettings(visualizationProvider, parentForm), 0, 1);
Controls.Add(new ColorSettings(parentForm), 0, 2);
Controls.Add(new SettingUpLayoutAlgorithm(parentForm), 0, 3);
Controls.Add(new SettingTextType(parentForm), 0, 4);
Controls.Add(new ConfiguringCloudCompressionRatio(visualizationProvider), 0, 5);
Controls.Add(new Panel { Dock = DockStyle.Fill }, 0, 6);
}
}
31 changes: 31 additions & 0 deletions TagCloud.GUI/Layout/FirstColumn/FontSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Drawing.Text;
using TagCloud.ImageGeneration;
using TagCloudGUI.Controls;

namespace TagCloudGUI.Layout.FirstColumn;

public sealed class FontSettings : DropdownList
{
private static readonly IEnumerable<string> FontFamilies = new InstalledFontCollection().Families
.Select(family => family.Name);

private readonly IVisualizationProvider _visualizationProvider;

public FontSettings(IVisualizationProvider visualizationProvider, TagCloudConfigurationForm parentForm)
: base("Шрифт:", FontFamilies, parentForm)
{
Dock = DockStyle.Fill;
DropDownList.SelectedItem = visualizationProvider.Settings.FontFamily.Name;
_visualizationProvider = visualizationProvider;
TextHasBeenChanged += FontIsSelected;
visualizationProvider.Settings.FontFamily.ValueChanged += (_, message) =>
{
ErrorMessage.Text = message;
};
}

private void FontIsSelected(object? sender, EventArgs args)
{
_visualizationProvider.Settings.FontFamily.Name = SelectedText;
}
}
Loading