コード例 #1
0
ファイル: Program.cs プロジェクト: shawnwildermuth/dnx
        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;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: shawnwildermuth/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,
                          string hostId)
 {
     _contexts                = contexts;
     _services                = services;
     _cache                   = cache;
     _cacheContextAccessor    = cacheContextAccessor;
     _namedDependencyProvider = namedDependencyProvider;
     _queue                   = queue;
     _hostId                  = hostId;
 }
コード例 #4
0
        private static void WriteProjectContexts(ProcessingQueue queue, IDictionary <int, ApplicationContext> contexts)
        {
            var projects = contexts.Values.Select(p => new
            {
                Id          = p.Id,
                ProjectPath = p.ApplicationPath
            })
                           .ToList();

            queue.Send(writer =>
            {
                writer.Write("ProjectContexts");
                writer.Write(projects.Count);
                for (int i = 0; i < projects.Count; i++)
                {
                    writer.Write(projects[i].ProjectPath);
                    writer.Write(projects[i].Id);
                }
            });
        }
コード例 #5
0
ファイル: ConnectionContext.cs プロジェクト: ivlists/KRuntime
 public void Start()
 {
     _queue            = new ProcessingQueue(_stream);
     _queue.OnReceive += OnReceive;
     _queue.Start();
 }