private async Task OpenChannel(int port, string hostId) { var contexts = new Dictionary <int, ApplicationContext>(); var protocolManager = new ProtocolManager(maxVersion: 3); // REVIEW: Should these be on a shared context object that flows? var applicationEnvironment = (IApplicationEnvironment)_services.GetService(typeof(IApplicationEnvironment)); var runtimeEnvironment = (IRuntimeEnvironment)_services.GetService(typeof(IRuntimeEnvironment)); var loadContextAccessor = (IAssemblyLoadContextAccessor)_services.GetService(typeof(IAssemblyLoadContextAccessor)); var compilationEngine = new CompilationEngine(new CompilationEngineContext(applicationEnvironment, runtimeEnvironment, loadContextAccessor.Default, new CompilationCache())); var frameworkResolver = new FrameworkReferenceResolver(); // This fixes the mono incompatibility but ties it to ipv4 connections var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port)); listenSocket.Listen(10); Console.WriteLine($"Process ID {Process.GetCurrentProcess().Id}"); Console.WriteLine("Listening on port {0}", port); while (true) { var acceptSocket = await AcceptAsync(listenSocket); Console.WriteLine("Client accepted {0}", acceptSocket.LocalEndPoint); var stream = new NetworkStream(acceptSocket); var queue = new ProcessingQueue(stream); var connection = new ConnectionContext( contexts, _services, applicationEnvironment, runtimeEnvironment, loadContextAccessor, frameworkResolver, queue, protocolManager, compilationEngine, hostId); queue.OnReceive += message => { // Enumerates all project contexts and return them to the // sender if (message.MessageType == "EnumerateProjectContexts") { WriteProjectContexts(message, queue, contexts); } else { // Otherwise it's a context specific message connection.OnReceive(message); } }; queue.Start(); } }
private static void WriteProjectContexts(Message message, ProcessingQueue queue, IDictionary <int, ApplicationContext> contexts) { try { var projectContexts = contexts.Values.Select(p => new { Id = p.Id, ProjectPath = p.ApplicationPath }) .ToList(); var versionToken = message.Payload.HasValues ? message.Payload?["Version"] : null; var version = versionToken != null?versionToken.Value <int>() : 0; queue.Send(writer => { if (version == 0) { writer.Write("ProjectContexts"); writer.Write(projectContexts.Count); for (int i = 0; i < projectContexts.Count; i++) { writer.Write(projectContexts[i].ProjectPath); writer.Write(projectContexts[i].Id); } } else { var obj = new JObject(); obj["MessageType"] = "ProjectContexts"; var projects = new JObject(); obj["Projects"] = projects; foreach (var pair in projectContexts) { projects[pair.ProjectPath] = pair.Id; } writer.Write(obj.ToString(Formatting.None)); } }); } catch (Exception ex) { var error = new JObject(); error["Message"] = ex.Message; queue.Send(new Message { MessageType = "Error", Payload = error }); throw; } }
private async Task OpenChannel(int port, string hostId) { var contexts = new Dictionary<int, ApplicationContext>(); var protocolManager = new ProtocolManager(maxVersion: 2); // REVIEW: Should these be on a shared context object that flows? var applicationEnvironment = (IApplicationEnvironment)_services.GetService(typeof(IApplicationEnvironment)); var loadContextAccessor = (IAssemblyLoadContextAccessor)_services.GetService(typeof(IAssemblyLoadContextAccessor)); var compilationEngine = new CompilationEngine(new CompilationEngineContext(applicationEnvironment, loadContextAccessor.Default, new CompilationCache())); var frameworkResolver = new FrameworkReferenceResolver(); // This fixes the mono incompatibility but ties it to ipv4 connections var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port)); listenSocket.Listen(10); Console.WriteLine($"Process ID {Process.GetCurrentProcess().Id}"); Console.WriteLine("Listening on port {0}", port); for (; ;) { var acceptSocket = await AcceptAsync(listenSocket); Console.WriteLine("Client accepted {0}", acceptSocket.LocalEndPoint); var stream = new NetworkStream(acceptSocket); var queue = new ProcessingQueue(stream); var connection = new ConnectionContext( contexts, _services, applicationEnvironment, loadContextAccessor, frameworkResolver, queue, protocolManager, compilationEngine, hostId); queue.OnReceive += message => { // Enumerates all project contexts and return them to the // sender if (message.MessageType == "EnumerateProjectContexts") { WriteProjectContexts(message, queue, contexts); } else { // Otherwise it's a context specific message connection.OnReceive(message); } }; queue.Start(); } }
public ConnectionContext(IDictionary <int, ApplicationContext> contexts, IServiceProvider services, ProcessingQueue queue, ProtocolManager protocolManager, string hostId) { _contexts = contexts; _services = services; _queue = queue; _hostId = hostId; _protocolManager = protocolManager; _cache = new CompilationCache(); }
public ConnectionContext(IDictionary<int, ApplicationContext> contexts, IServiceProvider services, ProcessingQueue queue, ProtocolManager protocolManager, string hostId) { _contexts = contexts; _services = services; _queue = queue; _hostId = hostId; _protocolManager = protocolManager; _cache = new CompilationCache(); }
private async Task OpenChannel(int port, string hostId) { var contexts = new Dictionary <int, ApplicationContext>(); var services = new ServiceProvider(_services); var protocolManager = new ProtocolManager(maxVersion: 2); // This fixes the mono incompatibility but ties it to ipv4 connections var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port)); listenSocket.Listen(10); Console.WriteLine($"Process ID {Process.GetCurrentProcess().Id}"); Console.WriteLine("Listening on port {0}", port); for (; ;) { var acceptSocket = await AcceptAsync(listenSocket); Console.WriteLine("Client accepted {0}", acceptSocket.LocalEndPoint); var stream = new NetworkStream(acceptSocket); var queue = new ProcessingQueue(stream); var connection = new ConnectionContext( contexts, services, queue, protocolManager, hostId); queue.OnReceive += message => { // Enumerates all project contexts and return them to the // sender if (message.MessageType == "EnumerateProjectContexts") { WriteProjectContexts(message, queue, contexts); } else { // Otherwise it's a context specific message connection.OnReceive(message); } }; queue.Start(); } }
private async Task OpenChannel(int port, string hostId) { var contexts = new Dictionary<int, ApplicationContext>(); var services = new ServiceProvider(_services); var protocolManager = new ProtocolManager(maxVersion: 2); // This fixes the mono incompatibility but ties it to ipv4 connections var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port)); listenSocket.Listen(10); Console.WriteLine($"Process ID {Process.GetCurrentProcess().Id}"); Console.WriteLine("Listening on port {0}", port); for (; ;) { var acceptSocket = await AcceptAsync(listenSocket); Console.WriteLine("Client accepted {0}", acceptSocket.LocalEndPoint); var stream = new NetworkStream(acceptSocket); var queue = new ProcessingQueue(stream); var connection = new ConnectionContext( contexts, services, queue, protocolManager, hostId); queue.OnReceive += message => { // Enumerates all project contexts and return them to the // sender if (message.MessageType == "EnumerateProjectContexts") { WriteProjectContexts(message, queue, contexts); } else { // Otherwise it's a context specific message connection.OnReceive(message); } }; queue.Start(); } }
public ConnectionContext(IDictionary <int, ApplicationContext> contexts, IServiceProvider services, IApplicationEnvironment applicationEnvironment, IAssemblyLoadContextAccessor loadContextAccessor, FrameworkReferenceResolver frameworkResolver, ProcessingQueue queue, ProtocolManager protocolManager, CompilationEngine compilationEngine, string hostId) { _contexts = contexts; _services = services; _applicationEnvironment = applicationEnvironment; _loadContextAccessor = loadContextAccessor; _frameworkResolver = frameworkResolver; _queue = queue; _compilationEngine = compilationEngine; _protocolManager = protocolManager; _compilationEngine = compilationEngine; _hostId = hostId; }
public ConnectionContext(IDictionary<int, ApplicationContext> contexts, IServiceProvider services, IApplicationEnvironment applicationEnvironment, IAssemblyLoadContextAccessor loadContextAccessor, FrameworkReferenceResolver frameworkResolver, ProcessingQueue queue, ProtocolManager protocolManager, CompilationEngine compilationEngine, string hostId) { _contexts = contexts; _services = services; _applicationEnvironment = applicationEnvironment; _loadContextAccessor = loadContextAccessor; _frameworkResolver = frameworkResolver; _queue = queue; _compilationEngine = compilationEngine; _protocolManager = protocolManager; _compilationEngine = compilationEngine; _hostId = hostId; }
private static void WriteProjectContexts(Message message, ProcessingQueue queue, IDictionary<int, ApplicationContext> contexts) { try { var projectContexts = contexts.Values.Select(p => new { Id = p.Id, ProjectPath = p.ApplicationPath }) .ToList(); var versionToken = message.Payload.HasValues ? message.Payload?["Version"] : null; var version = versionToken != null ? versionToken.Value<int>() : 0; queue.Send(writer => { if (version == 0) { writer.Write("ProjectContexts"); writer.Write(projectContexts.Count); for (int i = 0; i < projectContexts.Count; i++) { writer.Write(projectContexts[i].ProjectPath); writer.Write(projectContexts[i].Id); } } else { var obj = new JObject(); obj["MessageType"] = "ProjectContexts"; var projects = new JObject(); obj["Projects"] = projects; foreach (var pair in projectContexts) { projects[pair.ProjectPath] = pair.Id; } writer.Write(obj.ToString(Formatting.None)); } }); } catch (Exception ex) { var error = new JObject(); error["Message"] = ex.Message; queue.Send(new Message { MessageType = "Error", Payload = error }); throw; } }