-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
118 lines (110 loc) · 4.17 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
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace PlannerExAndImport
{
// This gets parameters and allows the user to select what he wants to do
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Planner Ex- and Import (" + Assembly.GetExecutingAssembly().GetName().Version + ")");
// expects 2 arguments (tenant and client id) and tries to falls back to env variables
if (args.Length != 2)
{
if (Environment.GetEnvironmentVariable("PEaI_TENANT") != null
&& Environment.GetEnvironmentVariable("PEaI_CLIENT_ID") != null)
{
Planner.TENANT = Environment.GetEnvironmentVariable("PEaI_TENANT");
Planner.CLIENT_ID = Environment.GetEnvironmentVariable("PEaI_CLIENT_ID");
}
else
{
Help();
Console.ReadLine();
Environment.Exit(1);
}
}
else
{
Planner.TENANT = args[0];
Planner.CLIENT_ID = args[1];
}
// select the action and call appropriate methods
try
{
while (true)
{
Console.WriteLine("");
Console.WriteLine("Select action by entering the letter:");
Console.WriteLine("E) export plan(s) to JSON");
Console.WriteLine("C) export plan(s) to CSV");
Console.WriteLine("I) export and then import plan");
Console.WriteLine("D) duplicate a bucket in a plan");
Console.WriteLine("F) forget stored credentials");
Console.WriteLine("H) help");
Console.WriteLine("X) exit");
string selected = GetInput().ToLower();
switch (selected)
{
case "e":
Planner.Export(true, true);
break;
case "c":
Planner.ExportToCSV();
break;
case "i":
Planner.Import();
break;
case "d":
Planner.DuplicateBucket();
break;
case "f":
Planner.ForgetCredentials();
break;
case "h":
Help();
break;
case "x":
Environment.Exit(0);
break;
default:
Console.WriteLine("Invalid entry. Please enter e, i, f, h or x");
break;
}
}
}
catch (Exception ex)
{
PrintError(ex);
}
}
private static void Help()
{
Console.WriteLine("PlannerExAndImport.exe <tenant id> <client id>, e.g. PlannerExAndImport.exe yourtenant.com 0d0c56f0-1444-412a-94a5-c8df7e54958c");
}
public static string GetInput(string message = null)
{
if (message != null)
Console.Write(message);
return Console.ReadLine();
}
public static void PrintError(Exception exc)
{
ConsoleColor before = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Something went wrong.");
Console.WriteLine("Message: " + exc.Message + "\n");
Console.ForegroundColor = before;
Console.ReadLine();
}
}
}