Base: Add Performance class for calling ngen
This commit is contained in:
parent
28e70226e5
commit
410cae21ea
@ -75,7 +75,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseClass.vb" />
|
||||
<Compile Include="ECM.vb" />
|
||||
<Compile Include="ECM\ECM.vb" />
|
||||
<Compile Include="IDB\Attributes.vb" />
|
||||
<Compile Include="IDB\Database.vb" />
|
||||
<Compile Include="IDB\FileStore.vb" />
|
||||
@ -95,6 +95,7 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Performance.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
|
||||
44
Base/Performance.vb
Normal file
44
Base/Performance.vb
Normal file
@ -0,0 +1,44 @@
|
||||
Imports System.IO
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports System.Security.Cryptography
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class Performance
|
||||
Public Sub New(pLogConfig As LogConfig, pAppDataPath As String)
|
||||
Dim savedHash = String.Empty
|
||||
Dim assemblyLocation = Assembly.GetEntryAssembly().Location
|
||||
|
||||
Dim hashPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "hash.txt")
|
||||
If Not File.Exists(hashPath) Then
|
||||
File.Create(hashPath)
|
||||
Else
|
||||
savedHash = File.ReadAllText(hashPath)
|
||||
End If
|
||||
|
||||
Dim hash = String.Concat(SHA1.Create().ComputeHash(File.ReadAllBytes(assemblyLocation)).Select(Function(x) x.ToString("x2")))
|
||||
If hash.Equals(savedHash) Then
|
||||
Return
|
||||
End If
|
||||
|
||||
Dim dotNetRuntimePath = RuntimeEnvironment.GetRuntimeDirectory()
|
||||
Dim ngenPath = Path.Combine(dotNetRuntimePath, "ngen.exe")
|
||||
|
||||
Dim process = New Process With {
|
||||
.StartInfo = New ProcessStartInfo With {
|
||||
.FileName = ngenPath,
|
||||
.Arguments = $"install ""{assemblyLocation}"" /nologo",
|
||||
.CreateNoWindow = True,
|
||||
.UseShellExecute = True,
|
||||
.Verb = "runas"
|
||||
}
|
||||
}
|
||||
Try
|
||||
process.Start()
|
||||
process.WaitForExit()
|
||||
File.WriteAllText(hashPath, hash)
|
||||
Catch
|
||||
' ...
|
||||
End Try
|
||||
End Sub
|
||||
End Class
|
||||
Loading…
x
Reference in New Issue
Block a user