-
Notifications
You must be signed in to change notification settings - Fork 240
Шагов Владислав #211
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
ShagovVladislav
wants to merge
3
commits into
kontur-courses:master
Choose a base branch
from
ShagovVladislav: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
Шагов Владислав #211
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
41 changes: 41 additions & 0 deletions
41
TagsCloudResult/ConsoleAppWordsCloud/CloudGenerationClient.cs
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,41 @@ | ||
| using WordsCloudGenerator; | ||
| using WordsCloudGenerator.models; | ||
|
|
||
| namespace ConsoleAppWordsCloud; | ||
|
|
||
| public sealed class CloudGenerationClient | ||
| { | ||
| private readonly ICloudGenerator generator; | ||
|
|
||
| public CloudGenerationClient(ICloudGenerator generator) | ||
| { | ||
| this.generator = generator; | ||
| } | ||
|
|
||
| public Result Generate(ConsoleCloudSettings settings) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(settings.InputFile)) | ||
| return Result.Fail("Input file is empty"); | ||
|
|
||
| var g = generator | ||
| .From(settings.InputFile) | ||
| .To(settings.OutputFile) | ||
| .WithLayouter(settings.Layout) | ||
| .WithFontSizeRange(settings.MinFontSize, settings.MaxFontSize) | ||
| .WithBackground(settings.Background) | ||
| .WithColorTheme(settings.Colors.ToArray()) | ||
| .WithFontFamily(settings.FontFamily) | ||
| .WithPadding(settings.Padding); | ||
|
|
||
| if (settings.ExcludedWordsFile != null) | ||
| g.WithExcludedWordsFile(settings.ExcludedWordsFile); | ||
|
|
||
| if (settings.CanvasSize.HasValue) | ||
| g.WithCanvasSize( | ||
| settings.CanvasSize.Value.Width, | ||
| settings.CanvasSize.Value.Height); | ||
|
|
||
| var generateResult = g.Generate(); | ||
| return generateResult; | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
TagsCloudResult/ConsoleAppWordsCloud/ConsoleAppWordsCloud.csproj
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,27 @@ | ||
| <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="..\WordsCloudGenerator\WordsCloudGenerator.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Content Include="..\WordsCloudGenerator\dicts\**"> | ||
| <Link>dicts\%(RecursiveDir)%(FileName)%(Extension)</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Folder Include="output\" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
25 changes: 25 additions & 0 deletions
25
TagsCloudResult/ConsoleAppWordsCloud/ConsoleCloudSettings.cs
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,25 @@ | ||
| using System.Drawing; | ||
| using WordsCloudGenerator.layout; | ||
|
|
||
| namespace ConsoleAppWordsCloud; | ||
|
|
||
| public sealed class ConsoleCloudSettings | ||
| { | ||
| public string InputFile { get; set; } | ||
| public string OutputFile { get; set; } = "cloud.png"; | ||
|
|
||
| public LayoutType Layout { get; set; } = LayoutType.Circular; | ||
|
|
||
| public int MinFontSize { get; set; } = 10; | ||
| public int MaxFontSize { get; set; } = 60; | ||
|
|
||
| public Size? CanvasSize { get; set; } | ||
|
|
||
| public Color Background { get; set; } = Color.Black; | ||
| public List<Color> Colors { get; set; } = new() { Color.LawnGreen }; | ||
|
|
||
| public string FontFamily { get; set; } = "Arial Black"; | ||
| public int Padding { get; set; } | ||
|
|
||
| public string? ExcludedWordsFile { get; set; } | ||
| } |
226 changes: 226 additions & 0 deletions
226
TagsCloudResult/ConsoleAppWordsCloud/ConsoleSettingsUI.cs
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,226 @@ | ||
| using System.Drawing; | ||
| using WordsCloudGenerator.layout; | ||
| using WordsCloudGenerator.models; | ||
|
|
||
| namespace ConsoleAppWordsCloud; | ||
|
|
||
| public sealed class ConsoleSettingsUI | ||
| { | ||
| private readonly ConsoleCloudSettings settings = new(); | ||
|
|
||
| public Result<ConsoleCloudSettings> Run() | ||
| { | ||
| while (true) | ||
| { | ||
| Console.Clear(); | ||
| DrawMenu(); | ||
|
|
||
| Console.Write("\nВыберите пункт: "); | ||
| var input = Console.ReadLine()?.Trim().ToUpper(); | ||
|
|
||
| switch (input) | ||
| { | ||
| case "1": SetInputFile(); break; | ||
| case "2": SetOutputFile(); break; | ||
| case "3": ChooseLayout(); break; | ||
| case "4": SetFontRange(); break; | ||
| case "5": SetCanvas(); break; | ||
| case "6": SetColors(); break; | ||
| case "7": SetBackground(); break; | ||
| case "8": SetFontFamily(); break; | ||
| case "9": SetPadding(); break; | ||
| case "10": SetExcludedWordsFile(); break; | ||
|
|
||
| case "G": | ||
| return Result<ConsoleCloudSettings>.Ok(settings); | ||
|
|
||
| case "Q": | ||
| return Result<ConsoleCloudSettings>.Fail("Cancelled by user"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void DrawMenu() | ||
| { | ||
| Console.WriteLine("WORD CLOUD GENERATOR"); | ||
| Console.WriteLine("===================\n"); | ||
|
|
||
| Console.WriteLine($"1. Входной файл: {settings.InputFile ?? "<не задан>"}"); | ||
| Console.WriteLine($"2. Выходной файл: {settings.OutputFile}"); | ||
| Console.WriteLine($"3. Layout: {settings.Layout}"); | ||
| Console.WriteLine($"4. Размер шрифта: {settings.MinFontSize} - {settings.MaxFontSize}"); | ||
| Console.WriteLine( | ||
| $"5. Холст: {(settings.CanvasSize.HasValue | ||
| ? $"{settings.CanvasSize.Value.Width}x{settings.CanvasSize.Value.Height}" : "auto")}"); | ||
| Console.WriteLine($"6. Цвета слов: {string.Join(", ", settings.Colors.Select(c => c.Name))}"); | ||
| Console.WriteLine($"7. Фон: {settings.Background.Name}"); | ||
| Console.WriteLine($"8. Шрифт: {settings.FontFamily}"); | ||
| Console.WriteLine($"9. Padding: {settings.Padding}"); | ||
| Console.WriteLine($"10. Стоп-слова: {settings.ExcludedWordsFile ?? "<не задан>"}"); | ||
|
|
||
|
|
||
| Console.WriteLine("\n[G] Generate"); | ||
| Console.WriteLine("[Q] Quit"); | ||
| } | ||
|
|
||
| private void SetInputFile() | ||
| { | ||
| Console.Write("\nВведите путь к входному файлу: "); | ||
| var path = Console.ReadLine(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(path)) | ||
| return; | ||
|
|
||
| if (!File.Exists(path)) | ||
| { | ||
| Console.WriteLine("Файл не найден."); | ||
| Console.ReadKey(); | ||
| return; | ||
| } | ||
|
|
||
| settings.InputFile = path; | ||
| } | ||
|
|
||
| private void SetOutputFile() | ||
| { | ||
| Console.Write("\nВведите путь для сохранения (png): "); | ||
| var path = Console.ReadLine(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(path)) | ||
| return; | ||
|
|
||
| settings.OutputFile = path; | ||
| } | ||
|
|
||
| private void SetFontRange() | ||
| { | ||
| Console.Write("\nМинимальный размер шрифта: "); | ||
| if (!int.TryParse(Console.ReadLine(), out var min) || min <= 0) | ||
| return; | ||
|
|
||
| Console.Write("Максимальный размер шрифта: "); | ||
| if (!int.TryParse(Console.ReadLine(), out var max) || max < min) | ||
| return; | ||
|
|
||
| settings.MinFontSize = min; | ||
| settings.MaxFontSize = max; | ||
| } | ||
|
|
||
| private void SetBackground() | ||
| { | ||
| Console.WriteLine("\nВведите цвет фона (Black, White, #112233)"); | ||
| Console.Write("> "); | ||
| var input = Console.ReadLine(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(input)) | ||
| return; | ||
|
|
||
| var color = ParseColor(input.Trim()); | ||
| if (color.HasValue) | ||
| settings.Background = color.Value; | ||
| } | ||
|
|
||
| private void SetFontFamily() | ||
| { | ||
| Console.Write("\nВведите название шрифта (например: Arial, Times New Roman): "); | ||
| var font = Console.ReadLine(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(font)) | ||
| return; | ||
|
|
||
| settings.FontFamily = font; | ||
| } | ||
|
|
||
| private void SetPadding() | ||
| { | ||
| Console.Write("\nВведите padding (>= 0): "); | ||
| if (!int.TryParse(Console.ReadLine(), out var value) || value < 0) | ||
| return; | ||
|
|
||
| settings.Padding = value; | ||
| } | ||
|
|
||
| private void SetExcludedWordsFile() | ||
| { | ||
| Console.Write("\nВведите путь к файлу со стоп-словами (пусто — убрать): "); | ||
| var path = Console.ReadLine(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(path)) | ||
| { | ||
| settings.ExcludedWordsFile = null; | ||
| return; | ||
| } | ||
|
|
||
| if (!File.Exists(path)) | ||
| { | ||
| Console.WriteLine("Файл не найден."); | ||
| Console.ReadKey(); | ||
| return; | ||
| } | ||
|
|
||
| settings.ExcludedWordsFile = path; | ||
| } | ||
|
|
||
| private void SetColors() | ||
| { | ||
| Console.WriteLine("\nВведите цвета через запятую (Red, Green, #FF00FF)"); | ||
| Console.Write("> "); | ||
| var input = Console.ReadLine(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(input)) | ||
| return; | ||
|
|
||
| settings.Colors.Clear(); | ||
|
|
||
| foreach (var token in input.Split(',')) | ||
| { | ||
| var color = ParseColor(token.Trim()); | ||
| if (color.HasValue) | ||
| settings.Colors.Add(color.Value); | ||
| } | ||
|
|
||
| if (settings.Colors.Count == 0) | ||
| settings.Colors.Add(Color.LawnGreen); | ||
| } | ||
|
|
||
| private static Color? ParseColor(string value) | ||
| { | ||
| try | ||
| { | ||
| return value.StartsWith("#") ? ColorTranslator.FromHtml(value) : Color.FromName(value); | ||
| } | ||
| catch | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private void ChooseLayout() | ||
| { | ||
| Console.WriteLine("\n1 - Circular\n2 - Rectangular"); | ||
| Console.Write("> "); | ||
| settings.Layout = Console.ReadLine() == "2" | ||
| ? LayoutType.Rectangular | ||
| : LayoutType.Circular; | ||
| } | ||
|
|
||
| private void SetCanvas() | ||
| { | ||
| Console.Write("\nВведите ширину (0 = auto): "); | ||
| if (!int.TryParse(Console.ReadLine(), out var w) || w < 0) | ||
| return; | ||
|
|
||
| if (w == 0) | ||
| { | ||
| settings.CanvasSize = null; | ||
| return; | ||
| } | ||
|
|
||
| Console.Write("Введите высоту: "); | ||
| if (!int.TryParse(Console.ReadLine(), out var h) || h <= 0) | ||
| return; | ||
|
|
||
| settings.CanvasSize = new Size(w, h); | ||
| } | ||
|
|
||
| } |
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,56 @@ | ||
| using System.Diagnostics; | ||
| using Autofac; | ||
| using WordsCloudGenerator; | ||
|
|
||
| namespace ConsoleAppWordsCloud; | ||
|
|
||
| public static class Program | ||
| { | ||
| static void Main() | ||
| { | ||
| var builder = new ContainerBuilder(); | ||
| builder.RegisterModule<WordsCloudModule>(); | ||
| using var container = builder.Build(); | ||
|
|
||
| var ui = new ConsoleSettingsUI(); | ||
| var settingsResult = ui.Run(); | ||
| var settings = settingsResult.Value; | ||
| if (!settingsResult.IsSuccess) return; | ||
|
|
||
| var generator = container.Resolve<ICloudGenerator>(); | ||
| var client = new CloudGenerationClient(generator); | ||
|
|
||
| var result = client.Generate(settings); | ||
|
|
||
| if (!result.IsSuccess) | ||
| { | ||
| Console.WriteLine($"Ошибка: {result.Error}"); | ||
| Console.ReadKey(); | ||
| return; | ||
| } | ||
|
|
||
| OpenFile(settings.OutputFile); | ||
| } | ||
|
|
||
| private static void OpenDirectory(string path) | ||
| { | ||
| var directory = Path.GetDirectoryName(path); | ||
| if (string.IsNullOrWhiteSpace(directory)) | ||
| directory = Directory.GetCurrentDirectory(); | ||
|
|
||
| Process.Start(new ProcessStartInfo | ||
| { | ||
| FileName = directory, | ||
| UseShellExecute = true | ||
| }); | ||
| } | ||
|
|
||
| private static void OpenFile(string path) | ||
| { | ||
| Process.Start(new ProcessStartInfo | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут наоборот не нужен перенос |
||
| { | ||
| FileName = path, | ||
| UseShellExecute = true | ||
| }); | ||
| } | ||
| } | ||
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.
Тут нужен перенос между методами