-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program-scored.txt
106 lines (100 loc) · 4.19 KB
/
Program-scored.txt
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
using System;
using System.Threading.Tasks;
using System.Text;
using MySqlConnector;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.IO;
namespace labfiles
{
class Program
{
static async Task Main(string[] args)
{
int i;
if ((args.Length < 2) || (!int.TryParse(args[0], out i)) || (!int.TryParse(args[1], out i)) || (int.Parse(args[0]) < 1) || (int.Parse(args[0]) > 5) || (int.Parse(args[1]) < 1) || (int.Parse(args[1]) > 10))
{
Console.WriteLine(@"To run this console application enter the following:
dotnet run <challenge #> <Test #>
Where <challenge #> is:
1 = File
2 = MySQL
3 = MongoDB
4 = Advanced
5 = Expert
and <Test #> is between 1 and 10.");
}
else
{
var showDisplay = true;
foreach (string arg in args)
{
if (arg.ToLower() == "silent") showDisplay = false;
}
switch (int.Parse(args[0]))
{
case 1: //File
break;
case 2: //MySQL
break;
case 3:
break;
case 4: //advanced
if (showDisplay)
{
switch (int.Parse(args[1]))
{
case 1: //Connect and modify relational data
await TestRelational.RunTest(0, showDisplay);
await TestRelational.RunTest(1, showDisplay);
await TestRelational.RunTest(2, showDisplay);
await TestRelational.RunTest(3, showDisplay);
break;
case 2: //Export relational data
await TestRelational.RunTest(4, showDisplay);
await TestRelational.RunTest(5, showDisplay);
break;
case 3: //Exception handling
TestMongo.RunTest(0, showDisplay);
TestMongo.RunTest(1, showDisplay);
break;
case 4: //Exception handling
TestReport.RunTest(0, showDisplay);
TestReport.RunTest(1, showDisplay);
break;
}
}
else
{
var resultCode = -1;
int test = int.Parse(args[1]);
var console = Console.Out;
Console.SetOut(new StreamWriter(File.OpenWrite(Path.GetTempFileName())));
if (test <= 6)
{
resultCode = await TestRelational.RunTest(test - 1, false);
} else if (test <=8) {
resultCode = TestMongo.RunTest(test-7,false);
} else if (test <= 10) {
resultCode = TestReport.RunTest(test-9,false);
}
Console.SetOut(console);
Console.WriteLine(resultCode);
}
break;
}
}
}
internal static string SaveResults(string name, object data)
{
var fileName = $"results.{name}.json";
var output = JsonSerializer.Serialize(data, options: new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(fileName, output);
return $"You can view the results in the file {fileName}.";
}
}
}