RobotViewModel.cs 947 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.ComponentModel.Composition;
  3. using ELog;
  4. using Microsoft.Practices.Prism.ViewModel;
  5. using ENet;
  6. namespace Modules.Robot
  7. {
  8. [Export(contractType: typeof (RobotViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
  9. internal class RobotViewModel : NotificationObject
  10. {
  11. private string logText = "";
  12. public string LogText
  13. {
  14. get
  15. {
  16. return this.logText;
  17. }
  18. set
  19. {
  20. if (this.logText == value)
  21. {
  22. return;
  23. }
  24. this.logText = value;
  25. this.RaisePropertyChanged("LogText");
  26. }
  27. }
  28. public void Start()
  29. {
  30. var address = new Address {HostName = "192.168.10.246", Port = 8888};
  31. var host = new Host(address, Native.ENET_PROTOCOL_MAXIMUM_PEER_ID);
  32. var e = new Event();
  33. var peer = host.Connect(address, 255, 0);
  34. while (host.CheckEvents(out e) > 0)
  35. {
  36. if (e.Type == EventType.Connect)
  37. {
  38. LogText += ("Connect OK\r\n");
  39. }
  40. }
  41. }
  42. }
  43. }