diff --git a/.gitignore b/.gitignore
index bfca666a..64efe93a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,3 +41,4 @@ bld/
msbuild.log
msbuild.err
msbuild.wrn
+FractalPainter/
\ No newline at end of file
diff --git a/ConsoleClient/ConsoleClient.csproj b/ConsoleClient/ConsoleClient.csproj
new file mode 100644
index 00000000..1ab0ce0e
--- /dev/null
+++ b/ConsoleClient/ConsoleClient.csproj
@@ -0,0 +1,21 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ConsoleClient/DependencyInjectionConfig.cs b/ConsoleClient/DependencyInjectionConfig.cs
new file mode 100644
index 00000000..958cb660
--- /dev/null
+++ b/ConsoleClient/DependencyInjectionConfig.cs
@@ -0,0 +1,72 @@
+using System.Drawing;
+using System.Runtime.InteropServices;
+using Autofac;
+using DrawingTagsCloudVisualization;
+using TagsCloudVisualization;
+using TagsCloudVisualization.FilesProcessing;
+using TagsCloudVisualization.ManagingRendering;
+
+namespace ConsoleClient;
+
+public static class DependencyInjectionConfig
+{
+ public static IContainer BuildContainer(Options options)
+ {
+ var builder = new ContainerBuilder();
+ var pathToMystem = "";
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ pathToMystem = "mystem.exe";
+ else
+ pathToMystem = "mystem";
+ builder.RegisterInstance(new MyStemWrapper.MyStem
+ {
+ PathToMyStem = pathToMystem,
+ Parameters = "-ni"
+ }).As().SingleInstance();
+
+ builder.RegisterType()
+ .As()
+ .InstancePerDependency();
+
+ builder.RegisterType()
+ .As()
+ .InstancePerDependency();
+
+ builder.Register(c =>
+ {
+ var centerPoint = new Point(options.CenterX, options.CenterY);
+ return options.AlgorithmForming switch
+ {
+ "Circle" => new ArchimedeanSpiral(centerPoint, 1),
+ _ => new FermatSpiral(centerPoint, 20),
+ };
+ }).As().InstancePerDependency();
+
+ builder.RegisterType()
+ .As()
+ .InstancePerDependency();
+ builder.RegisterType()
+ .As()
+ .InstancePerDependency();
+ builder.RegisterType()
+ .As()
+ .InstancePerDependency();
+
+ switch (options.AlgorithmDrawing)
+ {
+ case "Altering":
+ builder.RegisterType().As()
+ .InstancePerDependency();
+ break;
+ default:
+ builder.RegisterType().As()
+ .InstancePerDependency();
+ break;
+ }
+ builder.RegisterType()
+ .As()
+ .InstancePerDependency();
+
+ return builder.Build();
+ }
+}
diff --git a/ConsoleClient/Examples/README.md b/ConsoleClient/Examples/README.md
new file mode 100644
index 00000000..0424d369
--- /dev/null
+++ b/ConsoleClient/Examples/README.md
@@ -0,0 +1,39 @@
+# 1 example:
+
+Agrs: dotnet run
+
+
+# 2 example:
+
+Args: dotnet run -- -o Examples/example1.png -l 500 -w 500
+
+
+# 3 example:
+
+Args: dotnet run -- -o Examples/example2.png -x 150 -y 300
+
+
+# 4 example:
+
+Args: dotnet run -- -c pink -o Examples/example3.png
+
+
+# 5 example:
+
+Args: dotnet run -- -a Fermat -o Examples/example4.png
+
+
+# 6 example:
+
+Args: dotnet run -- -p S -o Examples/example5.png
+
+
+# 7 example:
+
+Args: dotnet run -- -d Altering -o Examples/example7.png
+
+
+# 8 example:
+
+Args: dotnet run -- -p A,V -o Examples/example8.png -i Examples/example1.txt
+
\ No newline at end of file
diff --git a/ConsoleClient/Examples/example.png b/ConsoleClient/Examples/example.png
new file mode 100644
index 00000000..0a4b0046
Binary files /dev/null and b/ConsoleClient/Examples/example.png differ
diff --git a/ConsoleClient/Examples/example.txt b/ConsoleClient/Examples/example.txt
new file mode 100644
index 00000000..a13659a9
--- /dev/null
+++ b/ConsoleClient/Examples/example.txt
@@ -0,0 +1,27 @@
+да
+о
+кошка
+кошка
+большой
+большой
+большой
+дом
+дом
+красиво
+красиво
+красиво
+красиво
+и
+книга
+книга
+азбука
+азбука
+кружка
+кружка
+кружка
+алгебра
+алгебра
+алгебра
+носок
+носок
+не
\ No newline at end of file
diff --git a/ConsoleClient/Examples/example1.png b/ConsoleClient/Examples/example1.png
new file mode 100644
index 00000000..a5a693c9
Binary files /dev/null and b/ConsoleClient/Examples/example1.png differ
diff --git a/ConsoleClient/Examples/example1.txt b/ConsoleClient/Examples/example1.txt
new file mode 100644
index 00000000..6e00102e
--- /dev/null
+++ b/ConsoleClient/Examples/example1.txt
@@ -0,0 +1,49 @@
+да
+о
+кошка
+кошка
+большой
+большой
+большой
+дом
+дом
+дом
+красиво
+красиво
+красиво
+красиво
+и
+книга
+книга
+азбука
+азбука
+кружка
+кружка
+кружка
+алгебра
+алгебра
+алгебра
+носок
+носок
+носок
+не
+говно
+говно
+говно
+хуй
+хуй
+хуй
+залупа
+залупа
+мошонник
+мошонник
+мошонник
+мошонник
+говнохуй
+говнохуй
+говнохуй
+говнохуй
+влиять
+влиять
+бегать
+бегать
\ No newline at end of file
diff --git a/ConsoleClient/Examples/example2.png b/ConsoleClient/Examples/example2.png
new file mode 100644
index 00000000..e19d6f89
Binary files /dev/null and b/ConsoleClient/Examples/example2.png differ
diff --git a/ConsoleClient/Examples/example3.png b/ConsoleClient/Examples/example3.png
new file mode 100644
index 00000000..83256a1e
Binary files /dev/null and b/ConsoleClient/Examples/example3.png differ
diff --git a/ConsoleClient/Examples/example4.png b/ConsoleClient/Examples/example4.png
new file mode 100644
index 00000000..1ed487eb
Binary files /dev/null and b/ConsoleClient/Examples/example4.png differ
diff --git a/ConsoleClient/Examples/example5.png b/ConsoleClient/Examples/example5.png
new file mode 100644
index 00000000..a1e05590
Binary files /dev/null and b/ConsoleClient/Examples/example5.png differ
diff --git a/ConsoleClient/Examples/example6.png b/ConsoleClient/Examples/example6.png
new file mode 100644
index 00000000..27959002
Binary files /dev/null and b/ConsoleClient/Examples/example6.png differ
diff --git a/ConsoleClient/Examples/example7.png b/ConsoleClient/Examples/example7.png
new file mode 100644
index 00000000..f5ea62da
Binary files /dev/null and b/ConsoleClient/Examples/example7.png differ
diff --git a/ConsoleClient/Examples/example8.png b/ConsoleClient/Examples/example8.png
new file mode 100644
index 00000000..7ae28138
Binary files /dev/null and b/ConsoleClient/Examples/example8.png differ
diff --git a/ConsoleClient/ITagsCloudDrawingFacade.cs b/ConsoleClient/ITagsCloudDrawingFacade.cs
new file mode 100644
index 00000000..dc7cc69d
--- /dev/null
+++ b/ConsoleClient/ITagsCloudDrawingFacade.cs
@@ -0,0 +1,5 @@
+namespace ConsoleClient;
+public interface ITagsCloudDrawingFacade
+{
+ void DrawRectangle(Options options);
+}
\ No newline at end of file
diff --git a/ConsoleClient/Options.cs b/ConsoleClient/Options.cs
new file mode 100644
index 00000000..c7049a8f
--- /dev/null
+++ b/ConsoleClient/Options.cs
@@ -0,0 +1,35 @@
+using CommandLine;
+namespace ConsoleClient;
+
+public class Options
+{
+ [Option('i', "input", Default = "Examples/example.txt", HelpText = "Путь к входному текстовому файлу.")]
+ public required string InputFilePath { get; set; }
+
+ [Option('o', "output", Default = "Examples/example.png", HelpText = "Путь к выходному изображению.")]
+ public required string OutputFilePath { get; set; }
+
+ [Option('x', "centerX", Default = 200, HelpText = "Координата X центра.")]
+ public int CenterX { get; set; }
+
+ [Option('y', "centerY", Default = 200, HelpText = "Координата Y центра.")]
+ public int CenterY { get; set; }
+
+ [Option('l', "length", Default = 400, HelpText = "Длина изображения")]
+ public int Length { get; set; }
+
+ [Option('w', "width", Default = 400, HelpText = "Ширина изображения")]
+ public int Width{ get; set; }
+
+ [Option('c', "color", Default = "black", HelpText = "Цвет текста")]
+ public string Color{ get; set; }
+
+ [Option('a', "algorithmf", Default = "Circle", HelpText = "Алгоритм формирования(квадрат, круг)")]
+ public string AlgorithmForming{ get; set; }
+
+ [Option('p', "excludedpartofspeech", Required = false, HelpText = "Исключить часть речи S V A ADV NUM SPRO ANUM ADVPRO")]
+ public string ExcludedPartOfSpeech{ get; set; }
+
+ [Option('d', "algorithmd", Default = "Standart", HelpText = "Алгоритм рисования(Standart, Altering)")]
+ public string AlgorithmDrawing{ get; set; }
+}
\ No newline at end of file
diff --git a/ConsoleClient/Program.cs b/ConsoleClient/Program.cs
new file mode 100644
index 00000000..cb4f2c74
--- /dev/null
+++ b/ConsoleClient/Program.cs
@@ -0,0 +1,81 @@
+using Autofac;
+using CommandLine;
+
+namespace ConsoleClient;
+
+
+public class Program
+{
+ static void Main(string[] args)
+ {
+ Parser.Default.ParseArguments(args)
+ .WithParsed(RunApplication)
+ .WithNotParsed(HandleErrors);
+ }
+ readonly static private HashSet validPartsOfSpeech =
+ [
+ "S", "V", "A", "ADV", "NUM", "SPRO", "ADVPRO", "ANUM"
+ ];
+
+ private static void RunApplication(Options options)
+ {
+ if (options.AlgorithmForming != "Circle" && options.AlgorithmForming != "Fermat")
+ {
+ Console.WriteLine($"Ошибка: Неизвестный алгоритм '{options.AlgorithmForming}'. Допустимые значения: 'Circle', 'Fermat'.");
+ return;
+ }
+ if (!string.IsNullOrEmpty(options.ExcludedPartOfSpeech))
+ {
+ var excludedParts = options.ExcludedPartOfSpeech.Split(',', StringSplitOptions.RemoveEmptyEntries)
+ .Select(part => part.Trim().ToUpper());
+
+ var invalidParts = excludedParts.Where(part => !validPartsOfSpeech.Contains(part)).ToList();
+
+ if (invalidParts.Count != 0)
+ {
+ Console.WriteLine($"Ошибка: Неизвестные части речи '{string.Join(", ", invalidParts)}'");
+ return;
+ }
+ }
+ if (options.AlgorithmDrawing != "Standart" && options.AlgorithmDrawing != "Altering")
+ {
+ Console.WriteLine($"Ошибка: Неизвестный алгоритм рассказки '{options.AlgorithmDrawing}'");
+ return;
+ }
+ var container = DependencyInjectionConfig.BuildContainer(options);
+
+ using var scope = container.BeginLifetimeScope();
+ try
+ {
+ scope.Resolve().DrawRectangle(options);
+ Console.WriteLine($"Облако тегов успешно сохранено в файл: {options.OutputFilePath}");
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Произошла ошибка: {ex.Message}");
+ }
+ }
+
+ private static void HandleErrors(IEnumerable errors)
+ {
+ Console.WriteLine("Ошибка при обработке аргументов командной строки.");
+ foreach (var error in errors)
+ {
+ switch (error)
+ {
+ case UnknownOptionError unknownOptionError:
+ Console.WriteLine($"- Неизвестный параметр: {unknownOptionError.Token}");
+ break;
+ case SetValueExceptionError setValueExceptionError:
+ Console.WriteLine($"- Ошибка установки значения: {setValueExceptionError.Exception.Message}");
+ break;
+ case MissingValueOptionError missingValueOptionError:
+ Console.WriteLine($"- Отсутствует значение: {missingValueOptionError.NameInfo}");
+ break;
+ default:
+ Console.WriteLine($"- Неизвестная ошибка: {error.GetType().Name}");
+ break;
+ }
+ }
+ }
+}
diff --git a/ConsoleClient/TagsCloudDrawingFacade.cs b/ConsoleClient/TagsCloudDrawingFacade.cs
new file mode 100644
index 00000000..97c0eead
--- /dev/null
+++ b/ConsoleClient/TagsCloudDrawingFacade.cs
@@ -0,0 +1,20 @@
+using System.Drawing;
+using DrawingTagsCloudVisualization;
+using TagsCloudVisualization;
+namespace ConsoleClient;
+
+public class TagsCloudDrawingFacade(
+ IWordHandler wordHandler,
+ IRectangleGenerator rectangleGenerator, IImageSaver imageSaver) : ITagsCloudDrawingFacade
+{
+ private readonly IWordHandler _wordHandler = wordHandler;
+ private readonly IRectangleGenerator _rectangleGenerator = rectangleGenerator;
+ private readonly IImageSaver _imageSaver = imageSaver;
+
+ public void DrawRectangle(Options options)
+ {
+ var frequencyRectangles = _wordHandler.ProcessFile(options.InputFilePath, options.ExcludedPartOfSpeech);
+ var arrRect = _rectangleGenerator.ExecuteRectangles(frequencyRectangles, new Point(options.CenterX, options.CenterY));
+ _imageSaver.SaveToFile(options.OutputFilePath, options.Length, options.Width, options.Color, arrRect);
+ }
+}
diff --git a/ConsoleClient/mystem b/ConsoleClient/mystem
new file mode 100755
index 00000000..78e1ae76
Binary files /dev/null and b/ConsoleClient/mystem differ
diff --git a/ConsoleClient/mystem.exe b/ConsoleClient/mystem.exe
new file mode 100755
index 00000000..e7158ff1
Binary files /dev/null and b/ConsoleClient/mystem.exe differ
diff --git a/DrawingTagsCloudVisualization/AlternatingColorsTagsCloudDrawer.cs b/DrawingTagsCloudVisualization/AlternatingColorsTagsCloudDrawer.cs
new file mode 100644
index 00000000..87e15ac4
--- /dev/null
+++ b/DrawingTagsCloudVisualization/AlternatingColorsTagsCloudDrawer.cs
@@ -0,0 +1,48 @@
+using Microsoft.Maui.Graphics;
+using TagsCloudVisualization;
+
+namespace DrawingTagsCloudVisualization;
+
+public class AlternatingColorsTagsCloudDrawer() : ITagsCloudDrawer
+{
+ private readonly List colors = new List
+ {
+ Colors.White,
+ Colors.Red,
+ Colors.Green,
+ Colors.Yellow,
+ Colors.Blue,
+ Colors.Pink,
+ Colors.Black
+ };
+
+ public ICanvas Draw(ICanvas canvas, string color, List rectangleInformation)
+ {
+ for (int i = 0; i < rectangleInformation.Count; i++)
+ {
+ var rectInfo = rectangleInformation[i];
+ var rect = rectInfo.rectangle;
+ var text = rectInfo.word;
+
+ var currentColor = colors[i % colors.Count];
+ canvas.FontColor = currentColor;
+
+ float fontSize = rect.Height;
+ var textBounds = canvas.GetStringSize(text, Font.Default, fontSize);
+
+ while ((textBounds.Width > rect.Width || textBounds.Height > rect.Height) && fontSize > 1)
+ {
+ fontSize -= 1;
+ textBounds = canvas.GetStringSize(text, Font.Default, fontSize);
+ }
+
+ canvas.FontSize = fontSize;
+ var textX = rect.X + (rect.Width - textBounds.Width) / 2;
+ var textY = rect.Y + (rect.Height - textBounds.Height) / 2;
+
+ canvas.DrawString(text, textX, textY, HorizontalAlignment.Left);
+ }
+
+ return canvas;
+ }
+}
\ No newline at end of file
diff --git a/DrawingTagsCloudVisualization/DecreasingRectangles120.png b/DrawingTagsCloudVisualization/DecreasingRectangles120.png
new file mode 100644
index 00000000..9590045b
Binary files /dev/null and b/DrawingTagsCloudVisualization/DecreasingRectangles120.png differ
diff --git a/DrawingTagsCloudVisualization/DrawingTagsCloudVisualization.csproj b/DrawingTagsCloudVisualization/DrawingTagsCloudVisualization.csproj
new file mode 100644
index 00000000..4d1e5a44
--- /dev/null
+++ b/DrawingTagsCloudVisualization/DrawingTagsCloudVisualization.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DrawingTagsCloudVisualization/EqualsRectangles250.png b/DrawingTagsCloudVisualization/EqualsRectangles250.png
new file mode 100644
index 00000000..b8855894
Binary files /dev/null and b/DrawingTagsCloudVisualization/EqualsRectangles250.png differ
diff --git a/DrawingTagsCloudVisualization/IImageSaver.cs b/DrawingTagsCloudVisualization/IImageSaver.cs
new file mode 100644
index 00000000..8302a11e
--- /dev/null
+++ b/DrawingTagsCloudVisualization/IImageSaver.cs
@@ -0,0 +1,8 @@
+using TagsCloudVisualization;
+
+namespace DrawingTagsCloudVisualization;
+
+public interface IImageSaver
+{
+ public void SaveToFile(string filePath, int lenght, int width, string color, List rectangleInformation);
+}
\ No newline at end of file
diff --git a/DrawingTagsCloudVisualization/ITagsCloudDrawer.cs b/DrawingTagsCloudVisualization/ITagsCloudDrawer.cs
new file mode 100644
index 00000000..180953d2
--- /dev/null
+++ b/DrawingTagsCloudVisualization/ITagsCloudDrawer.cs
@@ -0,0 +1,9 @@
+using Microsoft.Maui.Graphics;
+using TagsCloudVisualization;
+
+namespace DrawingTagsCloudVisualization;
+
+public interface ITagsCloudDrawer
+{
+ public ICanvas Draw(ICanvas canvas, string color, List rectangleInformation);
+}
\ No newline at end of file
diff --git a/DrawingTagsCloudVisualization/ImageSaver.cs b/DrawingTagsCloudVisualization/ImageSaver.cs
new file mode 100644
index 00000000..678f7e06
--- /dev/null
+++ b/DrawingTagsCloudVisualization/ImageSaver.cs
@@ -0,0 +1,21 @@
+using Microsoft.Maui.Graphics;
+using Microsoft.Maui.Graphics.Skia;
+using TagsCloudVisualization;
+
+namespace DrawingTagsCloudVisualization;
+
+public class ImageSaver(ITagsCloudDrawer tagsCloudDrawer) : IImageSaver
+{
+ readonly ITagsCloudDrawer tagsCloudDrawer = tagsCloudDrawer;
+
+ public void SaveToFile(string filePath, int lenght, int width, string color, List rectangleInformation)
+ {
+ using var bitmapContext = new SkiaBitmapExportContext(lenght, width, 2.0f);
+ var canvas = bitmapContext.Canvas;
+ canvas.FontColor = Colors.Black;
+ canvas = tagsCloudDrawer.Draw(canvas, color, rectangleInformation);
+ using var image = bitmapContext.Image;
+ using var stream = File.OpenWrite(filePath);
+ image.Save(stream);
+ }
+}
\ No newline at end of file
diff --git a/DrawingTagsCloudVisualization/MixedRectangles320.png b/DrawingTagsCloudVisualization/MixedRectangles320.png
new file mode 100644
index 00000000..f1f7cfde
Binary files /dev/null and b/DrawingTagsCloudVisualization/MixedRectangles320.png differ
diff --git a/DrawingTagsCloudVisualization/README.md b/DrawingTagsCloudVisualization/README.md
new file mode 100644
index 00000000..1f0b3536
--- /dev/null
+++ b/DrawingTagsCloudVisualization/README.md
@@ -0,0 +1,10 @@
+Увеличивающися по размеру прямоугольники
+
+
+
+Одинаковые прямоугольники
+
+
+
+Прямоугольники разных размеров
+
\ No newline at end of file
diff --git a/DrawingTagsCloudVisualization/StandartTagsCloudDrawer.cs b/DrawingTagsCloudVisualization/StandartTagsCloudDrawer.cs
new file mode 100644
index 00000000..088e4ba1
--- /dev/null
+++ b/DrawingTagsCloudVisualization/StandartTagsCloudDrawer.cs
@@ -0,0 +1,46 @@
+using Microsoft.Maui.Graphics;
+using TagsCloudVisualization;
+
+namespace DrawingTagsCloudVisualization;
+
+public class StandartTagsCloudDrawer() : ITagsCloudDrawer
+{
+ private readonly Dictionary dictColors = new(){
+ { "white", Colors.White },
+ { "red", Colors.Red },
+ { "green", Colors.Green },
+ { "yellow", Colors.Yellow },
+ { "blue", Colors.Blue },
+ { "pink", Colors.Pink },
+ { "black", Colors.Black },
+ };
+
+ public ICanvas Draw(ICanvas canvas, string color, List rectangleInformation)
+ {
+ foreach (var rectInfo in rectangleInformation)
+ {
+ var rect = rectInfo.rectangle;
+ var text = rectInfo.word;
+
+ float fontSize = rect.Height;
+ if (!dictColors.TryGetValue(color, out var colorGet))
+ colorGet = Colors.Black;
+ canvas.FontColor = colorGet;
+ var textBounds = canvas.GetStringSize(text, Font.Default, fontSize);
+
+ while ((textBounds.Width > rect.Width || textBounds.Height > rect.Height) && fontSize > 1)
+ {
+ fontSize -= 1;
+ textBounds = canvas.GetStringSize(text, Font.Default, fontSize);
+ }
+
+ canvas.FontSize = fontSize;
+ var textX = rect.X + (rect.Width - textBounds.Width) / 2;
+ var textY = rect.Y + (rect.Height - textBounds.Height) / 2;
+
+ canvas.DrawString(text, textX, textY, HorizontalAlignment.Left);
+ }
+
+ return canvas;
+ }
+}
\ No newline at end of file
diff --git a/FractalPainter/Application/Actions/DragonFractalAction.cs b/FractalPainter/Application/Actions/DragonFractalAction.cs
deleted file mode 100644
index fa55e68f..00000000
--- a/FractalPainter/Application/Actions/DragonFractalAction.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System.Net;
-using System.Text.Json;
-using FractalPainting.Application.Fractals;
-using FractalPainting.Infrastructure.Common;
-using FractalPainting.Infrastructure.Injection;
-using FractalPainting.Infrastructure.UiActions;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace FractalPainting.Application.Actions;
-
-public class DragonFractalAction : IApiAction, INeed
-{
- private readonly JsonSerializerOptions jsonSerializerOptions =
- new() { Converters = { new FigureJsonConverter() } };
- private IImageSettingsProvider imageSettingsProvider = null!;
-
- public void SetDependency(IImageSettingsProvider dependency)
- {
- imageSettingsProvider = dependency;
- }
-
- public string Endpoint => "/dragonFractal";
-
- public string HttpMethod => "POST";
-
- public int Perform(Stream inputStream, Stream outputStream)
- {
- var dragonSettings = JsonSerializer.Deserialize(inputStream);
- var services = new ServiceCollection();
- services.AddSingleton(dragonSettings!);
- services.AddSingleton(imageSettingsProvider);
- services.AddSingleton();
- var sp = services.BuildServiceProvider();
-
- var painter = sp.GetRequiredService();
- var figures = painter.Paint();
- JsonSerializer.Serialize(outputStream, figures, options: jsonSerializerOptions);
-
- return (int)HttpStatusCode.OK;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Actions/GetImageSettingsAction.cs b/FractalPainter/Application/Actions/GetImageSettingsAction.cs
deleted file mode 100644
index 5448ce14..00000000
--- a/FractalPainter/Application/Actions/GetImageSettingsAction.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System.Net;
-using System.Text.Json;
-using FractalPainting.Infrastructure.Common;
-using FractalPainting.Infrastructure.Injection;
-using FractalPainting.Infrastructure.UiActions;
-
-namespace FractalPainting.Application.Actions;
-
-public class GetImageSettingsAction : IApiAction, INeed
-{
- private IImageSettingsProvider? imageSettingsProvider;
-
- public void SetDependency(IImageSettingsProvider dependency)
- {
- imageSettingsProvider = dependency;
- }
-
- public string Endpoint => "/settings";
-
- public string HttpMethod => "GET";
-
- public int Perform(Stream inputStream, Stream outputStream)
- {
- var settings = imageSettingsProvider?.ImageSettings;
- JsonSerializer.Serialize(outputStream, settings);
- return (int)HttpStatusCode.OK;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Actions/GetPaletteSettingsAction.cs b/FractalPainter/Application/Actions/GetPaletteSettingsAction.cs
deleted file mode 100644
index 06927f5e..00000000
--- a/FractalPainter/Application/Actions/GetPaletteSettingsAction.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System.Net;
-using System.Text.Json;
-using FractalPainting.Infrastructure.Common;
-using FractalPainting.Infrastructure.Injection;
-using FractalPainting.Infrastructure.UiActions;
-
-namespace FractalPainting.Application.Actions;
-
-public class GetPaletteSettingsAction : IApiAction, INeed
-{
- private Palette palette = null!;
-
- public void SetDependency(Palette dependency)
- {
- palette = dependency;
- }
-
- public string Endpoint => "/palette";
-
- public string HttpMethod => "GET";
-
- public int Perform(Stream inputStream, Stream outputStream)
- {
- JsonSerializer.Serialize(outputStream, palette);
- return (int)HttpStatusCode.OK;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Actions/KochFractalAction.cs b/FractalPainter/Application/Actions/KochFractalAction.cs
deleted file mode 100644
index cce9488b..00000000
--- a/FractalPainter/Application/Actions/KochFractalAction.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System.Net;
-using System.Text.Json;
-using FractalPainting.Application.Fractals;
-using FractalPainting.Infrastructure.Common;
-using FractalPainting.Infrastructure.Injection;
-using FractalPainting.Infrastructure.UiActions;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace FractalPainting.Application.Actions;
-
-public class KochFractalAction : IApiAction, INeed, INeed
-{
- private readonly JsonSerializerOptions jsonSerializerOptions =
- new() { Converters = { new FigureJsonConverter() } };
- private Palette palette = null!;
- private IImageSettingsProvider imageSettingsProvider = null!;
-
- public void SetDependency(Palette dependency)
- {
- palette = dependency;
- }
-
- public void SetDependency(IImageSettingsProvider dependency)
- {
- imageSettingsProvider = dependency;
- }
-
- public string Endpoint => "/kochFractal";
-
- public string HttpMethod => "POST";
-
- public int Perform(Stream inputStream, Stream outputStream)
- {
- var services = new ServiceCollection();
- services.AddSingleton(palette);
- services.AddSingleton(imageSettingsProvider);
- services.AddSingleton();
- var sp = services.BuildServiceProvider();
-
- var painter = sp.GetRequiredService();
- var figures = painter.Paint();
- JsonSerializer.Serialize(outputStream, figures, options: jsonSerializerOptions);
- return (int)HttpStatusCode.OK;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Actions/UpdateImageSettingsAction.cs b/FractalPainter/Application/Actions/UpdateImageSettingsAction.cs
deleted file mode 100644
index d74652ca..00000000
--- a/FractalPainter/Application/Actions/UpdateImageSettingsAction.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Net;
-using System.Text.Json;
-using FractalPainting.Infrastructure.Common;
-using FractalPainting.Infrastructure.Injection;
-using FractalPainting.Infrastructure.UiActions;
-
-namespace FractalPainting.Application.Actions;
-
-public class UpdateImageSettingsAction : IApiAction, INeed
-{
- private IImageSettingsProvider imageSettingsProvider = null!;
-
- public void SetDependency(IImageSettingsProvider dependency)
- {
- imageSettingsProvider = dependency;
- }
-
- public string Endpoint => "/settings";
- public string HttpMethod => "PUT";
-
- public int Perform(Stream inputStream, Stream outputStream)
- {
- var updatedSettings = JsonSerializer.Deserialize(inputStream);
- var settings = imageSettingsProvider.ImageSettings;
- settings.Height = updatedSettings?.Height ?? settings.Height;
- settings.Width = updatedSettings?.Width ?? settings.Width;
- JsonSerializer.Serialize(outputStream, settings);
-
- return (int)HttpStatusCode.OK;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Actions/UpdatePaletteSettingsAction.cs b/FractalPainter/Application/Actions/UpdatePaletteSettingsAction.cs
deleted file mode 100644
index 016d73eb..00000000
--- a/FractalPainter/Application/Actions/UpdatePaletteSettingsAction.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System.Net;
-using System.Text.Json;
-using FractalPainting.Infrastructure.Common;
-using FractalPainting.Infrastructure.Injection;
-using FractalPainting.Infrastructure.UiActions;
-
-namespace FractalPainting.Application.Actions;
-
-public class UpdatePaletteSettingsAction : IApiAction, INeed
-{
- private Palette palette = null!;
-
- public void SetDependency(Palette dependency)
- {
- palette = dependency;
- }
-
- public string Endpoint => "/palette";
-
- public string HttpMethod => "PUT";
-
- public int Perform(Stream inputStream, Stream outputStream)
- {
- var updatedPalette = JsonSerializer.Deserialize(inputStream);
- palette.BackgroundColor = updatedPalette?.BackgroundColor ?? palette.BackgroundColor;
- palette.PrimaryColor = updatedPalette?.PrimaryColor ?? palette.PrimaryColor;
- palette.SecondaryColor = updatedPalette?.SecondaryColor ?? palette.SecondaryColor;
- JsonSerializer.Serialize(outputStream, palette);
-
- return (int)HttpStatusCode.OK;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/App.cs b/FractalPainter/Application/App.cs
deleted file mode 100644
index 828dbec9..00000000
--- a/FractalPainter/Application/App.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using System.Net;
-using System.Text.Json;
-using FractalPainting.Application.Actions;
-using FractalPainting.Application.Models;
-using FractalPainting.Infrastructure.Common;
-using FractalPainting.Infrastructure.Injection;
-using FractalPainting.Infrastructure.UiActions;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace FractalPainting.Application;
-
-internal sealed class App
-{
- private const string Endpoint = "http://localhost:8080/";
- private readonly HttpListener httpListener;
- private readonly IReadOnlyDictionary routeActions;
-
- public App() : this(
- new IApiAction[]
- {
- new KochFractalAction(),
- new DragonFractalAction(),
- new UpdateImageSettingsAction(),
- new GetImageSettingsAction(),
- new UpdatePaletteSettingsAction(),
- new GetPaletteSettingsAction()
- })
- {
- }
-
- public App(IEnumerable actions)
- {
- var actionsArray = actions.ToArray();
- httpListener = new HttpListener();
- httpListener.Prefixes.Add(Endpoint);
- routeActions = actionsArray.ToDictionary(action => $"{action.HttpMethod} {action.Endpoint}", action => action);
- DependencyInjector.Inject(actionsArray, CreateSettingsManager().Load());
- DependencyInjector.Inject(actionsArray, new Palette());
- }
-
- public async Task Run()
- {
- httpListener.Start();
- Console.WriteLine($"Listening at {Endpoint}");
- while (true)
- {
- var context = await httpListener.GetContextAsync();
-
- // Обработка запроса
- try
- {
- var actionKey = $"{context.Request.HttpMethod} {context.Request.Url!.AbsolutePath}";
-
- if (actionKey == "GET /")
- {
- context.Response.ContentType = "text/html";
- await using var fileStream = File.OpenRead(Path.Join(".", "static", "index.html"));
- await fileStream.CopyToAsync(context.Response.OutputStream);
- continue;
- }
-
- if (!routeActions.TryGetValue(actionKey, out var action))
- {
- context.Response.StatusCode = (int)HttpStatusCode.NotFound;
- context.Response.Close();
- continue;
- }
-
- action.Perform(context.Request.InputStream, context.Response.OutputStream);
- }
- // Перехват ошибок
- catch (Exception e)
- {
- context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
- await JsonSerializer.SerializeAsync(context.Response.OutputStream, new ResultError(e.Message));
- }
- finally
- {
- context.Response.Close();
- }
- }
- // ReSharper disable once FunctionNeverReturns
- }
-
- private static SettingsManager CreateSettingsManager()
- {
- var services = new ServiceCollection();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
-
- var sp = services.BuildServiceProvider();
- var settingsManager = sp.GetRequiredService();
-
- return settingsManager;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/AppSettings.cs b/FractalPainter/Application/AppSettings.cs
deleted file mode 100644
index fdd68373..00000000
--- a/FractalPainter/Application/AppSettings.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using FractalPainting.Infrastructure.Common;
-
-namespace FractalPainting.Application;
-
-public class AppSettings : IImageSettingsProvider
-{
- public ImageSettings ImageSettings { get; init; } = null!;
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/FigureJsonConverter.cs b/FractalPainter/Application/FigureJsonConverter.cs
deleted file mode 100644
index b3c5bc61..00000000
--- a/FractalPainter/Application/FigureJsonConverter.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System.Text.Json;
-using System.Text.Json.Serialization;
-using FractalPainting.Application.Models;
-
-namespace FractalPainting.Application;
-
-internal sealed class FigureJsonConverter : JsonConverter
-{
- public override Figure? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
- {
- throw new NotImplementedException();
- }
-
- public override void Write(Utf8JsonWriter writer, Figure value, JsonSerializerOptions options)
- {
- switch (value)
- {
- case Line line:
- writer.WriteRawValue(JsonSerializer.Serialize(line));
- return;
-
- case Rectangle rect:
- writer.WriteRawValue(JsonSerializer.Serialize(rect));
- break;
- }
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Fractals/DragonPainter.cs b/FractalPainter/Application/Fractals/DragonPainter.cs
deleted file mode 100644
index 21799c16..00000000
--- a/FractalPainter/Application/Fractals/DragonPainter.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System.Drawing;
-using FractalPainting.Application.Models;
-using FractalPainting.Infrastructure.Common;
-using Color = FractalPainting.Application.Models.Color;
-using Point = FractalPainting.Application.Models.Point;
-using Rectangle = FractalPainting.Application.Models.Rectangle;
-
-namespace FractalPainting.Application.Fractals;
-
-public class DragonPainter(DragonSettings settings, IImageSettingsProvider imageSettingsProvider)
-{
- public IReadOnlyCollection
Paint()
- {
- var imageSettings = imageSettingsProvider.ImageSettings;
- var size = Math.Min(imageSettings.Width, imageSettings.Height) / 2.1f;
-
- var backgroundColor = new Color(0, 0, 0);
- var foregroundColor = new Color(255, 255, 0);
-
- var figures = new List
();
- figures.Add(new Rectangle(imageSettings.Width, imageSettings.Height, new Point(0, 0), backgroundColor));
- var r = new Random();
- var cosa = (float)Math.Cos(settings.Angle1);
- var sina = (float)Math.Sin(settings.Angle1);
- var cosb = (float)Math.Cos(settings.Angle2);
- var sinb = (float)Math.Sin(settings.Angle2);
- var shiftX = settings.ShiftX * size * 0.8f;
- var shiftY = settings.ShiftY * size * 0.8f;
- var scale = settings.Scale;
- var p = new PointF(0, 0);
- foreach (var _ in Enumerable.Range(0, settings.IterationsCount))
- {
- figures.Add(new Rectangle(1, 1,
- new Point((int)(imageSettings.Width / 3f + p.X), (int)(imageSettings.Height / 2f + p.Y)),
- foregroundColor));
- if (r.Next(0, 2) == 0)
- p = new PointF(scale * (p.X * cosa - p.Y * sina), scale * (p.X * sina + p.Y * cosa));
- else
- p = new PointF(scale * (p.X * cosb - p.Y * sinb) + shiftX,
- scale * (p.X * sinb + p.Y * cosb) + shiftY);
- }
-
- return figures;
- }
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Fractals/DragonSettings.cs b/FractalPainter/Application/Fractals/DragonSettings.cs
deleted file mode 100644
index 1553078b..00000000
--- a/FractalPainter/Application/Fractals/DragonSettings.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace FractalPainting.Application.Fractals;
-
-public class DragonSettings
-{
- public double Angle1 { get; set; } = Math.PI / 4;
- public double Angle2 { get; set; } = 3 * Math.PI / 4;
- public float ShiftX { get; set; } = 1;
- public float ShiftY { get; set; } = 0;
- public float Scale { get; set; } = (float)(1 / Math.Sqrt(2));
- public int IterationsCount { get; set; } = 20000;
-}
\ No newline at end of file
diff --git a/FractalPainter/Application/Fractals/KochPainter.cs b/FractalPainter/Application/Fractals/KochPainter.cs
deleted file mode 100644
index 2ea61a2b..00000000
--- a/FractalPainter/Application/Fractals/KochPainter.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using FractalPainting.Application.Models;
-using FractalPainting.Infrastructure.Common;
-using Color = FractalPainting.Application.Models.Color;
-using Point = FractalPainting.Application.Models.Point;
-using Rectangle = FractalPainting.Application.Models.Rectangle;
-
-namespace FractalPainting.Application.Fractals;
-
-public class KochPainter(Palette palette, IImageSettingsProvider imageSettingsProvider)
-{
- public IReadOnlyCollection
Paint()
- {
- var imageSettings = imageSettingsProvider.ImageSettings;
- var figures = new List