-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
149 lines (113 loc) · 4.1 KB
/
Program.cs
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Reflection;
using System.Linq;
using PreDefinedRegex;
using Contracts;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Collections.Concurrent;
using RegexConsoleTester.Utils;
using System.Text.RegularExpressions;
using RegexConsoleTester.ConsoleHelper;
namespace RegexConsoleTester
{
public class Program
{
public static ConcurrentDictionary<int, string> CommandClassList { get; set; }
public static int Main(String[] args)
{
//Farklı karakterlerde çıktı basabilmek için.
Console.OutputEncoding = System.Text.Encoding.UTF8;
//Get ReferanceTypeRegexs
CommandClassList = Helper.GetRefranceTypeCommands();
try
{
ProcessArgs(new string[] { "--help" });
int exitCode = 0;
while (exitCode == 0)
{
var values = Console.ReadLine();
if (values != null && !string.IsNullOrEmpty(values))
{
exitCode = ProcessArgs(new string[] { values });
}
}
return exitCode;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
return 1;
}
}
internal static int ProcessArgs(string[] args)
{
var command = string.Empty;
var lastArg = 0;
for (; lastArg < args.Length; lastArg++)
{
var cmdClassKeyValueItem = IsReferanceTypeCmd(args[lastArg]);
if (cmdClassKeyValueItem.Value != null)
{
string className = (cmdClassKeyValueItem.Value);
Type type = Type.GetType("PreDefinedRegex." + className);
//Create RegexCommand Class object to Run desired package regex.
Activator.CreateInstance(type);
return 0; //Repeat
}
else
{
var isPrmtv = IsPrimitiveCmd(args[lastArg]);
switch (args[lastArg])
{
case "exit":
case "-ext":
case "--exit":
Environment.Exit(0);
break;
case "cls":
case "-cls":
case "--clear":
Console.Clear();
break;
case "-h":
case "--help":
Console.Clear();
Helper.PrintHelp(CommandClassList);
break;
default:
Helper.NotValidArgument();
break;
}
return 0;
}
}
return -1;
}
#region ProcessArgs Fnc
public static KeyValuePair<int, string> IsReferanceTypeCmd(string gArg)
{
KeyValuePair<int, string> cmdClassKeyValueItem;
bool isInt = Regex.IsMatch(gArg, RegexCodes.Integer);
if (isInt)
{
//entered value is ineger
cmdClassKeyValueItem = CommandClassList.Where(x => x.Key == Convert.ToInt32(gArg)).FirstOrDefault();
}
else
{
//entered valur is string
gArg = gArg.Replace("-", "");
cmdClassKeyValueItem = CommandClassList.Where(x => x.Value == gArg).FirstOrDefault();
}
return cmdClassKeyValueItem;
}
public static bool IsPrimitiveCmd(string gArg)
{
return gArg.Length > 0 && gArg.Contains("--");
}
#endregion
}
}