RobotViewModel.cs 974 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. Library.Initialize();
  31. var host = new Host(null, Native.ENET_PROTOCOL_MAXIMUM_PEER_ID);
  32. var address = new Address { HostName = "192.168.10.246", Port = 8888 };
  33. var peer = host.Connect(address, 1, 0);
  34. var e = new Event();
  35. while (host.CheckEvents(out e) > 0)
  36. {
  37. if (e.Type == EventType.Connect)
  38. {
  39. LogText += ("Connect OK\r\n");
  40. }
  41. }
  42. }
  43. }
  44. }