-
Notifications
You must be signed in to change notification settings - Fork 240
Якшибаев Данил #214
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
Open
gogy4
wants to merge
4
commits into
kontur-courses:master
Choose a base branch
from
gogy4: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
Якшибаев Данил #214
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b81899
feat(TagCloudGenerator): add tag cloud generator from previous task
gogy4 6e6e46e
apply Result pattern and update tests accordingly
gogy4 54bb5b1
feate(TagCloud): apply Result pattern and update tests accordingly
gogy4 0a62140
Merge remote-tracking branch 'origin/master'
gogy4 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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,20 @@ | ||
| using Autofac; | ||
| using ErrorHandling; | ||
| using TagCloud.DI; | ||
|
|
||
| namespace TagCloud.Client; | ||
|
|
||
| public static class ContainerBuilderHelper | ||
| { | ||
| public static Result<(IContainer container, ProgramArgs args)> BuildContainer(ProgramArgs args) | ||
| { | ||
| return Result.Of(() => | ||
| { | ||
| var builder = new ContainerBuilder(); | ||
| builder.RegisterModule(new TagCloudModule(args.WordsFile, args.StopWordsFile)); | ||
|
|
||
| var container = builder.Build(); | ||
| return (container, args); | ||
| }, "Ошибка при создании контейнера"); | ||
| } | ||
| } |
This file contains hidden or 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,30 @@ | ||
| using ErrorHandling; | ||
| using TagCloud.Client; | ||
|
|
||
| public class Program | ||
| { | ||
| public static int Main(string[] args) | ||
| { | ||
| return Run(args) | ||
| .OnFail(err => Console.WriteLine("Ошибка: " + err)) | ||
| .IsSuccess | ||
| ? 0 | ||
| : -1; | ||
| } | ||
|
|
||
| private static Result<None> Run(string[] args) | ||
| { | ||
| return | ||
| ProgramArgsValidator.ValidateArgs(args) | ||
| .Then(ProgramArgsValidator.ParseArgs) | ||
| .Then(ProgramArgsValidator.ValidateFiles) | ||
| .Then(ProgramArgsValidator.ValidateFont) | ||
| .Then(ContainerBuilderHelper.BuildContainer) | ||
| .Then(TagCloudGeneratorHelper.GenerateTagCloud) | ||
| .Then(_ => | ||
| { | ||
| Console.WriteLine("Генерация завершена"); | ||
| return None.Value; | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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,9 @@ | ||
| namespace TagCloud.Client; | ||
|
|
||
| public record ProgramArgs( | ||
| string WordsFile, | ||
| string StopWordsFile, | ||
| string OutputFile, | ||
| int Width, | ||
| int Height, | ||
| string FontName); |
This file contains hidden or 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,85 @@ | ||
| using System.Drawing; | ||
| using System.Drawing.Text; | ||
| using Autofac; | ||
| using ErrorHandling; | ||
| using TagCloud; | ||
| using TagCloud.DI; | ||
| using TagCloud.Models; | ||
|
|
||
| namespace TagCloud.Client; | ||
|
|
||
| public static class ProgramArgsValidator | ||
| { | ||
| public static Result<string[]> ValidateArgs(string[] args) | ||
| { | ||
| return args.Length < 3 | ||
| ? Result.Fail<string[]>("Не переданы аргументы") | ||
| : Result.Ok(args); | ||
| } | ||
|
|
||
| public static Result<ProgramArgs> ParseArgs(string[] args) | ||
| { | ||
| return Result.Of(() => | ||
| { | ||
| var width = args.Length > 3 ? int.Parse(args[3]) : 1200; | ||
| var height = args.Length > 4 ? int.Parse(args[4]) : 800; | ||
| var fontName = args.Length > 5 ? args[5] : "Arial"; | ||
|
|
||
| return new ProgramArgs( | ||
| args[0], | ||
| args[1], | ||
| args[2], | ||
| width, | ||
| height, | ||
| fontName | ||
| ); | ||
| }, "Ошибка при разборе аргументов"); | ||
| } | ||
|
|
||
| public static Result<ProgramArgs> ValidateFiles(ProgramArgs args) | ||
| { | ||
| if (!File.Exists(args.WordsFile)) | ||
| return Result.Fail<ProgramArgs>($"Файл слов не найден: {args.WordsFile}"); | ||
|
|
||
| return !File.Exists(args.StopWordsFile) | ||
| ? Result.Fail<ProgramArgs>($"Файл стоп-слов не найден: {args.StopWordsFile}") | ||
| : Result.Ok(args); | ||
| } | ||
|
|
||
| public static Result<ProgramArgs> ValidateFont(ProgramArgs args) | ||
| { | ||
| var fonts = new InstalledFontCollection(); | ||
|
|
||
| var exists = fonts.Families | ||
| .Any(f => string.Equals(f.Name, args.FontName, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| return !exists ? Result.Fail<ProgramArgs>($"Шрифт не найден в системе: {args.FontName}") : Result.Ok(args); | ||
| } | ||
|
|
||
| public static Result<None> GenerateTagCloud((IContainer container, ProgramArgs args) input) | ||
| { | ||
| return Result.Of(() => | ||
| { | ||
| var (container, args) = input; | ||
|
|
||
| var config = new TagCloudVisualizationConfig | ||
| { | ||
| CanvasWidth = args.Width, | ||
| CanvasHeight = args.Height, | ||
| CanvasBackgroundColor = Color.Black, | ||
| ShapeFillColor = Color.DarkSlateGray, | ||
| ShapeBorderColor = Color.White, | ||
| ShapeBorderThickness = 1, | ||
| FontName = args.FontName | ||
| }; | ||
|
|
||
| using var scope = container.BeginLifetimeScope(); | ||
| var generator = scope.Resolve<TagCloudGenerator>(); | ||
|
|
||
| generator.Generate(args.OutputFile, config); | ||
|
|
||
| Console.WriteLine($"Файл сохранён: {args.OutputFile}"); | ||
| return None.Value; | ||
| }, "Ошибка при генерации облака тегов"); | ||
| } | ||
| } |
This file contains hidden or 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,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Autofac" Version="9.0.0"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ErrorHandling\ErrorHandling.csproj" /> | ||
| <ProjectReference Include="..\TagCloud.Core\TagCloud.Core.csproj"/> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,37 @@ | ||
| using System.Drawing; | ||
| using Autofac; | ||
| using ErrorHandling; | ||
| using TagCloud.Models; | ||
|
|
||
|
|
||
| namespace TagCloud.Client; | ||
|
|
||
| public static class TagCloudGeneratorHelper | ||
| { | ||
| public static Result<None> GenerateTagCloud((IContainer container, ProgramArgs args) input) | ||
| { | ||
| return Result.Of(() => | ||
| { | ||
| var (container, args) = input; | ||
|
|
||
| var config = new TagCloudVisualizationConfig | ||
| { | ||
| CanvasWidth = args.Width, | ||
| CanvasHeight = args.Height, | ||
| CanvasBackgroundColor = Color.Black, | ||
| ShapeFillColor = Color.DarkSlateGray, | ||
| ShapeBorderColor = Color.White, | ||
| ShapeBorderThickness = 1, | ||
| FontName = args.FontName | ||
| }; | ||
|
|
||
| using var scope = container.BeginLifetimeScope(); | ||
| var generator = scope.Resolve<TagCloudGenerator>(); | ||
|
|
||
| generator.Generate(args.OutputFile, config); | ||
|
|
||
| Console.WriteLine($"Файл сохранён: {args.OutputFile}"); | ||
| return None.Value; | ||
| }, "Ошибка при генерации облака тегов"); | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains hidden or 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,11 @@ | ||
| hello | ||
| the | ||
| and | ||
| a | ||
| of | ||
| in | ||
| on | ||
| at | ||
| for | ||
| rain | ||
| sun |
Binary file not shown.
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.
кмк
EmptyResultлучше