-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
316 lines (235 loc) · 11.8 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using CommandLine;
using System.Text.RegularExpressions;
using ShellProgressBar;
using System.Diagnostics;
using System.IO;
using Microsoft.Extensions.Configuration;
using PureCloudPlatform.Client.V2.Model;
namespace CallFlowVisualizer
{
internal class Program
{
static void Main(string[] args)
{
bool convertToVisio = false;
bool convertToPng = false;
bool disableAcceleration=false;
int maxSecondDescriptionLengh = 50;
List<string> flowTypeList = new();
try
{
var configRoot = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: "appsettings.json").Build();
convertToVisio = configRoot.GetSection("drawioSettings").Get<DrawioSettings>().ConvertToVisio;
convertToPng = configRoot.GetSection("drawioSettings").Get<DrawioSettings>().ConvertToPng;
disableAcceleration = configRoot.GetSection("drawioSettings").Get<DrawioSettings>().DisableAcceleration;
maxSecondDescriptionLengh = configRoot.GetSection("cfvSettings").Get<CfvSettings>().MaxSecondDescriptionLengh;
flowTypeList = configRoot.GetSection("cfvSettings").Get<CfvSettings>().flowTypeList;
}
catch (Exception)
{
ColorConsole.WriteError($"The configuration file 'appsettings.json' was not found in this directory.");
PrintUsage();
}
if(maxSecondDescriptionLengh<=0 || maxSecondDescriptionLengh >= 1025)
{
ColorConsole.WriteError($"maxSecondDescriptionLength should be from 1 to 1024.");
PrintUsage();
}
var parseResult = Parser.Default.ParseArguments<Options>(args);
Options opt = new();
string mode = "";
FileInfo[] fileInfo = null;
List<string> jsonFiles = null;
switch (parseResult.Tag)
{
case ParserResultType.Parsed:
var parsed = parseResult as Parsed<Options>;
opt = parsed.Value;
if (convertToVisio) opt.visio = true;
if (convertToPng) opt.png = true;
if (opt.Filename != null && opt.flowId != null)
{
ColorConsole.WriteError("Incorrect command line argument.");
PrintUsage();
}
// [ADD] 2023/06/29
if (opt.Filename != null && opt.flowName != null)
{
ColorConsole.WriteError("Enclose flow name in double quotation marks.");
PrintUsage();
}
if (opt.drawio || opt.visio || opt.png)
{
Process[] processes = Process.GetProcessesByName("draw.io");
if (processes.Length > 0)
{
ColorConsole.WriteError($"draw.io is running. Close draw.io first.");
Environment.Exit(1);
}
}
if (opt.Filename != null)
{
if (!File.Exists(opt.Filename))
{
ColorConsole.WriteError($"{opt.Filename} does not exist. Check if the file exists.");
PrintUsage();
}
if (Path.GetExtension(opt.Filename) == ".json")
{
mode = "GenesysCloud";
break;
}
if (Path.GetExtension(opt.Filename) == ".xml")
{
mode = "PureConnect";
break;
}
}
if ((opt.flowId != null || opt.flowName != null) && args != null)
{
Regex regEx = new Regex(@"(^([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$)");
if(opt.flowName != null && opt.flowId != null)
{
ColorConsole.WriteError($"Set either Architect's flow ID or flow Name.");
PrintUsage();
}
IEnumerable<string> notContained = opt.flowType.Except(flowTypeList);
// [ADD] 2023/06/29
if (opt.flowType != null && notContained.Any())
{
var notContainedValue = String.Join(",",notContained.ToArray());
ColorConsole.WriteError($"Incorrect flow type [{notContainedValue}].");
PrintUsage();
}
if ((opt.flowId!=null && regEx.Match(opt.flowId).Success) || opt.flowId == "all" || opt.flowName!=null)
{
mode = "FetchFromGenesysCloud";
break;
}
else
{
ColorConsole.WriteError($"Argument is not a GUID format. {opt.flowId} Set Architect's flow ID.");
PrintUsage();
}
}
if (opt.architect)
{
mode = "architect";
try
{
DirectoryInfo di = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "Architect"));
fileInfo = di.GetFiles("*.json", SearchOption.AllDirectories);
if (fileInfo.Length == 0)
{
ColorConsole.WriteError($"No json files were found in Architect folder. Run fetch command first.");
PrintUsage();
}
else
{
jsonFiles = fileInfo.Select(x => x.FullName).ToList();
}
}
catch (Exception)
{
ColorConsole.WriteError($"No Architect folder.Run fetch command first.");
PrintUsage();
}
break;
}
PrintUsage();
break;
case ParserResultType.NotParsed:
PrintUsage();
break;
}
ColorConsole.WriteLine($"Mode : {mode} started.", ConsoleColor.Yellow);
List<string> csvFileResultList = new List<string>();
List<string> jsonFileListPD = new();
switch (mode)
{
case "PureConnect":
List<PureConnectFlowElements> flowElementsList = CollectDSValuesFromXML.CollectDS(opt.Filename);
ColorConsole.WriteLine("Creating CSV file for PureConnect", ConsoleColor.Yellow);
csvFileResultList = CreateCSV.CreateCSVPureConnect(flowElementsList);
Console.WriteLine();
break;
case "GenesysCloud":
List<string> jsonFileList = new() { opt.Filename };
csvFileResultList = GcJSONtoCSV.gcJsonToCSV(jsonFileList, opt);
jsonFileListPD = jsonFileList;
break;
case "FetchFromGenesysCloud":
FetchGCAccessToken.GetAccessToken(opt.profile);
// [ADD] 2023/06/29
if (opt.flowId != null)
{
jsonFileList = FetchFlows.CreateArchitectJSONFile(opt.flowId,opt.flowType);
}
else
{
jsonFileList = FetchFlows.CreateArchitectJSONFileWithName(opt.flowName, opt.flowType);
}
csvFileResultList = GcJSONtoCSV.gcJsonToCSV(jsonFileList, opt);
jsonFileListPD = jsonFileList;
Console.WriteLine();
break;
case "architect":
csvFileResultList = GcJSONtoCSV.gcJsonToCSV(jsonFiles, opt);
jsonFileListPD = jsonFiles;
break;
default:
PrintUsage();
break;
}
if (opt.drawio || opt.visio || opt.png)
{
DrawFlow.DrawFlowFromCSV(csvFileResultList, opt.visio, opt.png, disableAcceleration);
}
if(opt.createParticipantDataList)
{
GcJSONtoCSV.gcJsonToPDListCSV(jsonFileListPD);
}
Console.WriteLine();
ColorConsole.WriteLine("Completed!", ConsoleColor.Yellow);
Environment.Exit(0);
}
private static void PrintUsage()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("Usage:");
sb.AppendLine(" CallFlowVisualizer.exe <DSEDIT XML File> | <Architect JSON File>");
sb.AppendLine(" CallFlowVisualizer.exe -f <flowId> | <all>");
sb.AppendLine();
sb.AppendLine("Options:");
sb.AppendLine(@" -d --drawio Call .\drawio\draw.io.exe for CallFlowVisualizer after creating CSV files.");
sb.AppendLine(@" -f --fetch Fetch latest Architect flow of specified flowID from GenesysCloud and Create CSV files for drawio.");
sb.AppendLine(@" -n --name Fetch latest Architect flow of specified flowName from GenesysCloud and Create CSV files for drawio.");
sb.AppendLine(@" -t --type Fetch latest Architect flow of specified flowType from GenesysCloud and Create CSV files for drawio.");
sb.AppendLine(@" bot,commonmodule,digitalbot,inboundcall,inboundchat,inboundemail,inboundshortmessage,outboundcall");
sb.AppendLine(@" inqueuecall,inqueueemail,inqueueshortmessage,speech,securecall,surveyinvite,voice,voicemail,workflow,workitem");
sb.AppendLine(@" -a --architect Create CSV files for json files in .\Architect folder.");
sb.AppendLine(@" -p --profile [PROFILE NAME] Change GenesysCloud organization.Use [default] if not specified.");
sb.AppendLine(@" -v --visio Convert to visio file after creating drawio files");
sb.AppendLine(@" -g --png Convert to png file after creating drawio files");
sb.AppendLine(@" -l --list Create Participant Data CSV list");
sb.AppendLine(@" --help Show this screen.");
sb.AppendLine(@" --version Show version.");
sb.AppendLine(@" --debug Show node id of architect on diagram.");
sb.AppendLine();
sb.AppendLine("Examples:");
sb.AppendLine(" CallFlowVisualizer.exe PCSampleFlow.xml");
sb.AppendLine(" CallFlowVisualizer.exe GCSampleFlow.json -d");
sb.AppendLine(" CallFlowVisualizer.exe -f all");
sb.AppendLine(" CallFlowVisualizer.exe -f 3a3d264a-978e-4a1d-abc9-e1f76c556f1a -v -p prod-org");
sb.AppendLine(" CallFlowVisualizer.exe -n MarketingDev -t call -v -p prod-org");
sb.AppendLine();
Console.Out.Write(sb.ToString());
Environment.Exit(1);
}
}
}