Du kan inte välja fler än 25 ämnen
Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
|
- 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); });
- pipeClient.StartPipeStream();
- MessageLog.GetInstance.NotifyShow = new Action<string>((o) => { if (pipeClient.IsConnected) pipeClient.SendCommand(o); });
-
- }
-
- /// <summary>
- /// 变量保存
- /// </summary>
- public void VarSave()
- {
- Json<CommunicationPar>.Save(FileConfigModel.VarConfigPath);
- pipeClient.SendCommand(PipeTopic.VarSave);
- MessageLog.GetInstance.Show("变量保存成功");
- }
- }
- }
|