-
Notifications
You must be signed in to change notification settings - Fork 32
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
Бессараб Дмитрий #31
Open
d2em0n
wants to merge
29
commits into
kontur-courses:master
Choose a base branch
from
d2em0n:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Бессараб Дмитрий #31
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
59d38a8
start
d2em0n 45b91db
add simple filter
d2em0n 441cd69
add textprocessor
d2em0n 143db64
add some tests for processor, filter, provider
d2em0n baf26aa
add layout with some tests
d2em0n 8149754
add interface for TextProcessor
d2em0n 1b85764
add Tag and interface for Tag generator
d2em0n 3f413ea
remove and sort usings, text processor refactoring
d2em0n 29ea260
Word became record
d2em0n e9254ec
add interface for string parsers
d2em0n 5259a19
add rnd color tag generator
d2em0n 78bb80a
add shortwordfilter
d2em0n cf302b3
hypothesis
d2em0n 66b48b9
add chosing color
d2em0n c329079
add IColorProvider and refactor TagGenerator
d2em0n 529f90c
pattern filter for filters
d2em0n 821147e
container refuse to wark (
d2em0n 2392c92
mvp
d2em0n db6772b
add DocTextProvider
d2em0n 29142c4
DocXTextProvider
d2em0n 2cb1edd
minus unused usings
d2em0n 8eeaab8
fix color and pointgenerator checking
d2em0n ab0392f
fix color data integrity
d2em0n 825fa46
fix random for multithreading in randomcolorprovider
d2em0n 2fa6816
no public mod to interface methods
d2em0n 946768e
fix TxtText provider
d2em0n 7c1ca09
dispose idisposable
d2em0n ef193e7
fix regexparser
d2em0n cb067a4
fix packages
d2em0n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TagsCloudContainer\TagsCloudContainer.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="test.doc"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="test.docx"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="TestFile.txt"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Autofac; | ||
using TagsCloudContainer; | ||
using TagsCloudContainer.ColorProviders; | ||
using TagsCloudContainer.Configuration; | ||
using TagsCloudContainer.PointGenerators; | ||
using TagsCloudContainer.StringParsers; | ||
using TagsCloudContainer.TagGenerator; | ||
using TagsCloudContainer.TextProcessor; | ||
using TagsCloudContainer.TextProviders; | ||
using TagsCloudContainer.WordFilters; | ||
|
||
namespace Client; | ||
|
||
public class DependencyInjection | ||
{ | ||
public static IContainer BuildContainer(Config config) | ||
{ | ||
var container = new ContainerBuilder(); | ||
container.RegisterInstance(config).AsSelf(); | ||
|
||
container.RegisterType(config.SupportedReadingFormats[Path.GetExtension(config.FilePath)]) | ||
.As<ITextProvider>() | ||
.WithParameter("filePath", config.FilePath) | ||
.SingleInstance(); | ||
container.RegisterType<TextProcessor>() | ||
.As<ITextProcessor>() | ||
.SingleInstance(); | ||
|
||
container.RegisterType(config.PointGenerator) | ||
.As<IPointGenerator>() | ||
.SingleInstance(); | ||
|
||
if (config.Color != null) | ||
container.RegisterType<ColorProvider>() | ||
.As<IColorProvider>() | ||
.WithParameter("color", config.Color) | ||
.SingleInstance(); | ||
else | ||
container.RegisterType<RandomColorProvider>() | ||
.As<IColorProvider>() | ||
.SingleInstance(); | ||
|
||
container.RegisterType<RegexParser>() | ||
.As<IStringParser>() | ||
.SingleInstance(); | ||
|
||
container.RegisterType<TagGenerator>() | ||
.As<ITagsGenerator>() | ||
.WithParameter("defaultFont", config.Font) | ||
.SingleInstance(); | ||
|
||
|
||
|
||
container.RegisterType<ToLowerFilter>().As<IWordFilter>() | ||
.SingleInstance(); | ||
container.RegisterType<ShortWordFilter>().As<IWordFilter>() | ||
.SingleInstance(); | ||
container.RegisterType<BoringWordFilter>().As<IWordFilter>() | ||
.SingleInstance(); | ||
|
||
container.RegisterType<PictureMaker>() | ||
.AsSelf() | ||
.WithParameter("fileName", config.PicturePath) | ||
.WithParameter("startPoint", config.StartPoint) | ||
.SingleInstance(); | ||
|
||
return container.Build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System.Drawing; | ||
using System.Reflection; | ||
using TagsCloudContainer.Configuration; | ||
using TagsCloudContainer.PointGenerators; | ||
using TagsCloudContainer.TextProviders; | ||
using TagsCloudContainer; | ||
using Autofac; | ||
|
||
namespace Client | ||
{ | ||
internal class Program | ||
{ | ||
static void Main() | ||
{ | ||
var config = new Config(); | ||
|
||
ConfigureSupportedReadingFormats(config); | ||
ConfigureFileSource(config); | ||
ConfigureCloudView(config); | ||
ConfigureColor(config); | ||
ConfigurePathToSave(config); | ||
ConfigureStartPoint(config); | ||
ConfigureFont(config); | ||
|
||
var container = DependencyInjection.BuildContainer(config); | ||
using var scope = container.BeginLifetimeScope(); | ||
scope.Resolve<PictureMaker>().DrawPicture(); | ||
Console.WriteLine($"результат сохранен в {config.PicturePath}"); | ||
} | ||
|
||
private static void ConfigureSupportedReadingFormats(Config config) | ||
{ | ||
Console.WriteLine("Поддерживаются следующие форматы файлов для чтения:"); | ||
var textProviders = FindImplemetations<ITextProvider>(); | ||
foreach (var point in textProviders) | ||
Console.WriteLine("\t" + point.Key); | ||
config.SupportedReadingFormats = textProviders; | ||
} | ||
|
||
private static void ConfigureFont(Config config) | ||
{ | ||
config.Font = new Font("arial", 12); | ||
} | ||
|
||
private static void ConfigurePathToSave(Config config) | ||
{ | ||
Console.WriteLine("Введите полный путь и название файла для сохранения"); | ||
var inp = Console.ReadLine(); | ||
config.PicturePath = inp.Length == 0 ? "1.bmp" : inp; | ||
} | ||
|
||
private static void ConfigureStartPoint(Config config) | ||
{ | ||
Console.WriteLine("Введите координаты центра поля для рисования" + | ||
"\n При некорректном вводе координаты центра составят ( 1000, 1000)"); | ||
var xLine = ReadValue("Координата Х"); | ||
var yLine = ReadValue("Координата Y"); | ||
if (int.TryParse(xLine, out var xResult) && | ||
int.TryParse(yLine, out var yResult)) | ||
config.StartPoint = new Point(xResult, yResult); | ||
config.StartPoint = new Point(1000, 1000); | ||
} | ||
|
||
private static void ConfigureFileSource(Config config) | ||
{ | ||
Console.WriteLine("Введите имя файла источника тэгов"); | ||
var inp = Console.ReadLine(); | ||
config.FilePath = inp.Length == 0 ? @"TestFile.txt" : inp; | ||
} | ||
|
||
private static string GetLabel(RainbowColors color) | ||
{ | ||
var fieldInfo = color.GetType().GetField(color.ToString()); | ||
var attribute = (LabelAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(LabelAttribute)); | ||
|
||
return attribute.LabelText; | ||
} | ||
|
||
private static void ConfigureColor(Config config) | ||
{ | ||
Console.WriteLine("Выборите цвет из возможных:"); | ||
var colors = Enum.GetValues(typeof(RainbowColors)) | ||
.Cast<RainbowColors>() | ||
.ToDictionary(color => GetLabel(color).ToLower(), color => color); | ||
|
||
foreach (var color in colors) | ||
Console.WriteLine("\t" + color.Key); | ||
|
||
Console.WriteLine("В случае неправильного ввода - цвет будет выбираться случайным образом"); | ||
var inp = Console.ReadLine().ToLower(); | ||
if (colors.TryGetValue(inp, out var colorName)) | ||
{ | ||
config.Color = Color.FromName(colorName.ToString()); | ||
Console.WriteLine($"Выбран {inp} цвет"); | ||
} | ||
else | ||
Console.WriteLine("Цвет будет выбираться случайно"); | ||
|
||
} | ||
|
||
private static void ConfigureCloudView(Config config) | ||
{ | ||
Console.WriteLine("Выберите внешний вид облака из возможных:"); | ||
var pointGenerators = FindImplemetations<IPointGenerator>(); | ||
foreach (var point in pointGenerators) | ||
Console.WriteLine("\t" + point.Key); | ||
Console.WriteLine("Введите, соблюдая орфографию"); | ||
var pointGenerator = Console.ReadLine().ToLower(); | ||
if (pointGenerators.TryGetValue(pointGenerator, out var pointGeneratorName)) | ||
config.PointGenerator = pointGeneratorName; | ||
else | ||
{ | ||
Console.WriteLine("Такой формы не предусмотрено"); | ||
ConfigureCloudView(config); | ||
} | ||
} | ||
|
||
private static Dictionary<string, Type> FindImplemetations<T>() | ||
{ | ||
var assembly = Assembly.LoadFrom("TagsCloudContainer.dll"); | ||
var type = typeof(T); | ||
return assembly.GetTypes() | ||
.Where(t => type.IsAssignableFrom(t) && !t.IsInterface) | ||
.ToDictionary(x => x.GetCustomAttribute<LabelAttribute>().LabelText.ToLower(), x => x); | ||
} | ||
|
||
private static string? ReadValue(string? argName = null) | ||
{ | ||
Console.Write($"{argName ?? ""}: "); | ||
return Console.ReadLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
корзина корзина корзина корзина фрукты фрукты фрукты овощи овощи овощи яблоки груши бананы смородина персики картофель свекла | ||
морковь он я ты она за по |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using FluentAssertions; | ||
using System.Drawing; | ||
using TagsCloudContainer.PointGenerators; | ||
|
||
|
||
namespace TagsCloudContainer.Tests | ||
{ | ||
[TestFixture] | ||
public class CloudLayoutShould | ||
{ | ||
[TestCase(1, 2, TestName = "Odd coordinate value results in an even size value")] | ||
[TestCase(2, 5, TestName = "Even coordinate value results in an odd size value")] | ||
public void MakeRightSizeLayout(int coordinateValue, int sizeValue) | ||
{ | ||
var center = new Point(coordinateValue, coordinateValue); | ||
var size = new Size(sizeValue, sizeValue); | ||
|
||
var layout = new CloudLayout(center, new ArchemedianSpiral()); | ||
|
||
layout.Size.Should().BeEquivalentTo(size); | ||
} | ||
|
||
[TestCase(-1, 1, TestName = "Negative X")] | ||
[TestCase(1, -1, TestName = "Negative Y")] | ||
[TestCase(0, 1, TestName = "Zero X")] | ||
[TestCase(1, 0, TestName = "Zero Y")] | ||
public void GetOnlyPositiveCenterCoordinates(int x, int y) | ||
{ | ||
Action makeLayout = () => new CloudLayout(new Point(x, y), new ArchemedianSpiral()); | ||
|
||
makeLayout.Should().Throw<ArgumentException>() | ||
.WithMessage("Center coordinates values have to be greater than Zero"); | ||
} | ||
|
||
[Test] | ||
public void PutNextRectangle_ShouldKeepEnteredSize() | ||
{ | ||
var layout = new CloudLayout(new Point(5, 5), new ArchemedianSpiral()); | ||
var enteredSize = new Size(3, 4); | ||
var returnedSize = layout.PutNextRectangle(enteredSize).Size; | ||
|
||
returnedSize.Should().BeEquivalentTo(enteredSize); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using FluentAssertions; | ||
using System.Drawing; | ||
using TagsCloudContainer.PointGenerators; | ||
|
||
namespace TagsCloudContainer.Tests | ||
{ | ||
[TestFixture] | ||
public class IPointGeneratorShould | ||
{ | ||
[TestCaseSource(nameof(TestCases))] | ||
public void GeneratePoints_MovingAwayFromTheStartFor(IPointGenerator pointGenerator) | ||
{ | ||
var start = new Point(0, 0); | ||
var points = pointGenerator.GeneratePoints(start); | ||
var nearPoint = points.ElementAt(100); | ||
var farPoint = points.ElementAt(1000); | ||
|
||
DistanceBetween(start, nearPoint).Should().BeLessThan(DistanceBetween(start, farPoint)); | ||
} | ||
|
||
[TestCaseSource(nameof(TestCases))] | ||
public void GeneratePoints_ReturnsStartAsFirstPointFor(IPointGenerator pointGenerator) | ||
{ | ||
var start = new Point(100, 100); | ||
var firstReturned = pointGenerator.GeneratePoints(start) | ||
.First(); | ||
|
||
firstReturned.Should().BeEquivalentTo(start); | ||
} | ||
|
||
private static IEnumerable<IPointGenerator> TestCases() | ||
{ | ||
yield return new ArchemedianSpiral(); | ||
yield return new HeartShaped(); | ||
yield return new DeltaShaped(); | ||
} | ||
|
||
private static int DistanceBetween(Point start, Point destination) | ||
{ | ||
return (int)Math.Sqrt((start.X - destination.X) * (start.X - destination.X) + | ||
(start.Y - destination.Y) * (start.Y - destination.Y)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using FluentAssertions; | ||
using TagsCloudContainer.ColorProviders; | ||
using TagsCloudContainer.StringParsers; | ||
using TagsCloudContainer.TextProviders; | ||
using TagsCloudContainer.WordFilters; | ||
|
||
namespace TagsCloudContainer.Tests | ||
{ | ||
public class TagGeneratorShould | ||
{ | ||
[Test] | ||
public void SetRightFontSize() | ||
{ | ||
var processor = new TextProcessor.TextProcessor( | ||
new TxtTextProvider(@"TextFile1.txt"), new RegexParser(), new ToLowerFilter(), new BoringWordFilter()); | ||
var words = processor.WordFrequencies(); | ||
var generator = new TagGenerator.TagGenerator(new RandomColorProvider(), new System.Drawing.Font("arial", 12)); | ||
var result = generator.GenerateTags(words).First(); | ||
|
||
result.Font.Name.Should().Be("Arial"); | ||
result.Font.Size.Should().Be(36); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="FluentAssertions" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="NUnit" Version="3.14.0" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TagsCloudContainer\TagsCloudContainer.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="TextFile1.txt"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
он ОНА ОНО корзина творог печенье Корзина ++ ,- = корЗина по ха за |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно использовать без усложнений со скоупами, так как жизненный цикл всех сущностей совпадает с временем жизни всего приложения. Просто у контейнера вызывать Resolve