Skip to content

Commit e9dc6de

Browse files
committed
Changed relating to post 7
1 parent 91e2238 commit e9dc6de

18 files changed

+540
-83
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,7 @@ install_manifest.txt
240240
Win32
241241
udf_example.dir
242242
RelWithDebInfo
243+
244+
# Custom Ignore for Windows Link
245+
# =========================
246+
/MySQLHostManager40/MySQLHostManager.cs

MySQLHostManager40/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MySQLHostManager.cs

MySQLHostManager40/MySQLHostManager40.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<DebugType>full</DebugType>
1818
<Optimize>false</Optimize>
1919
<OutputPath>bin\Debug\</OutputPath>
20-
<DefineConstants>DEBUG;TRACE</DefineConstants>
20+
<DefineConstants>TRACE;DEBUG;DOTNET40</DefineConstants>
2121
<ErrorReport>prompt</ErrorReport>
2222
<WarningLevel>4</WarningLevel>
2323
</PropertyGroup>
@@ -63,6 +63,9 @@
6363
<PostBuildEvent>"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe" /i $(TargetPath)
6464
</PostBuildEvent>
6565
</PropertyGroup>
66+
<PropertyGroup>
67+
<PreBuildEvent>IF EXIST MySQLHostManager.cs ( echo "Link Exists") ELSE (mklink MySQLHostManager.cs ..\mysql_managed_interface\MySQLHostManager.cs)</PreBuildEvent>
68+
</PropertyGroup>
6669
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6770
Other similar extension points exist, see Microsoft.Common.targets.
6871
<Target Name="BeforeBuild">
File renamed without changes.

MySQLTestHarness/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{5FA25495-E051-4950-BCCD-DD5A6751DCB1}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>MySQLTestHarness</RootNamespace>
11+
<AssemblyName>MySQLTestHarness</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="MySql.Data, Version=6.9.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" />
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Program.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="App.config" />
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
53+
Other similar extension points exist, see Microsoft.Common.targets.
54+
<Target Name="BeforeBuild">
55+
</Target>
56+
<Target Name="AfterBuild">
57+
</Target>
58+
-->
59+
</Project>

