Example #1
0
        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();
            }
        }
Example #2
0
        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();
            }
        }
Example #3
0
        private static void 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 = PlatformServices.Default.Application;
            var runtimeEnvironment = PlatformServices.Default.Runtime;
            var loadContextAccessor = PlatformServices.Default.AssemblyLoadContextAccessor;
            var compilationEngine = new CompilationEngine(new CompilationEngineContext(applicationEnvironment, runtimeEnvironment, loadContextAccessor.Default, new CompilationCache()));
            var frameworkResolver = new FrameworkReferenceResolver();

            var services = new ServiceProvider();
            services.Add(typeof(IApplicationEnvironment), PlatformServices.Default.Application);
            services.Add(typeof(IRuntimeEnvironment), PlatformServices.Default.Runtime);
            services.Add(typeof(IAssemblyLoadContextAccessor), PlatformServices.Default.AssemblyLoadContextAccessor);
            services.Add(typeof(IAssemblyLoaderContainer), PlatformServices.Default.AssemblyLoaderContainer);
            services.Add(typeof(ILibraryManager), PlatformServices.Default.LibraryManager);

            // 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 = listenSocket.Accept();

                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();
            }
        }
Example #4
0
        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();
            }
        }