//[Test] public void SingleUpdate_RecievedGetAllPercepts_PickUpPerceptsAndReturnThemThroughWriter() { ActionManager manager = new ActionManager(new EventManager()); TileWorldBuilder worldBuilder = new TileWorldBuilder(new Size(4, 4)); Agent agent = new Agent("testagent"); worldBuilder.AddEntity(() => agent, new TileSpawnInformation(new TilePosition(new Point(0, 0)))); XmasFactory fact = new XmasFactory(manager); TileWorld world = (TileWorld)worldBuilder.Build(); agent.ActionManager = manager; agent.World = world; agent.Factory = fact; Thread thread1 = new Thread(test2); thread1.Name = "TCP Server"; thread1.Start(); while (lock1) { } TcpClient client = new TcpClient("localhost", 6661); Stream stream = client.GetStream(); StringBuilder sb = new StringBuilder(); EisConversionTool ctool = new EisConversionTool(); ctool.AddConverter(new GetAllPerceptsActionConverter()); ctool.AddConverter(new EISPerceptCollectionSerializer()); ctool.AddConverter(new EisTileVisionSerializer()); ctool.AddConverter(new EISSingleNumeralSerializer()); IILActionParser parser = new IILActionParser(); XmlReaderSettings set = new XmlReaderSettings(); set.ConformanceLevel = ConformanceLevel.Fragment; XmlReader xreader = XmlReader.Create(new StreamReader(stream, Encoding.UTF8)); XmlWriterSettings wset = new XmlWriterSettings(); wset.OmitXmlDeclaration = true; XmlWriter xwriter = XmlWriter.Create(sb, wset); controller = new EISAgentController(agent, client, manager, new PacketStream(stream), new StreamReader(stream), new StreamWriter(stream), ctool, parser); Thread thread2 = new Thread(test1); thread2.Name = "Controller"; thread2.Start(); while (manager.ExecuteActions() == 0) ; string returned = null; do { try { returned = sb.ToString(); } catch { } } while (String.IsNullOrEmpty(returned)); }
private AgentController CreateAgentController(TcpClient client, out string name) { PacketStream packet = new PacketStream(client.GetStream()); StreamReader sreader = new StreamReader(packet, Encoding.UTF8); StreamWriter swriter = new StreamWriter(packet, Encoding.UTF8); packet.ReadNextPackage(); XmlSerializer serializer = new XmlSerializer(typeof (IilIdentifier)); IilIdentifier ident = (IilIdentifier) serializer.Deserialize(sreader); name = ident.Value; Agent agent = TakeControlOf(name); EISAgentController con = new EISAgentController(agent, client, this.ActionManager, packet, sreader, swriter, tool, parser); return con; }