예제 #1
0
        private async Task OpenChannel(int port, string hostId)
        {
            var cacheContextAccessor = new CacheContextAccessor();
            var cache = new Cache(cacheContextAccessor);
            var namedDependencyProvider = new NamedCacheDependencyProvider();
            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("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,
                    cache,
                    cacheContextAccessor,
                    namedDependencyProvider,
                    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();
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: noahfalk/dnx
        private async Task OpenChannel(int port, string hostId)
        {
            var cacheContextAccessor = new CacheContextAccessor();
            var cache = new Cache(cacheContextAccessor);
            var namedDependencyProvider = new NamedCacheDependencyProvider();
            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("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,
                    cache,
                    cacheContextAccessor,
                    namedDependencyProvider,
                    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();
            }
        }
예제 #3
0
 public ConnectionContext(IDictionary <int, ApplicationContext> contexts,
                          IServiceProvider services,
                          ICache cache,
                          ICacheContextAccessor cacheContextAccessor,
                          INamedCacheDependencyProvider namedDependencyProvider,
                          ProcessingQueue queue,
                          ProtocolManager protocolManager,
                          string hostId)
 {
     _contexts                = contexts;
     _services                = services;
     _cache                   = cache;
     _cacheContextAccessor    = cacheContextAccessor;
     _namedDependencyProvider = namedDependencyProvider;
     _queue                   = queue;
     _hostId                  = hostId;
     _protocolManager         = protocolManager;
 }
예제 #4
0
 public ConnectionContext(IDictionary<int, ApplicationContext> contexts,
                          IServiceProvider services,
                          ICache cache,
                          ICacheContextAccessor cacheContextAccessor,
                          INamedCacheDependencyProvider namedDependencyProvider,
                          ProcessingQueue queue,
                          ProtocolManager protocolManager,
                          string hostId)
 {
     _contexts = contexts;
     _services = services;
     _cache = cache;
     _cacheContextAccessor = cacheContextAccessor;
     _namedDependencyProvider = namedDependencyProvider;
     _queue = queue;
     _hostId = hostId;
     _protocolManager = protocolManager;
 }