-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
84 lines (73 loc) · 2.61 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Scenario3
{
class Program
{
static async Task Main(string[] args)
{
string inputFile = FindFullPath("input.json");
string outputFile = FindFullPath("output.json");
Account account;
using (FileStream fs = File.OpenRead(inputFile))
{
account = await Deserialize(fs);
}
using (FileStream fs = File.Create(outputFile))
{
await Serialize(account, fs);
}
Console.WriteLine("Press any key to continue ...");
Console.ReadLine();
}
// TODO:
// 1) Deserialize the json string from the file, asynchronously, into an "account" object and return it.
// Note: Feel free to open input.json to view its contents, but do NOT modify it.
private static async Task<Account> Deserialize(Stream fileStream)
{
// <Add/modify code here>
return null;
}
// TODO:
// 2) Asynchronously serialize the entire "account" object we deserialized in (1) to a new file but omit any null values.
// Note: Write the JSON indented.
private static async Task Serialize(Account account, Stream fileStream)
{
// <Add code here>
}
private static string FindFullPath(string fileName)
{
string dir = Directory.GetCurrentDirectory();
string fullPath = dir + "\\" + fileName;
int count = 0;
while (true)
{
if (count > 5)
{
throw new FileNotFoundException($"The file necessary for this scenario could not be found. Looking for {fileName}.");
}
if (File.Exists(fullPath))
{
break;
}
if (dir.EndsWith("Scenario3\\"))
{
throw new FileNotFoundException($"The file necessary for this scenario could not be found (stopped searching at project root). Looking for {fileName}.");
}
dir = Path.GetFullPath(Path.Combine(dir, @"..\"));
fullPath = dir + "\\" + fileName;
count++;
}
return fullPath;
}
}
public class Account
{
public string Email { get; set; }
public bool Active { get; set; }
public DateTime CreatedDate { get; set; }
public IList<string> Roles { get; set; }
}
}