25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

55 lines
1.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using HBLConsole.Service;
  8. using System.Collections.Concurrent;
  9. using BPA.Message;
  10. using HBLConsole.GVL;
  11. using HBLConsole.Interface;
  12. using HBLConsole.Factory;
  13. namespace HBLConsole.Business
  14. {
  15. public class ServerData
  16. {
  17. private volatile static ServerData _Instance;
  18. public static ServerData GetInstance => _Instance ?? (_Instance = new ServerData());
  19. private ServerData() { }
  20. ConcurrentQueue<string> receives = new ConcurrentQueue<string>();
  21. public void Init()
  22. {
  23. ThreadManage.GetInstance.StartLong(new Action(() =>
  24. {
  25. while (receives.Count > 0)
  26. {
  27. if (receives.TryDequeue(out string msg))
  28. {
  29. var package = BPAPackage.Deserialize(msg);
  30. if (package?.ClientId == InternetInfo.ClientId)
  31. {
  32. if (package.Message != null)
  33. {
  34. SimpleFactory.GetInstance.MqttMessage(package.Message);
  35. }
  36. }
  37. }
  38. }
  39. Thread.Sleep(100);
  40. }), "mqtt消息处理", true);
  41. }
  42. public void ReceiveData(string info)
  43. {
  44. receives.Enqueue(info);
  45. }
  46. }
  47. }