MySQLTestHarness/Program.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace MySQLTestHarness
8+
{
9+
10+
class Program
11+
{
12+
static object objLock = new object();
13+
static void Main(string[] args)
14+
{
15+
for (int i = 0; i < 1; i++)
16+
{
17+
18+
var tp = System.Threading.ThreadPool.QueueUserWorkItem(RunQueries);
19+
System.Threading.Thread.Sleep(10);
20+
}
21+
Console.ReadLine();
22+
23+
}
24+
25+
private static void RunQueries(object StateInfo)
26+
{
27+
for (int i = 0; i < 600; i++)
28+
{
29+
using (var conn = new MySql.Data.MySqlClient.MySqlConnection(@"Server=localhost;Database=employees;Uid=root"))
30+
//using (var comm = new MySql.Data.MySqlClient.MySqlCommand(@"SELECT (emp_no * 3.14) + 10, emp_no, first_name, last_name FROM employees", conn))
31+
using (var comm = new MySql.Data.MySqlClient.MySqlCommand(@"SELECT MYSQLDOTNET_INT('MySQLCustomClass.CustomMySQLClass', emp_no), emp_no, first_name, last_name FROM employees", conn))
32+
using (var dt = new System.Data.DataTable())
33+
{
34+
comm.CommandTimeout = 600;
35+
conn.Open();
36+
using (var da = new MySql.Data.MySqlClient.MySqlDataAdapter(comm))
37+
{
38+
var start = DateTime.Now;
39+
try
40+
{
41+
da.Fill(dt);
42+
}
43+
catch (Exception e)
44+
{
45+
46+
Console.WriteLine(e.Message);
47+
}
48+
var stop = DateTime.Now;
49+
lock (objLock)
50+
{
51+
Console.WriteLine("Retrieved {0} records in {1} milliseconds", dt.Rows.Count, (stop - start).TotalMilliseconds);
52+
}
53+
54+
}
55+
conn.Close();
56+
}
57+
}
58+
}
59+
}
60+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("MySQLTestHarness")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("MySQLTestHarness")]
13+
[assembly: AssemblyCopyright("Copyright © 2014")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("762a0894-4c93-4e37-bf30-99c305cebe5e")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

clr_host/ClrHost.cpp

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ CADMHostModule _AtlModule;
3131

3232
CClrHost::CClrHost() : m_started(false), m_pClrControl(NULL)
3333
{
34-
35-
3634
return;
3735
}
3836

@@ -41,13 +39,13 @@ CClrHost::CClrHost() : m_started(false), m_pClrControl(NULL)
4139
/// </summary>
4240
CClrHost::~CClrHost()
4341
{
44-
// free the AppDomainManagers
45-
for (AppDomainManagerMap::iterator iAdm = m_appDomainManagers.begin(); iAdm != m_appDomainManagers.end(); iAdm++)
46-
iAdm->second->Release();
42+
//// free the AppDomainManagers
43+
//for (AppDomainManagerMap::iterator iAdm = m_appDomainManagers.begin(); iAdm != m_appDomainManagers.end(); iAdm++)
44+
// iAdm->second->Release();
4745

48-
// release the CLR
49-
if (m_pClrControl != NULL)
50-
m_pClrControl->Release();
46+
//// release the CLR
47+
//if (m_pClrControl != NULL)
48+
// m_pClrControl->Release();
5149
return;
5250
}
5351

@@ -154,7 +152,6 @@ HRESULT CClrHost::FinalConstruct()
154152
// Enumeration example from COM books.
155153

156154
bool runtimesLoaded = false;
157-
//pMetaHost->EnumerateLoadedRuntimes(GetCurrentProcess(), &pRtEnum);
158155

159156
WCHAR strName[MAXSTRING];
160157
DWORD len = MAXSTRING;
@@ -164,6 +161,10 @@ HRESULT CClrHost::FinalConstruct()
164161

165162

166163
pMetaHost->EnumerateLoadedRuntimes(GetCurrentProcess(), &pRtEnum);
164+
if (pRtEnum == NULL)
165+
{
166+
return E_POINTER;
167+
}
167168
while ((hr = pRtEnum->Next(1, (IUnknown **)&info, &fetched)) == S_OK && fetched > 0)
168169
{
169170
// If the runtime is loaded in MySQL already, then we may not have control over it.
@@ -407,43 +408,38 @@ STDMETHODIMP CClrHost::raw_GetManagedHost(long appDomain, BSTR clr, IManagedHost
407408
}
408409
}
409410

410-
STDMETHODIMP CClrHost::raw_GetSpecificManagedHost(BSTR clr, IManagedHost **ppHost)
411-
{
412-
_ASSERTE(m_started);
413-
414-
if (ppHost == NULL)
415-
return E_POINTER;
416-
417-
// get the AppDomainManager for the specified domain
418-
auto iHost = m_NewlyCreatedAppDomains[clr];
419-
420-
// see if we've got a host
421-
if (iHost == NULL)
422-
{
423-
*ppHost = NULL;
424-
return E_NOMANAGEDHOST;
425-
}
426-
else
427-
{
428-
*ppHost = iHost;
429-
(*ppHost)->AddRef();
430-
return S_OK;
431-
}
432-
}
433411

434412

435413
// IHostGCManager
436414
STDMETHODIMP CClrHost::SuspensionEnding(DWORD generation){ return S_OK; }
437415
STDMETHODIMP CClrHost::SuspensionStarting(){ return S_OK; }
438416
STDMETHODIMP CClrHost::ThreadIsBlockingForSuspension(){ return S_OK; }
439417

440-
STDMETHODIMP CClrHost::raw_CreateAppDomainForQuery(BSTR FnName, BSTR *pRetVal)
418+
STDMETHODIMP CClrHost::raw_CreateAppDomainForQuery(BSTR FnName, IManagedHost **ppHost)
441419
{
442420
IManagedHostPtr pAppMgr = this->GetDefaultManagedHost();
443421
auto clrVersion = pAppMgr->GetAssemblyCLRVersion(FnName);
444422
auto domManager = this->m_appDomainManagers[std::wstring(clrVersion)];
445423
IManagedHostPtr pNewDomain = domManager->CreateAppDomain(FnName);
446-
*pRetVal = (BSTR)pNewDomain->GetAppDomainName;
447-
this->m_NewlyCreatedAppDomains[std::wstring(*pRetVal)] = pNewDomain;
424+
*ppHost = pNewDomain;
425+
(*ppHost)->AddRef();
426+
// Check to see if the appdmain stored in our default domain is one we have a ref to.
427+
return S_OK;
428+
}
429+
430+
STDMETHODIMP CClrHost::raw_UnloadAppDomain(IManagedHost * managedHost, VARIANT_BOOL * pRetVal)
431+
{
432+
try
433+
{
434+
auto appdomainName = managedHost->GetAppDomainName;
435+
auto appDomainCLR = managedHost->GetCLR();
436+
// We're good to access this map since we're not writing to it once we've bound the CLRs
437+
this->m_appDomainManagers[std::wstring(appDomainCLR)]->Unload(appdomainName);
438+
}
439+
catch (const _com_error &e)
440+
{
441+
// I'm alright with there being nothing here.
442+
}
448443
return S_OK;
449-
}
444+
445+
}

clr_host/ClrHost.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ATL_NO_VTABLE CClrHost : public CComObjectRootEx<CComSingleThreadModel>,
3838
std::wstring m_lastCLR;
3939

4040

41+
4142
public:
4243
CClrHost();
4344
~CClrHost();
@@ -61,8 +62,8 @@ class ATL_NO_VTABLE CClrHost : public CComObjectRootEx<CComSingleThreadModel>,
6162
STDMETHODIMP raw_Stop();
6263
STDMETHODIMP get_DefaultManagedHost(IManagedHost **ppHost);
6364
STDMETHODIMP raw_GetManagedHost(long appDomain, BSTR clr, IManagedHost **ppHost);
64-
STDMETHODIMP raw_GetSpecificManagedHost(BSTR clr, IManagedHost **ppHost);
65-
STDMETHODIMP raw_CreateAppDomainForQuery(BSTR FnName, BSTR * pRetVal);
65+
STDMETHODIMP raw_CreateAppDomainForQuery(BSTR FnName, IManagedHost **ppHost);
66+
STDMETHODIMP raw_UnloadAppDomain(IManagedHost * appdomainName, VARIANT_BOOL * pRetVal);
6667

6768
// IHostGCManager
6869
public:

0 commit comments

Comments
 (0)