Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allowing the debugger to run inside of the asp.net process

  • Loading branch information...
commit 490a322b3731b86dadbcb53a4f6287971e968db0 1 parent 7719fc4
@flaub authored
View
58 src/DotWeb.Debugger/Program.cs
@@ -1,70 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Net.Sockets;
-using System.Net;
-using DotWeb.Hosting;
using DotWeb.Hosting.Bridge;
-using System.Diagnostics;
-using System.Threading;
namespace DotWeb.Debugger
{
class Program
{
static void Main(string[] args) {
- new Program().Start();
- }
-
- public void Start() {
- var listener = new TcpListener(IPAddress.Loopback, 0x1337);
- listener.Start();
- while (true) {
- var client = listener.AcceptTcpClient();
- ThreadPool.QueueUserWorkItem((state) => 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();
- 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();
- }
- }
+ new HostingServer().Start();
}
}
}
View
3  src/DotWeb.Hosting.Bridge/DotWeb.Hosting.Bridge.csproj
@@ -46,12 +46,15 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="CallContextStorage.cs" />
+ <Compile Include="HostingServer.cs" />
<Compile Include="DefaultFactory.cs" />
<Compile Include="JsDynamicWrapper.cs" />
<Compile Include="IJsWrapper.cs" />
View
86 src/DotWeb.Hosting.Bridge/HostingServer.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Net.Sockets;
+using System.Diagnostics;
+using System.Net;
+using System.Threading;
+
+namespace DotWeb.Hosting.Bridge
+{
+ public class HostingServer
+ {
+ private TcpListener listener;
+
+ public IPEndPoint EndPoint { get { return (IPEndPoint)this.listener.LocalEndpoint; } }
+
+ public HostingServer()
+ : this(0) {
+ }
+
+ public HostingServer(int port) {
+ this.listener = new TcpListener(IPAddress.Loopback, port);
+ }
+
+ public void Start() {
+ this.listener.Start();
+ while (true) {
+ var client = this.listener.AcceptTcpClient();
+ ThreadPool.QueueUserWorkItem((state) => RunInAppDomain(client));
+ }
+ }
+
+ public void AsyncStart() {
+ this.listener.Start();
+ this.listener.BeginAcceptTcpClient(this.OnAccept, null);
+ }
+
+ private void OnAccept(IAsyncResult ar) {
+ var client = this.listener.EndAcceptTcpClient(ar);
+ this.listener.BeginAcceptTcpClient(this.OnAccept, null);
+ 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();
+ 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();
+ }
+ }
+ }
+ }
+}
View
5 src/DotWeb.Web/ClientCodeRenderer.cs
@@ -144,11 +144,14 @@ public class ClientCodeRenderer
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
writer.RenderBeginTag(HtmlTextWriterTag.Script);
+ var server = new HostingServer();
+ server.AsyncStart();
+
writer.WriteLine(Resources.JsHelper);
var url = context.RequestUrl;
var binPath = context.MapPath("/bin").Replace("\\", "\\\\");
var typeSpec = HttpUtility.HtmlEncode(string.Format("{0}, {1}", Source, binPath));
- string js = string.Format(Resources.HostedEntry, url.Host, 0x1337, typeSpec);
+ string js = string.Format(Resources.HostedEntry, url.Host, server.EndPoint.Port, typeSpec);
writer.WriteLine(js);
writer.RenderEndTag();
Please sign in to comment.
Something went wrong with that request. Please try again.