RobotViewModel.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Composition;
  4. using System.Windows.Threading;
  5. using ENet;
  6. using Log;
  7. using Microsoft.Practices.Prism.ViewModel;
  8. using LoginClient;
  9. namespace Modules.Robot
  10. {
  11. [Export(contractType: typeof (RobotViewModel)),
  12. PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
  13. internal sealed class RobotViewModel: NotificationObject, IDisposable
  14. {
  15. private string loginIP = "192.168.11.95";
  16. private ushort loginPort = 8888;
  17. private string account = "egametang@163.com";
  18. private string password = "163bio1";
  19. private readonly LoginClient.LoginClient realmClient = new LoginClient.LoginClient();
  20. private readonly DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.Normal)
  21. { Interval = new TimeSpan(0, 0, 0, 0, 50) };
  22. public string LoginIP
  23. {
  24. get
  25. {
  26. return this.loginIP;
  27. }
  28. set
  29. {
  30. if (this.loginIP == value)
  31. {
  32. return;
  33. }
  34. this.loginIP = value;
  35. this.RaisePropertyChanged("LoginIP");
  36. }
  37. }
  38. public ushort LoginPort
  39. {
  40. get
  41. {
  42. return this.loginPort;
  43. }
  44. set
  45. {
  46. if (this.loginPort == value)
  47. {
  48. return;
  49. }
  50. this.loginPort = value;
  51. this.RaisePropertyChanged("LoginPort");
  52. }
  53. }
  54. public string Account
  55. {
  56. get
  57. {
  58. return this.account;
  59. }
  60. set
  61. {
  62. if (this.account == value)
  63. {
  64. return;
  65. }
  66. this.account = value;
  67. this.RaisePropertyChanged("Account");
  68. }
  69. }
  70. public string Password
  71. {
  72. get
  73. {
  74. return this.password;
  75. }
  76. set
  77. {
  78. if (this.password == value)
  79. {
  80. return;
  81. }
  82. this.password = value;
  83. this.RaisePropertyChanged("Password");
  84. }
  85. }
  86. public RobotViewModel()
  87. {
  88. //this.timer.Tick += delegate { this.clientHost.RunOnce(); };
  89. //this.timer.Start();
  90. }
  91. ~RobotViewModel()
  92. {
  93. this.Disposing(false);
  94. }
  95. public void Dispose()
  96. {
  97. this.Disposing(true);
  98. GC.SuppressFinalize(this);
  99. }
  100. private void Disposing(bool disposing)
  101. {
  102. }
  103. public async void Login()
  104. {
  105. try
  106. {
  107. // 登录realm
  108. List<Realm_List_Gate> gateList = await this.realmClient.LoginRealm(
  109. this.LoginIP, this.LoginPort, this.Account, this.Password);
  110. // 登录gate
  111. }
  112. catch (Exception e)
  113. {
  114. Logger.Trace("realm exception: {0}, {1}", e.Message, e.StackTrace);
  115. }
  116. }
  117. }
  118. }