コード例 #1
0
 public static INativeProxy GetProxy(INativeTracer nativeTracer)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(new NativeImportsWin32(nativeTracer));
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         return(new NativeImportsLinux(nativeTracer));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
コード例 #2
0
        public NativeConnection(string dllPath, INativeTracer nativeTracer)
        {
            _nativeProxy = NativeProxyFactory.GetProxy(nativeTracer);
            if (!string.IsNullOrWhiteSpace(dllPath) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                lock (Win32PathsAlreadyAdded)
                {
                    if (!Win32PathsAlreadyAdded.Contains(dllPath))
                    {
                        var p = Environment.GetEnvironmentVariable("PATH");
                        Environment.SetEnvironmentVariable("PATH", p + ";" + dllPath, EnvironmentVariableTarget.Process);
                        Win32PathsAlreadyAdded.Add(dllPath);
                    }
                }
            }

            if (IntPtr.Size == sizeof(int))
            {
                throw new Exception("32Bit process is not supported");
            }

            if (!_mysqlServerInitCalled)
            {
                int rv = _nativeProxy.mysql_server_init(0, IntPtr.Zero, IntPtr.Zero);
                if (rv != 0)
                {
                    throw new MySqlException("Could not initialize MySQL client library");
                }
                _mysqlServerInitCalled = true;
            }

            MySql = _nativeProxy.mysql_init(IntPtr.Zero);
            if (MySql == null)
            {
                throw new MySqlException("mysql_init failed");
            }

            IntPtr vers = mysql_get_client_info();

            if (vers == null)
            {
                throw new MySqlException("mysql_get_client_info failed");
            }
            ClientVersion = Marshal.PtrToStringAnsi(vers);
        }
コード例 #3
0
 public static void SetDefaultNativeTracer(INativeTracer nativeTracer)
 {
     _defaultNativeTracer = nativeTracer;
 }
コード例 #4
0
 public void SetNativeTracer(INativeTracer nativeTracer)
 {
     _currentNativeTracer = nativeTracer;
 }
コード例 #5
0
 internal NativeImportsLinux(INativeTracer nativeTracer)
 {
     _nativeTracer = nativeTracer;
 }
コード例 #6
0
 internal NativeImportsWin32(INativeTracer nativeTracer)
 {
     _nativeTracer = nativeTracer;
 }
コード例 #7
0
 internal NativeImportsTemplate(INativeTracer nativeTracer)
 {
     _nativeTracer = nativeTracer;
 }