Пример #1
0
        public void RunAgent()
        {
            var socket = ConnectToServer();
            if (socket == null)
            {
                Log.Error("Could not establish a connection to the server, aborting...");
                return;
            }

            networkClient = new NetworkClient(socket);
            //networkClient.MessageReceived += AgentOnMessageReceived;

            var agentInfo = new BuildAgentInfoMessage
            {
                MachineName = Environment.MachineName
            };

            networkClient.Send(NetworkMessageKind.BuildAgentInfo, agentInfo);

            while (networkClient.IsActive)
            {
                var task = networkClient.GetMessage();
                task.Wait();

                var message = task.Result;
                OnServerMessage(networkClient, message);
            }
        }
Пример #2
0
        private void OnClientDisconnected(NetworkClient client)
        {
            client.IsActive = false;
            client.Socket.Close();

            if (_clients.Contains(client))
                _clients.Remove(client);

            ClientDisconnected(client);
        }
Пример #3
0
        private void OnClientConnected(TcpClient client, int clientNumber)
        {
            var netClient = new NetworkClient(client, clientNumber);
            netClient.ClientDisconnected += OnClientDisconnected;

            ClientConnected(netClient);

            _clients.Add(netClient);
            _clientReceiveInputTasks.Add(
                new KeyValuePair<Task, NetworkClient>(netClient.GetMessage(), netClient));
        }
Пример #4
0
 private void HandleBuildAgentDisconnect(NetworkClient client)
 {
     lock (BuildAgents)
     {
         foreach (var agent in BuildAgents.Where(
             agent => agent.Client == client).ToArray())
         {
             BuildAgents.Remove(agent);
             Log.Message("Build agent disconnected: {0}", agent);
         }
     }
 }
Пример #5
0
        private void HandleBuildAgentConnection(NetworkClient client)
        {
            var agent = new RemoteBuildAgent(client);
            lock (BuildAgents)
            {
                BuildAgents.Add(agent);
            }

            Log.Message("Build agent connected: {0}", agent);
        }
Пример #6
0
        private void OnServerMessage(NetworkClient client, NetworkMessage message)
        {
            Log.Message("Received: {0}", message);

            switch (message.Kind)
            {
                case NetworkMessageKind.Disconnect:
                    break;
                case NetworkMessageKind.ProtocolVersion:
                    break;
                case NetworkMessageKind.BuildAgentInfo:
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Пример #7
0
 void HandleBuildAgentMessage(NetworkClient client,
     NetworkMessage message)
 {
     var data = message.Data;
     Log.Message("Message: {0}", data);
 }
Пример #8
0
 public RemoteBuildAgent(NetworkClient client)
 {
     Client = client;
     Client.MessageReceived += HandleBuildAgentMessage;
 }