Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
|
- 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<string> msg = new ConcurrentQueue<string>();
-
- /// <summary>
- /// 退出通知
- /// </summary>
- public Action ExitNotify { get; set; }
-
- public void Init()
- {
-
- }
-
- /// <summary>
- /// 客户端管道通讯初始化
- /// </summary>
- 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<string>((s) => { if (pipeClient.IsConnected) msg.Enqueue(s); });
- MessageLog.GetInstance.NotifyShow = new Action<string>((o) => { if (pipeClient.IsConnected) pipeClient.SendCommand(o); });
- pipeClient.StartPipeStream();
-
- }
-
- /// <summary>
- /// 变量保存
- /// </summary>
- public void VarSave()
- {
- Json<CommunicationPar>.Save(FileConfigModel.VarConfigPath);
- pipeClient.SendCommand(PipeTopic.VarSave);
- MessageLog.GetInstance.Show("变量保存成功");
- }
- }
- }
|