mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-20 15:42:35 +08:00
fd10fe7ccb
This eliminates the dual solutions and brings Contrib into the project.json fold. - Tests are ported to xUnit though SQLite is disabled on DNX due to Issue #375 (Interop loads fail in the VS runner and params are busted regardless). - Projects are consolidated down to what's currently possible with project.json. - Contrib moved to: Dapper.Contrib and Dapper.Tests.Contrib (so tests appear at the end, no other reason vs. Dapper.Contrib.Tests) - EF moved to: Dapper.EntityFramework(.StrongName) - Rainbow moved to: Dapper.Rainbow - SqlBuilder moved to: Dapper.SqlBuilder - Packages are removed since it's not current-tooling friendly to keep them (nor was it using them). - xUnit implemented in Contrib via abstracts - this allow us to very quickly add any database provider to the rig in a very concise way. - Contrib unit tests fixed in various places - they were not parallel-runner friendly - Nuspecs removed, since they aren't used anymore (to eliminate confusion) - Removed speed tests for libraries that aren't on current versions of .Net (what would we be comparing?) - Perf tests moved to Dapper.Tests (consolidation from Dapper.DNX.Tests), but aren't activated yet (no define)
57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace SqlServerTypes
|
|
{
|
|
/// <summary>
|
|
/// Utility methods related to CLR Types for SQL Server
|
|
/// </summary>
|
|
internal class Utilities
|
|
{
|
|
private static object _nativeLoadLock = new object();
|
|
private static bool _nativeAssembliesLoaded = false;
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
private static extern IntPtr LoadLibrary(string libname);
|
|
|
|
/// <summary>
|
|
/// Loads the required native assemblies for the current architecture (x86 or x64)
|
|
/// </summary>
|
|
/// <param name="rootApplicationPath">
|
|
/// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
|
|
/// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
|
|
/// </param>
|
|
public static void LoadNativeAssemblies(string rootApplicationPath)
|
|
{
|
|
if (_nativeAssembliesLoaded)
|
|
return;
|
|
lock (_nativeLoadLock)
|
|
{
|
|
if (!_nativeAssembliesLoaded)
|
|
{
|
|
var nativeBinaryPath = IntPtr.Size > 4
|
|
? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
|
|
: Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");
|
|
|
|
LoadNativeAssembly(nativeBinaryPath, "msvcr100.dll");
|
|
LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial110.dll");
|
|
_nativeAssembliesLoaded = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
|
|
{
|
|
var path = Path.Combine(nativeBinaryPath, assemblyName);
|
|
var ptr = LoadLibrary(path);
|
|
if (ptr == IntPtr.Zero)
|
|
{
|
|
throw new Exception(string.Format(
|
|
"Error loading {0} (ErrorCode: {1})",
|
|
assemblyName,
|
|
Marshal.GetLastWin32Error()));
|
|
}
|
|
}
|
|
}
|
|
} |