Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit d353303

Browse files
authored
Merge pull request #1 from tavanuka/console-extract
Rework interaction logic
2 parents da65bc2 + cd1eb49 commit d353303

2 files changed

Lines changed: 119 additions & 89 deletions

File tree

‎ConsoleLogic.cs‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
}

‎Program.cs‎

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,12 @@
11
// See https://aka.ms/new-console-template for more information
22
using SvgPathExtractor;
33

4-
FileService fileService = new();
5-
ConsoleKey? response;
6-
Console.WriteLine("Svg path extractor");
7-
do
8-
{
9-
Console.Write("Are .svg files located in currently residing folder? (Y/N)");
10-
response = Console.ReadKey(false).Key;
11-
if (response is ConsoleKey.N)
12-
{
13-
ReadFilesFromAnotherPath(fileService);
14-
}
15-
else if (response is ConsoleKey.Y)
16-
{
17-
ReadFilesFromCurrentPath(fileService);
18-
}
19-
}
20-
while (response is not ConsoleKey.N && response is not ConsoleKey.Y);
4+
ConsoleLogic logic = new ConsoleLogic();
215

22-
response = null;
6+
await logic.Start();
237

24-
do
25-
{
26-
Console.WriteLine("Do you want to save output anywhere else? (Y/N)");
27-
response = Console.ReadKey(false).Key;
28-
if (response is ConsoleKey.Y)
29-
{
30-
OutputFilesToAnotherPath();
31-
await WriteFilesToAnotherPath(fileService);
328

33-
}
34-
else if (response is ConsoleKey.N)
35-
{
36-
await WriteFilesToLocalPath(fileService);
37-
}
38-
}
39-
while (response is not ConsoleKey.N && response is not ConsoleKey.Y);
409

41-
Console.Write("\noperation done. Press any key to continue...");
42-
Console.ReadKey(true);
43-
44-
void ReadFilesFromAnotherPath(FileService fileService)
45-
{
46-
Console.Clear();
47-
bool isValid = false;
48-
do
49-
{
50-
Console.WriteLine("Please enter the folder file path:");
51-
fileService.FolderPath = Console.ReadLine() ?? "";
52-
if (string.IsNullOrWhiteSpace(fileService.FolderPath))
53-
{
54-
Console.WriteLine("Incorrect input. please try again!\n");
55-
}
56-
else
57-
isValid = true;
58-
}
59-
while (!isValid);
60-
fileService.ReadAllFiles();
61-
}
62-
63-
void ReadFilesFromCurrentPath(FileService fileService)
64-
{
65-
Console.Clear();
66-
fileService.ReadAllFiles();
67-
}
68-
69-
void OutputFilesToAnotherPath()
70-
{
71-
bool isValid = false;
72-
Console.Clear();
73-
do
74-
{
75-
Console.WriteLine("Where would you like to output the result?");
76-
Console.Write("Path: ");
77-
fileService.OutputPath = Console.ReadLine() ?? "";
78-
if (string.IsNullOrWhiteSpace(fileService.OutputPath))
79-
{
80-
Console.WriteLine("Incorrect input. please try again!\n");
81-
}
82-
else
83-
isValid = true;
84-
}
85-
while (!isValid);
86-
}
87-
88-
async Task WriteFilesToAnotherPath(FileService fileService)
89-
{
90-
await fileService.WriteOutputToJson();
91-
}
92-
async Task WriteFilesToLocalPath(FileService fileService)
93-
{
94-
fileService.CreateNewDirectory();
95-
await fileService.WriteOutputToJson();
96-
}
9710

9811

9912

0 commit comments

Comments
 (0)