using BPA.Communication; using BPA.Helper; using BPASmart.Model; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections.Concurrent; using System.Threading; namespace BPASmart.VariableManager { public class ServiceCenter { private volatile static ServiceCenter _Instance; public static ServiceCenter GetInstance => _Instance ?? (_Instance = new ServiceCenter()); private ServiceCenter() { } PipeClient pipeClient = new PipeClient(PipeTopic.PipeName); ConcurrentQueue msg = new ConcurrentQueue(); /// /// 退出通知 /// public Action ExitNotify { get; set; } public void Init() { } /// /// 客户端管道通讯初始化 /// public void PipeInit() { ThreadManage.GetInstance().StartLong(new Action(() => { while (msg.Count > 0) { if (msg.TryDequeue(out string s)) { if (s == PipeTopic.ExitNotify) { ExitNotify?.Invoke(); } else { MessageLog.GetInstance.Show(s); } } } Thread.Sleep(100); }), "客户端管道消息控制"); pipeClient.PushCommand = new Action((s) => { if (pipeClient.IsConnected) msg.Enqueue(s); }); MessageLog.GetInstance.NotifyShow = new Action((o) => { if (pipeClient.IsConnected) pipeClient.SendCommand(o); }); pipeClient.StartPipeStream(); } /// /// 变量保存 /// public void VarSave() { Json.Save(FileConfigModel.VarConfigPath); pipeClient.SendCommand(PipeTopic.VarSave); MessageLog.GetInstance.Show("变量保存成功"); } } }