-
Notifications
You must be signed in to change notification settings - Fork 1
/
DumpCompilerError.cs
68 lines (59 loc) · 3.12 KB
/
DumpCompilerError.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
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using LINQPad;
using System.Linq;
namespace Aerospike.Database.LINQPadDriver
{
internal static class DumpCompilerError
{
const string stdHeader = @"
<Query Kind=""Program"">
<NuGetReference>Aerospike.Client</NuGetReference>
<Reference Relative=""..\..\AppData\Local\LINQPad\Drivers\DataContext\NetCore\Aerospike.Database.LINQPadDriver\Aerospike.Database.LINQPadDriver.dll""><LocalApplicationData>\LINQPad\Drivers\DataContext\NetCore\Aerospike.Database.LINQPadDriver\Aerospike.Database.LINQPadDriver.dll</Reference>
<Namespace>Aerospike.Client</Namespace>
<Namespace>Aerospike.Database.LINQPadDriver</Namespace>
<Namespace>Aerospike.Database.LINQPadDriver.Extensions</Namespace>
</Query>
";
public static string GetFrameWorkInfo()
{
return System.Reflection.Assembly.GetEntryAssembly()
.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), true)
?.Cast<System.Runtime.Versioning.TargetFrameworkAttribute>()
.FirstOrDefault()
?.FrameworkName
?? System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
}
public static void ToLinqPadFile(string sourceCode, string[] errors)
{
var fileBuilder = new StringBuilder(stdHeader);
var fixedSourceCode = sourceCode.Replace("using ", "//using ");
fileBuilder.AppendLine();
{
fileBuilder.AppendLine("// Platform Information:");
fileBuilder.AppendLine(string.Format("//\t\t{0}",
System.Runtime.InteropServices.RuntimeInformation.OSDescription));
fileBuilder.AppendLine(string.Format("//\t\t{0}",
GetFrameWorkInfo()));
var lqDriver = typeof(Aerospike.Database.LINQPadDriver.AerospikeConnection).Assembly.GetName();
fileBuilder.AppendLine(string.Format("//\t\tLinqPad Driver: {0} Version: {1}",
lqDriver?.Name,
lqDriver?.Version));
var asyncClient = typeof(Aerospike.Client.Connection).Assembly.GetName();
fileBuilder.AppendLine(string.Format("//\t\tAerospike Driver: {0} Version: {1}",
asyncClient?.Name,
asyncClient?.Version));
}
foreach (var error in errors)
{
fileBuilder.AppendLine("// " + error);
}
fileBuilder.AppendLine();
fileBuilder.AppendLine(fixedSourceCode);
var name = errors.Length == 0 ? "Debug" : "Errors";
File.WriteAllText(Path.Combine(LINQPad.Util.MyQueriesFolder, $"Aerospike.LINQPadDriver {name} {DateTime.Now.ToString("yyMMddHHmmss")}.linq"), fileBuilder.ToString());
}
}
}