Permalink
Browse files

New DotWeb.Debugger works great, all tests are passing once again, pr…

…eparing to merge with mater soon
  • Loading branch information...
1 parent fd6326c commit 25bf8d794157c76ccb25a6dff12afaa7ee7f0f86 Frank Laub committed Jun 27, 2010
@@ -53,7 +53,6 @@
</Compile>
<Compile Include="CallContextStorage.cs" />
<Compile Include="DefaultFactory.cs" />
- <Compile Include="HostingServer.cs" />
<Compile Include="JsDynamicWrapper.cs" />
<Compile Include="IJsWrapper.cs" />
<Compile Include="IObjectFactory.cs" />
@@ -1,125 +0,0 @@
-// Copyright 2009, Frank Laub
-//
-// This file is part of DotWeb.
-//
-// DotWeb is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// DotWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with DotWeb. If not, see <http://www.gnu.org/licenses/>.
-
-using System.Net.Sockets;
-using System.Net;
-using System.IO;
-using DotWeb.Utility;
-using System;
-using System.Diagnostics;
-using DotWeb.Hosting.Weaver;
-using System.Threading;
-
-namespace DotWeb.Hosting.Bridge
-{
- public interface IHostingServer
- {
- string PrepareType(string binPath, AssemblyQualifiedTypeName aqtn);
-
- IPEndPoint EndPoint { get; }
-
- void Start();
- void Stop();
- }
-
- public static class HostingServerFactory
- {
- public static IHostingServer CreateHostingServer() {
- return new HostingServer();
- }
- }
-
- class HostingServer : IHostingServer
- {
- TcpListener listener;
-
- public HostingServer() {
- this.listener = new TcpListener(IPAddress.Loopback, 0);
- }
-
- public IPEndPoint EndPoint { get { return (IPEndPoint)this.listener.LocalEndpoint; } }
-
- public string PrepareType(string binPath, AssemblyQualifiedTypeName aqtn) {
- var weaver = new SimpleWeaver(binPath, binPath, new string[] { binPath }, false);
- string path = Path.Combine(binPath, aqtn.AssemblyName.Name);
- if (!path.EndsWith(".dll")) {
- path += ".dll";
- }
-
- var asm = weaver.ProcessAssembly(path);
- var asmName = asm.GetName();
- aqtn.AssemblyName.Name = asmName.Name;
- return aqtn.ToString();
- }
-
- public void Stop() {
- this.listener.Stop();
- }
-
- public void Start() {
- }
-
- private void OnAccept(IAsyncResult ar) {
- var listener = (TcpListener)ar.AsyncState;
- var client = listener.EndAcceptTcpClient(ar);
-
- RunInAppDomain(client);
- }
-
- private void RunInAppDomain(TcpClient client) {
- var curDomain = AppDomain.CurrentDomain;
- var setup = curDomain.SetupInformation;
-
- var appDomain = AppDomain.CreateDomain("DotWeb Hosting Environment", null, setup);
- var type = typeof(IsolatedContext);
- var context = (IsolatedContext)appDomain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
-
- try {
- context.Run(client.GetStream());
- }
- finally {
- client.Close();
- this.listener.Stop();
- AppDomain.Unload(appDomain);
- }
- }
-
- /// <summary>
- /// This allows static variables to be reset on each new request.
- /// It also serves as a good way to isolate each request from each other.
- /// </summary>
- class IsolatedContext : MarshalByRefObject
- {
- public void Run(NetworkStream stream) {
- HostedMode.Host = new CallContextStorage();
- try {
- var session = new RemoteSession(stream, stream);
- var factory = new DefaultFactory();
- var bridge = new JsBridge(session, factory);
- HostedMode.Host = bridge;
- bridge.DispatchForever();
- }
- catch (Exception ex) {
- Debug.WriteLine(ex);
- }
- finally {
- stream.Close();
- }
- }
- }
- }
-}
@@ -20,7 +20,9 @@
using System.Linq;
using System.Reflection;
using System.Diagnostics;
+using System.IO;
using DotWeb.Utility;
+using DotWeb.Hosting.Weaver;
namespace DotWeb.Hosting.Bridge
{
@@ -31,8 +33,6 @@ namespace DotWeb.Hosting.Bridge
using ReferenceToObjectMap = Dictionary<int, object>;
using JsObjectToReferenceMap = Dictionary<object, int>;
- using System.IO;
- using DotWeb.Hosting.Weaver;
public class JsBridge : IDotWebHost
{
@@ -148,13 +148,21 @@ public class JsBridge : IDotWebHost
var typeName = parts[0].Trim();
var asmName = parts[1].Trim();
var binPath = parts[2].Trim();
- var weaver = new SimpleWeaver(binPath, binPath, new string[] { binPath }, false);
var asmPath = Path.Combine(binPath, asmName);
if (!asmPath.EndsWith(".dll")) {
asmPath += ".dll";
}
- var asm = weaver.ProcessAssembly(asmPath);
+
+ Assembly asm;
+ if (asmName.StartsWith("Hosted-")) {
+ // for testing
+ asm = Assembly.LoadFrom(asmPath);
+ }
+ else {
+ var weaver = new SimpleWeaver(binPath, binPath, new string[] { binPath }, false);
+ asm = weaver.ProcessAssembly(asmPath);
+ }
return asm.GetType(typeName);
}
@@ -1,143 +0,0 @@
-// Copyright 2009, Frank Laub
-//
-// This file is part of DotWeb.
-//
-// DotWeb is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// DotWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with DotWeb. If not, see <http://www.gnu.org/licenses/>.
-//
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Mono.Cecil;
-using System.Reflection;
-using System.Reflection.Emit;
-using Mono.Cecil.Cil;
-using System.IO;
-using DotWeb.Utility;
-using System.Diagnostics;
-using DotWeb.Hosting;
-
-namespace DotWeb.Hosting.Weaver
-{
- public class AssemblyProcessor : IAssembly
- {
- private IResolver resolver;
- private AssemblyDefinition asmDef;
- private ModuleDefinition moduleDef;
- private AssemblyBuilder asmBuilder;
- private ModuleBuilder moduleBuilder;
- private string fileName;
-
- private Dictionary<string, IType> typesByDef = new Dictionary<string, IType>();
-
- public const string HostedPrefix = "Hosted-";
-
- public Assembly Assembly { get { return this.asmBuilder; } }
-
- public AssemblyProcessor(IResolver resolver, AssemblyDefinition asmDef, string outputDir) {
- this.resolver = resolver;
- this.asmDef = asmDef;
- this.moduleDef = asmDef.MainModule;
- this.moduleDef.LoadSymbols();
-
- var name = asmDef.Name.Name;
- if (!name.StartsWith(HostedPrefix))
- name = HostedPrefix + name;
-
- this.fileName = name + ".dll";
- var asmName = new AssemblyName(name);
-
- this.asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave, outputDir);
- this.moduleBuilder = asmBuilder.DefineDynamicModule(name, this.fileName, true);
- }
-
- public Assembly ProcessModule() {
- foreach (TypeDefinition typeDef in this.moduleDef.Types) {
- if (typeDef.Name == Constants.ModuleType)
- continue;
-
- if (typeDef.Name.StartsWith("__StaticArrayInitTypeSize="))
- continue;
-
- IType item;
- if (!this.typesByDef.TryGetValue(typeDef.FullName, out item)) {
- item = ProcessType(typeDef);
- }
-
- item.Process();
- }
-
- foreach (var item in this.typesByDef.Values) {
- item.Close();
- }
-
- if (this.asmDef.HasCustomAttributes) {
- CustomAttributeProcessor.Process(this.resolver, this.asmDef, this.asmBuilder, null);
- }
-
- var type = typeof(AssemblyWeavedAttribute);
- var ctor = type.GetConstructor(Type.EmptyTypes);
- this.asmBuilder.SetCustomAttribute(new CustomAttributeBuilder(ctor, new object[0]));
-
- this.asmBuilder.Save(this.fileName);
-
- return this.asmBuilder;
- }
-
- private string GetTypeKey(TypeReference typeRef) {
- // TypeDefinition reports:
- // DotWeb.System.Collections.Generic.IEnumerable`1
- // TypeReference reports:
- // DotWeb.System.Collections.Generic.IEnumerable`1<T>
- // Proposal:
- // Resolve() all TypeReferences to TypeDefinitions to get a consistent key
-
- // NOTE: the above approach breaks resolution of array types (and GenericInstanceTypes)
- // because Resolve() removes the fact that the typeRef is an array.
- if (typeRef is TypeSpecification) {
- return typeRef.FullName;
- }
-
- return typeRef.Resolve().FullName;
- }
-
- public IType ResolveTypeReference(TypeReference typeRef, IGenericScope genericScope) {
- IType type;
- string key = GetTypeKey(typeRef);
- if (!this.typesByDef.TryGetValue(key, out type)) {
- type = ProcessType(typeRef);
- }
-
- return type;
- }
-
- private IType ProcessType(TypeReference typeRef) {
- var typeDef = typeRef.Resolve();
- TypeBuilder outerBuilder = null;
- if (typeDef.IsNested) {
- var outerProc = this.resolver.ResolveTypeReference(typeDef.DeclaringType, null);
- outerBuilder = (TypeBuilder)outerProc.Type;
- }
-
- var typeProc = new TypeProcessor(this.resolver, this, typeDef, this.moduleBuilder, outerBuilder);
- RegisterType(typeRef, typeProc);
- return typeProc;
- }
-
- private void RegisterType(TypeReference typeRef, IType type) {
- string key = GetTypeKey(typeRef);
- this.typesByDef.Add(key, type);
- }
- }
-}
Oops, something went wrong.

0 comments on commit 25bf8d7

Please sign in to comment.