-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaunchModes.cs
162 lines (149 loc) · 7.23 KB
/
LaunchModes.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
using Spectre.Console;
namespace RSNiniManager
{
static class LaunchModes
{
static public void ChangeCurrent(List<string> RevitServesFolders, string autodeskDataFolder, string fullBackupFolderPath)
{
Dictionary<string, List<ServerObject>> RevitsAndServers = new Dictionary<string, List<ServerObject>>();
Dictionary<string, List<string>> NewRevitsAndServers = new Dictionary<string, List<string>>();
foreach (var autodeskFolder in RevitServesFolders)
{
RevitsAndServers.Add(autodeskFolder.Replace(autodeskDataFolder, ""), Utils.GetServersFromini(autodeskFolder, true));
}
Utils.GetServersFromBackup(RevitServesFolders, autodeskDataFolder, fullBackupFolderPath, ref RevitsAndServers);
AnsiConsole.Markup($"[bold {Colors.mainColor}]ChangeCurrent mode[/]");
//List<string> revitServFolder = new List<string>();
Console.WriteLine("\n");
var selectionPrompt = new MultiSelectionPrompt<string>();
selectionPrompt.Title($"[underline {Colors.mainColor}] Select revit servers to activate[/]")
.HighlightStyle(Colors.selectionStyle)
.NotRequired()
.Mode(SelectionMode.Leaf)
.WrapAround(true)
.PageSize(20)
.MoreChoicesText($"[{Colors.infoColor}](Move up and down to reveal more servers)[/]")
.InstructionsText(
$"[{Colors.infoColor}](Press [{Colors.selectionColor}]<space>[/] to toggle servers, " +
$"[{Colors.mainColor}]<enter>[/] to accept)[/]"
);
foreach (KeyValuePair<string, List<ServerObject>> item in RevitsAndServers)
{
List<string> serversName = new List<string>();
item.Value.ForEach(serv => serversName.Add(serv.Server));
selectionPrompt.AddChoiceGroup(item.Key, serversName);
foreach (ServerObject server in item.Value)
{
if (server.IsMarked)
{
selectionPrompt.Select(server.Server);
}
}
}
List<string> selectedRevitServers = AnsiConsole.Prompt(selectionPrompt);
foreach (string server in selectedRevitServers)
{
var RevitName = selectionPrompt.GetParent(server);
if (NewRevitsAndServers.ContainsKey(RevitName))
{
NewRevitsAndServers[RevitName].Add(server);
}
else
{
NewRevitsAndServers[RevitName] = new List<string>() { server };
}
}
foreach (KeyValuePair<string, List<ServerObject>> item in RevitsAndServers)
{
string RevitIniFolerPath = autodeskDataFolder + item.Key;
if (NewRevitsAndServers.ContainsKey(item.Key))
{
Utils.SetServersIni(RevitIniFolerPath, NewRevitsAndServers[item.Key]);
}
else
{
Utils.SetServersIni(RevitIniFolerPath, new List<string>());
}
}
}
static public void AddNewServers(List<string> RevitServesFolders)
{
AnsiConsole.Markup($"[bold {Colors.mainColor}]AddNewServers mode[/]");
Console.WriteLine("\n");
string autodeskfolder = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title($"[underline {Colors.mainColor}]Select Revit to add new revitServer[/]\n")
.HighlightStyle(Colors.selectionStyle)
.PageSize(10)
.AddChoices(RevitServesFolders)
);
List<string> currentServers = Utils.GetServersFromini(autodeskfolder);
AnsiConsole.Markup($"[{Colors.infoColor}]current servers of:[/] {autodeskfolder}\n");
currentServers.ForEach(s => AnsiConsole.Markup($" {s}\n"));
Console.WriteLine("\n");
AnsiConsole.Markup($"[{Colors.infoColor}]Promt new server name and press [{Colors.mainColor}]<enter>[/][/]" +
$"[{Colors.infoColor}] or press [{Colors.attentionColor}]<esc>[/] to finish adding[/]\n");
while (true)
{
//ConsoleKeyInfo cki = Console.ReadKey();
//if (cki.Key == ConsoleKey.Escape)
//{
// break;
//}
//string newServer = Console.ReadLine();
//newServer = cki.KeyChar + newServer;
string newServer = Utils.ReadLineOrEsc();
if (string.IsNullOrEmpty(newServer))
{
break;
}
else
{
currentServers.Add(newServer);
AnsiConsole.Markup($"server addet: [{Colors.selectionColor}]{newServer}[/]\n");
}
}
Console.WriteLine("\n");
AnsiConsole.Markup($"[{Colors.mainColor}]Addition completed[/]\n");
Utils.SetServersIni(autodeskfolder, currentServers);
}
static public void RemoveServers(List<string> RevitServesFolders, string autodeskDataFolder, string fullBackupFolderPath)
{
AnsiConsole.Markup($"[bold {Colors.mainColor}]RemoveServers mode[/]");
Console.WriteLine("\n");
AnsiConsole.Markup($"[{Colors.infoColor}](remove from revit and also from buckup be careful)[/]");
Console.WriteLine("\n");
string autodeskfolder = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title($"[underline {Colors.mainColor}]Select Revit to remove revitServer[/]\n")
.HighlightStyle(Colors.selectionStyle)
.PageSize(10)
.AddChoices(RevitServesFolders)
);
List<string> currentServers = Utils.GetServersFromini(autodeskfolder);
string finishRemove = "<finish remove>";
currentServers.Add(finishRemove);
string backupFolder = autodeskfolder.Replace(autodeskDataFolder, fullBackupFolderPath);
List<string> backupServers = Utils.GetServersFromini(backupFolder);
while (true)
{
string serverToRemove = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title($"[underline {Colors.mainColor}]Select Server to remove[/]\n")
.HighlightStyle(Colors.selectionStyle)
.PageSize(10)
.AddChoices(currentServers)
);
if (serverToRemove == finishRemove)
{
currentServers.Remove(finishRemove);
break;
}
currentServers.Remove(serverToRemove);
backupServers.Remove(serverToRemove);
}
Utils.SetServersIni(autodeskfolder, currentServers);
Utils.SetServersIni(backupFolder, backupServers);
}
}
}