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