Skip to content

Commit 9cdd66a

Browse files
committed
Adding Managed Interface
1 parent 58da956 commit 9cdd66a

File tree

7 files changed

+292
-0
lines changed

7 files changed

+292
-0
lines changed

clr_host/resource.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//{{NO_DEPENDENCIES}}
2+
// Microsoft Visual C++ generated include file.
3+
// Used by ADMHost.rc
4+
//
5+
#define IDS_PROJNAME 100
6+
7+
// Next default values for new objects
8+
//
9+
#ifdef APSTUDIO_INVOKED
10+
#ifndef APSTUDIO_READONLY_SYMBOLS
11+
#define _APS_NEXT_RESOURCE_VALUE 201
12+
#define _APS_NEXT_COMMAND_VALUE 32768
13+
#define _APS_NEXT_CONTROL_VALUE 201
14+
#define _APS_NEXT_SYMED_VALUE 102
15+
#endif
16+
#endif
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace mysql_managed_interface
5+
{
6+
[ComVisible(true),
7+
Guid("0961af1d-ebb7-4f7d-ab4a-d4234b74caca"),
8+
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
9+
public interface IManagedHost
10+
{
11+
/// <summary>
12+
/// Create a new AppDomain
13+
/// </summary>
14+
/// <param name="name">name of the AppDomain to create</param>
15+
/// <returns>ID of the new AppDomain</returns>
16+
int CreateAppDomain([MarshalAs(UnmanagedType.BStr)]string name);
17+
18+
/// <summary>
19+
/// Clean up the AppDomianManager
20+
/// </summary>
21+
void Dispose();
22+
23+
/// <summary>
24+
/// Set the unmanaged host for the AppDomainManager to work with
25+
/// </summary>
26+
/// <param name="unmanagedHost">unmanaged half of the host</param>
27+
void SetUnmanagedHost(IUnmanagedHost unmanagedHost);
28+
29+
/// <summary>
30+
/// Write a message
31+
/// </summary>
32+
/// <param name="message">message to write</param>
33+
void Write([MarshalAs(UnmanagedType.BStr)]string message);
34+
35+
36+
/// <summary>
37+
/// Write a message
38+
/// </summary>
39+
/// <param name="message">message to write</param>
40+
///
41+
[return: MarshalAs(UnmanagedType.I8)]
42+
Int64 Run([MarshalAs(UnmanagedType.I8)]Int64 path);
43+
}
44+
45+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
5+
namespace mysql_managed_interface
6+
{
7+
[ComVisible(true),
8+
Guid("3659e1f4-5003-4d1b-9c37-d82325428f94"),
9+
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
10+
public interface IUnmanagedHost
11+
{
12+
/// <summary>
13+
/// Start the CLR
14+
/// </summary>
15+
void Start();
16+
17+
/// <summary>
18+
/// Stop the CLR
19+
/// </summary>
20+
void Stop();
21+
22+
/// <summary>
23+
/// Get the managed host of the default AppDomain
24+
/// </summary>
25+
IManagedHost DefaultManagedHost { get; }
26+
27+
/// <summary>
28+
/// Get the managed host for a specific AppDomain
29+
/// </summary>
30+
/// <param name="appDomain">AppDomain ID</param>
31+
IManagedHost GetManagedHost(int appDomain);
32+
}
33+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Reflection;
5+
using System.Security;
6+
using System.Security.Permissions;
7+
using System.Security.Policy;
8+
9+
namespace mysql_managed_interface
10+
{
11+
class MySQLHostManager: AppDomainManager, IManagedHost
12+
{
13+
14+
public static StrongName CreateStrongName(Assembly assembly)
15+
{
16+
if (assembly == null)
17+
throw new ArgumentNullException("assembly");
18+
19+
AssemblyName assemblyName = assembly.GetName();
20+
Debug.Assert(assemblyName != null, "Could not get assembly name");
21+
22+
// get the public key blob
23+
byte[] publicKey = assemblyName.GetPublicKey();
24+
if (publicKey == null || publicKey.Length == 0)
25+
throw new InvalidOperationException("Assembly is not strongly named");
26+
27+
StrongNamePublicKeyBlob keyBlob = new StrongNamePublicKeyBlob(publicKey);
28+
29+
// and create the StrongName
30+
return new StrongName(keyBlob, assemblyName.Name, assemblyName.Version);
31+
}
32+
33+
private IUnmanagedHost unmanagedInterface = null;
34+
35+
/// <summary>
36+
/// A new AppDomain has been created
37+
/// </summary>
38+
public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
39+
{
40+
// let the unmanaged host know about us
41+
InitializationFlags = AppDomainManagerInitializationOptions.RegisterWithHost;
42+
43+
return;
44+
}
45+
46+
public int CreateAppDomain(string name)
47+
{
48+
PermissionSet permissions = new PermissionSet(PermissionState.None);
49+
permissions.AddPermission(new SecurityPermission(PermissionState.Unrestricted));
50+
permissions.AddPermission(new UIPermission(PermissionState.Unrestricted));
51+
52+
return AppDomain.CreateDomain(
53+
name,
54+
AppDomain.CurrentDomain.Evidence,
55+
AppDomain.CurrentDomain.SetupInformation,
56+
permissions,
57+
CreateStrongName(Assembly.GetExecutingAssembly())).Id;
58+
}
59+
60+
public void Dispose()
61+
{
62+
return;
63+
}
64+
65+
public void SetUnmanagedHost(IUnmanagedHost unmanagedHost)
66+
{
67+
Debug.Assert(unmanagedHost != null, "Attempt to set null unmanaged host");
68+
Debug.Assert(this.unmanagedInterface == null, "Attempt to reset unmanaged host");
69+
70+
this.unmanagedInterface = unmanagedHost;
71+
return;
72+
}
73+
74+
public void Write(string message)
75+
{
76+
Trace.WriteLine(message);
77+
Console.WriteLine(message);
78+
return;
79+
}
80+
81+
public Int64 Run(Int64 path)
82+
{
83+
return (path * 3);
84+
//new FileIOPermission(PermissionState.Unrestricted).Assert();
85+
//string fullPath = Path.Combine(
86+
// Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
87+
// path);
88+
//CodeAccessPermission.RevertAssert();
89+
90+
//new FileIOPermission(
91+
// FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery,
92+
// fullPath).Assert();
93+
//AppDomain.CurrentDomain.ExecuteAssembly(fullPath);
94+
//CodeAccessPermission.RevertAssert();
95+
}
96+
}
97+
}
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("mysql_managed_interface")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("mysql_managed_interface")]
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("b734c08c-715f-4218-982a-3f51842e3b09")]
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")]
596 Bytes
Binary file not shown.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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>{A15DADAC-D3C8-4226-93CD-2DA7C85F51DC}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>mysql_managed_interface</RootNamespace>
11+
<AssemblyName>mysql_managed_interface</AssemblyName>
12+
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
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+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<PropertyGroup>
34+
<SignAssembly>true</SignAssembly>
35+
</PropertyGroup>
36+
<PropertyGroup>
37+
<AssemblyOriginatorKeyFile>generic_signing.snk</AssemblyOriginatorKeyFile>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="System" />
41+
<Reference Include="System.Core" />
42+
<Reference Include="System.Xml.Linq" />
43+
<Reference Include="System.Data.DataSetExtensions" />
44+
<Reference Include="Microsoft.CSharp" />
45+
<Reference Include="System.Data" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="IManagedHost.cs" />
50+
<Compile Include="IUnmanagedHost.cs" />
51+
<Compile Include="MySQLHostManager.cs" />
52+
<Compile Include="Properties\AssemblyInfo.cs" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<None Include="generic_signing.snk" />
56+
</ItemGroup>
57+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
58+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
59+
Other similar extension points exist, see Microsoft.Common.targets.
60+
<Target Name="BeforeBuild">
61+
</Target>
62+
<Target Name="AfterBuild">
63+
</Target>
64+
-->
65+
</Project>

0 commit comments

Comments
 (0)