|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace SvgPathExtractor |
| 8 | +{ |
| 9 | + public class ConsoleLogic |
| 10 | + { |
| 11 | + private readonly FileService fileService; |
| 12 | + private ConsoleKey? response; |
| 13 | + public ConsoleLogic() |
| 14 | + { |
| 15 | + fileService = new FileService(); |
| 16 | + response = new ConsoleKey(); |
| 17 | + } |
| 18 | + |
| 19 | + |
| 20 | + public async Task Start() |
| 21 | + { |
| 22 | + Console.WriteLine("Svg path extractor"); |
| 23 | + do |
| 24 | + { |
| 25 | + Console.Write("Are .svg files located in currently residing folder? (Y/N)"); |
| 26 | + response = Console.ReadKey(false).Key; |
| 27 | + if (response is ConsoleKey.N) |
| 28 | + { |
| 29 | + ReadFilesFromAnotherPath(); |
| 30 | + } |
| 31 | + else if (response is ConsoleKey.Y) |
| 32 | + { |
| 33 | + ReadFilesFromCurrentPath(); |
| 34 | + } |
| 35 | + } |
| 36 | + while (response is not ConsoleKey.N && response is not ConsoleKey.Y); |
| 37 | + |
| 38 | + response = null; |
| 39 | + |
| 40 | + do |
| 41 | + { |
| 42 | + Console.WriteLine("Do you want to save output anywhere else? (Y/N)"); |
| 43 | + response = Console.ReadKey(false).Key; |
| 44 | + if (response is ConsoleKey.Y) |
| 45 | + { |
| 46 | + |
| 47 | + await WriteFilesToAnotherPath(); |
| 48 | + |
| 49 | + } |
| 50 | + else if (response is ConsoleKey.N) |
| 51 | + { |
| 52 | + await WriteFilesToLocalPath(); |
| 53 | + } |
| 54 | + } |
| 55 | + while (response is not ConsoleKey.N && response is not ConsoleKey.Y); |
| 56 | + |
| 57 | + Console.Write("\noperation done. Press any key to continue..."); |
| 58 | + Console.ReadKey(true); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + private void ReadFilesFromAnotherPath() |
| 63 | + { |
| 64 | + Console.Clear(); |
| 65 | + bool isValid = false; |
| 66 | + do |
| 67 | + { |
| 68 | + Console.WriteLine("Please enter the folder file path:"); |
| 69 | + fileService.FolderPath = Console.ReadLine() ?? ""; |
| 70 | + if (string.IsNullOrWhiteSpace(fileService.FolderPath)) |
| 71 | + { |
| 72 | + Console.WriteLine("Incorrect input. please try again!\n"); |
| 73 | + } |
| 74 | + else |
| 75 | + isValid = true; |
| 76 | + } |
| 77 | + while (!isValid); |
| 78 | + fileService.ReadAllFiles(); |
| 79 | + } |
| 80 | + |
| 81 | + private void ReadFilesFromCurrentPath() |
| 82 | + { |
| 83 | + Console.Clear(); |
| 84 | + fileService.ReadAllFiles(); |
| 85 | + } |
| 86 | + |
| 87 | + private void OutputFilesToAnotherPath() |
| 88 | + { |
| 89 | + bool isValid = false; |
| 90 | + Console.Clear(); |
| 91 | + do |
| 92 | + { |
| 93 | + Console.WriteLine("Where would you like to output the result?"); |
| 94 | + Console.Write("Path: "); |
| 95 | + fileService.OutputPath = Console.ReadLine() ?? ""; |
| 96 | + if (string.IsNullOrWhiteSpace(fileService.OutputPath)) |
| 97 | + { |
| 98 | + Console.WriteLine("Incorrect input. please try again!\n"); |
| 99 | + } |
| 100 | + else |
| 101 | + isValid = true; |
| 102 | + } |
| 103 | + while (!isValid); |
| 104 | + } |
| 105 | + |
| 106 | + private async Task WriteFilesToAnotherPath() |
| 107 | + { |
| 108 | + OutputFilesToAnotherPath(); |
| 109 | + await fileService.WriteOutputToJson(); |
| 110 | + } |
| 111 | + private async Task WriteFilesToLocalPath() |
| 112 | + { |
| 113 | + fileService.CreateNewDirectory(); |
| 114 | + await fileService.WriteOutputToJson(); |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments