-
Notifications
You must be signed in to change notification settings - Fork 0
/
GacScriptTests.cs
170 lines (151 loc) · 5.17 KB
/
GacScriptTests.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//css_inc GACHelper.cs;
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.Diagnostics;
using System.Reflection;
using System.Collections;
//Microsoft.CLRAdmin.Fusion
//http://www.dotnet247.com/247reference/a.aspx?u=http://blogs.msdn.com/junfeng/archive/2004/09/14/229653.aspx
//http://www.codeproject.com/KB/dotnet/undocumentedfusion.aspx
//http://www.codeguru.com/columns/kate/article.php/c12793/
//http://blogs.msdn.com/junfeng/articles/229649.aspx
//http://www.google.com.au/#hl=en&source=hp&q=Fusion+Wrapper+GAC&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=b694f344a6ac6cb7
//http://dotnetkicks.com/linq/Linq_to_Gac_Use_Linq_to_Power_Query_your_Gac_via_C_to_Fusion
class Script
{
[STAThread]
static public void Main(string[] args)
{
Action<Action> profile = (action) =>
{
var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 100; i++)
{
action();
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
};
profile(() => TestWithFusion("System.Core"));
profile(() => TestWithExternalCompiler("System.Core.dll"));
profile(() => TestWithInProcCompiler("System.Core.dll"));
profile(() => TestWithGacUtil("System.Core"));
Console.ReadKey();
}
static void TestWithFusion(string asm)
{
var e = new csscript.AssemblyEnum(asm);
var name = e.GetNextAssembly();
var file = csscript.AssemblyCache.QueryAssemblyInfo(name);
}
static void TestWithInProcCompiler(string asm)
{
IDictionary<string, string> providerOptions = new Dictionary<string, string>();
providerOptions["CompilerVersion"] = "3.5";
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.ReferencedAssemblies.Add(asm);
ICodeCompiler compiler = CodeDomProvider.CreateProvider("C#").CreateCompiler();
var result = compiler.CompileAssemblyFromSource(compilerParams, "");
var erorr = result.Errors[0];
}
static bool TestWithExternalCompiler(string asm)
{
string compiler = Environment.ExpandEnvironmentVariables(@"%windir%\Microsoft.NET\Framework\v3.5\csc.exe");
string args = @"/nologo ""/out:asm.dll /t:library ""G:\cs-script\engine\Build\asm.cs"" /r:System.dll /r:"+asm;
var p = new Process();
p.StartInfo.FileName = compiler;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
int code = p.ExitCode;
return code == 0;
}
static bool TestWithGacUtil(string asm)
{
string compiler = @"D:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe";
string args = "/nologo /l "+asm;
var p = new Process();
p.StartInfo.FileName = compiler;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
int code = p.ExitCode;
return code == 0;
}
static bool ProcessStart(string app, string args)
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = app;
myProcess.StartInfo.Arguments = args;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
string line = null;
while (null != (line = myProcess.StandardOutput.ReadLine()))
{
Console.WriteLine(line);
}
myProcess.WaitForExit();
int code = myProcess.ExitCode;
return code == 0;
}
}
public class Fusion
{
public enum CacheType
{
Zap = 0x1,
GAC = 0x2,
Download = 0x4
}
static Type FusionType;
static Fusion()
{
Assembly a = Assembly.Load("mscorcfg, "
+ "Version=1.0.5000.0, "
+ "Culture=neutral, "
+ "PublicKeyToken=b03f5f7f11d50a3a");
FusionType = a.GetType("Microsoft.CLRAdmin.Fusion");
}
public static String GetCacheTypeString(UInt32 nFlag)
{
object[] args = new object[] { nFlag };
BindingFlags bindingFlags = (BindingFlags)314;
return ((String)
(FusionType.InvokeMember("GetCacheTypeString",
bindingFlags,
null,
null,
args)));
}
public static void ReadCache(ArrayList alAssems, UInt32 nFlag)
{
object[] args = new object[] { alAssems, nFlag };
BindingFlags bindingFlags = (BindingFlags)314;
FusionType.InvokeMember("ReadCache",
bindingFlags,
null,
null,
args);
}
public static StringCollection GetKnownFusionApps()
{
object[] args = new object[0];
BindingFlags bindingFlags = (BindingFlags)314;
return ((StringCollection)
(FusionType.InvokeMember("GetKnownFusionApps",
bindingFlags,
null,
null,
args)));
}
}