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(); } }
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(); } }
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; }
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; }