Skip to content

Commit 5b31d40

Browse files
committed
code cleanup
1 parent 4715377 commit 5b31d40

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

Ellabit/DynamicCode/SimpleUnloadableAssemblyLoadContext.cs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,54 @@ public class SimpleUnloadableAssemblyLoadContext : AssemblyLoadContext, IDisposa
2020
HttpClient? client;
2121
public SimpleUnloadableAssemblyLoadContext(HttpClient httpClient)
2222
: base(isCollectible: true)
23-
{
24-
client = httpClient;
23+
{
24+
client = httpClient;
25+
Stream stream;
26+
StreamReader reader;
27+
bool flowControl = LoadFrameworkManifest(out stream, out reader);
28+
if (!flowControl)
29+
{
30+
return;
31+
}
32+
}
2533

34+
private bool LoadFrameworkManifest(out Stream stream, out StreamReader reader)
35+
{
2636
var asm = Assembly.GetExecutingAssembly();
27-
using var stream = asm.GetManifestResourceStream("Ellabit.framework_manifest.json");
28-
using var reader = new StreamReader(stream!);
37+
stream = asm.GetManifestResourceStream("Ellabit.framework_manifest.json")!;
38+
reader = new StreamReader(stream!);
2939
var json = reader.ReadToEnd();
30-
if (string.IsNullOrEmpty(json))
31-
{
32-
System.Console.WriteLine("framework_manifest.json is empty");
33-
return;
40+
if (string.IsNullOrEmpty(json))
41+
{
42+
Console.WriteLine("framework_manifest.json is empty");
43+
return false;
3444
}
35-
Console.WriteLine($"60x50: {json.Substring(60, 50)}");
36-
if (!json.StartsWith("["))
37-
{
38-
Console.WriteLine("Missing [ ");
39-
json = "[" + json.ReplaceLineEndings("").Replace("}", "},").TrimEnd(',') + "]"; //Add missing , between each array element, but for last one remove last comma
40-
}
41-
Console.WriteLine($"CONTENTS: {json}");
45+
46+
if (!json.StartsWith("["))
47+
{
48+
Console.WriteLine("Missing [ ");
49+
json = "[" + json.ReplaceLineEndings("").Replace("}", "},").TrimEnd(',') + "]"; //Add missing , between each array element, but for last one remove last comma
50+
}
51+
Console.WriteLine($"CONTENTS: {json}");
4252

4353
var frameworkAssemblyJson = JArray.Parse(json);
4454
foreach (JObject child in frameworkAssemblyJson)
4555
{
46-
string name = child["Name"]!.ToString();
47-
int lastDot = name.LastIndexOf('.');
48-
name = lastDot > 0 ? name.Substring(0, lastDot) : name;
56+
string name = child["Name"]!.ToString();
57+
int lastDot = name.LastIndexOf('.');
58+
name = lastDot > 0 ? name.Substring(0, lastDot) : name;
4959

50-
string file = child["File"]!.ToString();
51-
lastDot = file.LastIndexOf('.');
52-
file = lastDot > 0 ? file.Substring(0, lastDot) : file;
60+
string file = child["File"]!.ToString();
61+
lastDot = file.LastIndexOf('.');
62+
file = lastDot > 0 ? file.Substring(0, lastDot) : file;
5363

5464
References.Add(name, file);
55-
}
65+
}
66+
67+
return true;
5668
}
57-
public IChallenge? Challenge { get; set; }
69+
70+
public IChallenge? Challenge { get; set; }
5871
public Dictionary<string, string> References { get; set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
5972

6073
public void Dispose()

0 commit comments

Comments
 (0)