终端一体化运控平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

74 linhas
2.1 KiB

  1. using BPA.Communication;
  2. using BPA.Helper;
  3. using BPASmart.Model;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Collections.Concurrent;
  10. using System.Threading;
  11. namespace BPASmart.VariableManager
  12. {
  13. public class ServiceCenter
  14. {
  15. private volatile static ServiceCenter _Instance;
  16. public static ServiceCenter GetInstance => _Instance ?? (_Instance = new ServiceCenter());
  17. private ServiceCenter() { }
  18. PipeClient pipeClient = new PipeClient(PipeTopic.PipeName);
  19. ConcurrentQueue<string> msg = new ConcurrentQueue<string>();
  20. /// <summary>
  21. /// 退出通知
  22. /// </summary>
  23. public Action ExitNotify { get; set; }
  24. public void Init()
  25. {
  26. }
  27. /// <summary>
  28. /// 客户端管道通讯初始化
  29. /// </summary>
  30. public void PipeInit()
  31. {
  32. ThreadManage.GetInstance().StartLong(new Action(() =>
  33. {
  34. while (msg.Count > 0)
  35. {
  36. if (msg.TryDequeue(out string s))
  37. {
  38. if (s == PipeTopic.ExitNotify)
  39. {
  40. ExitNotify?.Invoke();
  41. }
  42. else
  43. {
  44. MessageLog.GetInstance.Show(s);
  45. }
  46. }
  47. }
  48. Thread.Sleep(100);
  49. }), "客户端管道消息控制");
  50. pipeClient.PushCommand = new Action<string>((s) => { if (pipeClient.IsConnected) msg.Enqueue(s); });
  51. MessageLog.GetInstance.NotifyShow = new Action<string>((o) => { if (pipeClient.IsConnected) pipeClient.SendCommand(o); });
  52. pipeClient.StartPipeStream();
  53. }
  54. /// <summary>
  55. /// 变量保存
  56. /// </summary>
  57. public void VarSave()
  58. {
  59. Json<CommunicationPar>.Save(FileConfigModel.VarConfigPath);
  60. pipeClient.SendCommand(PipeTopic.VarSave);
  61. MessageLog.GetInstance.Show("变量保存成功");
  62. }
  63. }
  64. }