-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGcJSONtoCSV.cs
185 lines (131 loc) · 6.35 KB
/
GcJSONtoCSV.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
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using ShellProgressBar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Configuration;
using NLog;
namespace CallFlowVisualizer
{
class GcJSONtoCSV
{
/// <summary>
/// Load GenesysCloud JSON file and create CSV file
/// </summary>
/// <param name="filePathList"></param>
internal static List<string> gcJsonToCSV(List<string> filePathList, Options opt)
{
var configRoot = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: "appsettings.json").Build();
bool appendGcFlowTypeToFileName = configRoot.GetSection("cfvSettings").Get<CfvSettings>().AppendGcFlowTypeToFileName;
bool appendGcOrgNameToFileName = configRoot.GetSection("cfvSettings").Get<CfvSettings>().AppendGcOrgNameToFileName;
bool createFlowPerReusabletask = configRoot.GetSection("cfvSettings").Get<CfvSettings>().CreateFlowPerReusabletask;
bool createPagePerReusabletask = configRoot.GetSection("cfvSettings").Get<CfvSettings>().CreatePagePerReusabletask;
// v1.5.0
bool showExpression = configRoot.GetSection("cfvSettings").Get<CfvSettings>().ShowExpression;
bool showPromptDetail = configRoot.GetSection("cfvSettings").Get<CfvSettings>().ShowPromptDetail;
List<string> csvFileResultList = new();
Console.WriteLine();
ColorConsole.WriteLine("Creating CSV file for GenesysCloud", ConsoleColor.Yellow);
var pboptions = new ProgressBarOptions
{
ProgressCharacter = '─',
ProgressBarOnBottom = true
};
var csvpb = new ProgressBar(filePathList.Count(), "Creating CSV file", pboptions);
foreach (var jsonFilePath_i in filePathList)
{
List<GenesysCloudFlowNode> flowNodesList = CollectGCValuesFromJSON.CollectNode(jsonFilePath_i);
if(showPromptDetail)
{
flowNodesList = FetchAudioPrompt.FetchPromptDescription(flowNodesList,opt);
}
var json = File.ReadAllText(jsonFilePath_i);
JObject result;
using (var sr = new StreamReader(jsonFilePath_i, Encoding.UTF8))
{
var jsonData = sr.ReadToEnd();
result = (JObject)JsonConvert.DeserializeObject(jsonData);
}
string flowName = result["name"].ToString().Replace(" ", "_").Replace("&","and");
if (appendGcFlowTypeToFileName)
{
flowName = "(" + result["type"].ToString() + ")_" + flowName;
}
if (appendGcOrgNameToFileName)
{
string fileName = Path.GetFileNameWithoutExtension(jsonFilePath_i);
string orgName = null;
Regex regOrg = new Regex(@"^(\[.+\]).+");
Match matchOrg = regOrg.Match(fileName);
if (matchOrg.Success)
{
GroupCollection group = matchOrg.Groups;
orgName = group[1].Value;
}
flowName =orgName + flowName;
}
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}))");
string flowId = regEx.Match(jsonFilePath_i).Value;
csvpb.Tick(flowName);
foreach (char c in Path.GetInvalidFileNameChars())
{
flowName = flowName.Replace(c, '_');
}
// [ADD-1]2023/03/25
if (createFlowPerReusabletask)
{
var flowNodeListGrouped = flowNodesList.GroupBy(x=>x.FlowGroup).ToList();
foreach (var flowNodeListGrouped_i in flowNodeListGrouped)
{
string flowGroupName = flowNodeListGrouped_i.Key;
foreach (char c in Path.GetInvalidFileNameChars())
{
flowGroupName = flowGroupName.Replace(c, '_');
}
flowGroupName = flowGroupName.Replace(' ', '_');
List<GenesysCloudFlowNode> flowNodesListPerTask = new();
flowNodesListPerTask = flowNodeListGrouped_i.ToList();
csvFileResultList.Add(CreateCSV.CreateCSVGenCloud(flowNodesListPerTask, flowName, flowId, opt.debug, flowGroupName));
}
}
else if (createPagePerReusabletask) //[ADD] 2023/03/31
{
csvFileResultList.Add(CreateCSV.CreateCSVGenCloudPerPage(flowNodesList, flowName, flowId, opt.debug, null));
}else
{
csvFileResultList.Add(CreateCSV.CreateCSVGenCloud(flowNodesList, flowName, flowId, opt.debug,null));
}
}
Console.WriteLine();
return csvFileResultList;
}
internal static void gcJsonToPDListCSV(List<string> filePathList)
{
Console.WriteLine();
ColorConsole.WriteLine("Creating Participant Data List of Architect flow", ConsoleColor.Yellow);
var pboptions = new ProgressBarOptions
{
ProgressCharacter = '─',
ProgressBarOnBottom = true
};
var csvpb = new ProgressBar(filePathList.Count(), "Creating Participant Data List CSV file", pboptions);
List<GenesysCloudParticipantData> gcPDList = new();
foreach (var jsonFilePath_i in filePathList)
{
var pdResult = CollectGCParticipantData.CollectParticipantData(jsonFilePath_i);
if(pdResult != null)
{
gcPDList.AddRange(pdResult);
}
csvpb.Tick(jsonFilePath_i);
Console.WriteLine();
}
CreateCSV.CreatePDListCSVGenCloud(gcPDList);
Console.WriteLine();
}
}
}