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

Сазонов Александр #27

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b95df23
classwork
AlexxSaz Dec 17, 2024
7d65d55
inital commit
AlexxSaz Dec 17, 2024
38ec0e7
devflow
AlexxSaz Dec 18, 2024
16772d2
newDevflow
AlexxSaz Dec 18, 2024
ec2e3a1
removed hard logic
AlexxSaz Dec 20, 2024
4e8a3a1
Base implementation created
AlexxSaz Dec 20, 2024
3feda7e
Reworked to DI container
AlexxSaz Dec 20, 2024
c721144
Added tests
AlexxSaz Dec 21, 2024
d8d4191
TagCloud converted to class lib
AlexxSaz Dec 22, 2024
8c34546
Settings refactored
AlexxSaz Dec 22, 2024
1b09b9d
Added client v0.1
AlexxSaz Dec 22, 2024
61fadfa
Added palette provider
AlexxSaz Dec 23, 2024
94c8301
DI logic fixed
AlexxSaz Dec 23, 2024
a2c82e1
Samples added
AlexxSaz Dec 23, 2024
dddadd4
Tests fixed
AlexxSaz Dec 23, 2024
806a234
Added exit option with implementation
AlexxSaz Dec 23, 2024
0c8e753
Added setters for font properties
AlexxSaz Dec 23, 2024
85d1cf9
Implemented new properties
AlexxSaz Dec 23, 2024
dca481d
Unused usings removed
AlexxSaz Dec 23, 2024
7a3d486
Added new point generator algorithm
AlexxSaz Dec 24, 2024
af29b62
Console client updated with new point generator algo
AlexxSaz Dec 24, 2024
66180a4
Tests updated for new algo
AlexxSaz Dec 24, 2024
90edc1e
Created web client
AlexxSaz Dec 24, 2024
7dfdb5d
Added actions to web client
AlexxSaz Dec 25, 2024
b68d10b
Created result Error record
AlexxSaz Dec 25, 2024
c8dd95b
Index updated to current implementation
AlexxSaz Dec 25, 2024
48ba56a
Added update logic action
AlexxSaz Dec 25, 2024
1894531
Added custom json converters
AlexxSaz Dec 25, 2024
9e41f10
Tagcloud implementation reworked
AlexxSaz Dec 26, 2024
0c8908d
Created own project for reader
AlexxSaz Dec 26, 2024
ca2c233
Created custom model classes
AlexxSaz Dec 26, 2024
c451e5e
index html updated
AlexxSaz Dec 26, 2024
d59761b
Web client implementation fix
AlexxSaz Dec 26, 2024
a483597
Tests fixed
AlexxSaz Dec 26, 2024
951cf68
Console client reworked to new tagcloud implementation
AlexxSaz Dec 26, 2024
111874e
Added few type of font to web client
AlexxSaz Dec 26, 2024
f1ff2ab
Reader fixed
AlexxSaz Dec 26, 2024
3c9b5b2
Added JsonSerializerOptions fields to actions
AlexxSaz Dec 26, 2024
ffb4d89
Reader splitters fixed
AlexxSaz Dec 27, 2024
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
22 changes: 5 additions & 17 deletions FractalPainter/Application/Actions/DragonFractalAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
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<IImageSettingsProvider>
public class DragonFractalAction(IDragonPainterFactory dragonPainterFactory) : IApiAction
{
private readonly JsonSerializerOptions jsonSerializerOptions =
new() { Converters = { new FigureJsonConverter() } };
private IImageSettingsProvider imageSettingsProvider = null!;

public void SetDependency(IImageSettingsProvider dependency)
{
imageSettingsProvider = dependency;
}

public string Endpoint => "/dragonFractal";

Expand All @@ -26,14 +18,10 @@ public void SetDependency(IImageSettingsProvider dependency)
public int Perform(Stream inputStream, Stream outputStream)
{
var dragonSettings = JsonSerializer.Deserialize<DragonSettings>(inputStream);
var services = new ServiceCollection();
services.AddSingleton(dragonSettings!);
services.AddSingleton(imageSettingsProvider);
services.AddSingleton<DragonPainter>();
var sp = services.BuildServiceProvider();

var painter = sp.GetRequiredService<DragonPainter>();
var figures = painter.Paint();
if (dragonSettings == null) return (int)HttpStatusCode.BadRequest;
var figures = dragonPainterFactory
.Create(dragonSettings)
.Paint();
JsonSerializer.Serialize(outputStream, figures, options: jsonSerializerOptions);

return (int)HttpStatusCode.OK;
Expand Down
10 changes: 2 additions & 8 deletions FractalPainter/Application/Actions/GetImageSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
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<IImageSettingsProvider>
public class GetImageSettingsAction(IImageSettingsProvider imageSettingsProvider) : IApiAction
{
private IImageSettingsProvider? imageSettingsProvider;

public void SetDependency(IImageSettingsProvider dependency)
{
imageSettingsProvider = dependency;
}
private IImageSettingsProvider? imageSettingsProvider = imageSettingsProvider;

public string Endpoint => "/settings";

Expand Down
10 changes: 2 additions & 8 deletions FractalPainter/Application/Actions/GetPaletteSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
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<Palette>
public class GetPaletteSettingsAction(Palette palette) : IApiAction
{
private Palette palette = null!;

public void SetDependency(Palette dependency)
{
palette = dependency;
}
private Palette palette = palette;

public string Endpoint => "/palette";

Expand Down
27 changes: 3 additions & 24 deletions FractalPainter/Application/Actions/KochFractalAction.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
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<Palette>, INeed<IImageSettingsProvider>
public class KochFractalAction(KochPainter kochPainter) : IApiAction
{
private readonly JsonSerializerOptions jsonSerializerOptions =
new() { Converters = { new FigureJsonConverter() } };
private Palette palette = null!;
private IImageSettingsProvider imageSettingsProvider = null!;

public void SetDependency(Palette dependency)
{
palette = dependency;
}
private readonly KochPainter kochPainter = kochPainter;

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<KochPainter>();
var sp = services.BuildServiceProvider();

var painter = sp.GetRequiredService<KochPainter>();
var figures = painter.Paint();
var figures = kochPainter.Paint();
JsonSerializer.Serialize(outputStream, figures, options: jsonSerializerOptions);
return (int)HttpStatusCode.OK;
}
Expand Down
10 changes: 1 addition & 9 deletions FractalPainter/Application/Actions/UpdateImageSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
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<IImageSettingsProvider>
public class UpdateImageSettingsAction(IImageSettingsProvider imageSettingsProvider) : IApiAction
{
private IImageSettingsProvider imageSettingsProvider = null!;

public void SetDependency(IImageSettingsProvider dependency)
{
imageSettingsProvider = dependency;
}

public string Endpoint => "/settings";
public string HttpMethod => "PUT";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
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<Palette>
public class UpdatePaletteSettingsAction(Palette palette) : IApiAction
{
private Palette palette = null!;

public void SetDependency(Palette dependency)
{
palette = dependency;
}
private Palette palette = palette;

public string Endpoint => "/palette";

Expand Down
37 changes: 1 addition & 36 deletions FractalPainter/Application/App.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
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;

Expand All @@ -15,27 +11,12 @@ internal sealed class App
private readonly HttpListener httpListener;
private readonly IReadOnlyDictionary<string, IApiAction> routeActions;

public App() : this(
new IApiAction[]
{
new KochFractalAction(),
new DragonFractalAction(),
new UpdateImageSettingsAction(),
new GetImageSettingsAction(),
new UpdatePaletteSettingsAction(),
new GetPaletteSettingsAction()
})
{
}

public App(IEnumerable<IApiAction> actions)
{
var actionsArray = actions.ToArray();
httpListener = new HttpListener();
httpListener.Prefixes.Add(Endpoint);
routeActions = actionsArray.ToDictionary(action => $"{action.HttpMethod} {action.Endpoint}", action => action);
DependencyInjector.Inject<IImageSettingsProvider>(actionsArray, CreateSettingsManager().Load());
DependencyInjector.Inject(actionsArray, new Palette());
}

public async Task Run()
Expand All @@ -45,8 +26,7 @@ public async Task Run()
while (true)
{
var context = await httpListener.GetContextAsync();

// Обработка запроса

try
{
var actionKey = $"{context.Request.HttpMethod} {context.Request.Url!.AbsolutePath}";
Expand All @@ -68,7 +48,6 @@ public async Task Run()

action.Perform(context.Request.InputStream, context.Response.OutputStream);
}
// Перехват ошибок
catch (Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
Expand All @@ -79,19 +58,5 @@ public async Task Run()
context.Response.Close();
}
}
// ReSharper disable once FunctionNeverReturns
}

private static SettingsManager CreateSettingsManager()
{
var services = new ServiceCollection();
services.AddSingleton<IObjectSerializer, XmlObjectSerializer>();
services.AddSingleton<IBlobStorage, FileBlobStorage>();
services.AddSingleton<SettingsManager>();

var sp = services.BuildServiceProvider();
var settingsManager = sp.GetRequiredService<SettingsManager>();

return settingsManager;
}
}
7 changes: 3 additions & 4 deletions FractalPainter/Application/Fractals/DragonPainter.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
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 class DragonPainter(Palette palette, DragonSettings settings, IImageSettingsProvider imageSettingsProvider)
{
public IReadOnlyCollection<Figure> 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 backgroundColor = palette.BackgroundColor;
var foregroundColor = palette.PrimaryColor;

var figures = new List<Figure>();
figures.Add(new Rectangle(imageSettings.Width, imageSettings.Height, new Point(0, 0), backgroundColor));
Expand Down
11 changes: 6 additions & 5 deletions FractalPainter/Application/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@
<!-- </div>-->

<div class="dropdown">
<button class="dropbtn">Фракталы</button>
<button class="dropbtn">Генераторы точек</button>
<div class="dropdown-content">
<a href="#" id="dragon-fractal-btn">Дракон</a>
<a href="#" id="koch-fractal-btn">Кривая Коха</a>
<a href="#" id="spiral-generator-btn">Спираль</a>
<a href="#" id="astroid-generator-btn">Астроида</a>
</div>
</div>

Expand All @@ -122,6 +122,7 @@
<div class="dropdown-content">
<a href="#" id="image-settings-btn">Изображение</a>
<a href="#" id="palette-settings-btn">Палитра</a>
<a href="#" id="logic-settings-btn">Логика</a>
</div>
</div>
</nav>
Expand Down Expand Up @@ -365,7 +366,7 @@
}
});

const kochFractalBtn = document.querySelector("#koch-fractal-btn");
const kochFractalBtn = document.querySelector("#astroid-generator-btn");
kochFractalBtn.addEventListener("click", function (event) {
event.preventDefault();
post("/kochFractal")
Expand Down Expand Up @@ -483,7 +484,7 @@
dragonFractalSettingsModal.classList.remove("hidden");
}

const dragonFractalButton = document.querySelector("#dragon-fractal-btn");
const dragonFractalButton = document.querySelector("#spiral-generator-btn");
dragonFractalButton.addEventListener("click", function (_) {
openDragonFractalSettingModal();
});
Expand Down
11 changes: 11 additions & 0 deletions FractalPainter/Infrastructure/Common/DragonPainterFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FractalPainting.Application.Fractals;

namespace FractalPainting.Infrastructure.Common;

public class DragonPainterFactory(IImageSettingsProvider imageSettingsProvider, Palette palette) : IDragonPainterFactory
{
private readonly IImageSettingsProvider imageSettingsProvider = imageSettingsProvider;

public DragonPainter Create(DragonSettings settings) =>
new DragonPainter(palette, settings, imageSettingsProvider);
}
6 changes: 3 additions & 3 deletions FractalPainter/Infrastructure/Common/Palette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace FractalPainting.Infrastructure.Common;

public class Palette
{
public Color PrimaryColor { get; set; } = new(255, 255, 0); // 255 255 0
public Color SecondaryColor { get; set; } = new(255, 0, 0); // 255 0 0
public Color BackgroundColor { get; set; } = new(0, 0, 139); // 0 0 139
public Color PrimaryColor { get; set; } = new(255, 255, 0);
public Color SecondaryColor { get; set; } = new(255, 0, 0);
public Color BackgroundColor { get; set; } = new(0, 0, 139);
}
18 changes: 0 additions & 18 deletions FractalPainter/Infrastructure/Injection/DependencyInjector.cs

This file was deleted.

6 changes: 0 additions & 6 deletions FractalPainter/Infrastructure/Injection/INeed.cs

This file was deleted.

Loading