代码拉取完成,页面将自动刷新
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace FnSync
{
class AlivePhones : IEnumerable<PhoneClient>
{
public static readonly AlivePhones Singleton = new AlivePhones();
private readonly ConcurrentDictionary<string, PhoneClient> map = new ConcurrentDictionary<string, PhoneClient>();
public PhoneClient this[string id]
{
get
{
return TryGet(id);
}
}
public long AliveCount
{
get
{
int Count = 0;
foreach(PhoneClient client in this)
{
if (client.IsAlive)
++Count;
}
return Count;
}
}
public int Count => map.Count;
private AlivePhones()
{
}
public bool Contains(string id)
{
return map.ContainsKey(id);
}
public PhoneClient AddOrUpdate(string id, PhoneClient phone)
{
PhoneClient old = null;
map.AddOrUpdate(id, phone, (k, v) => { old = v; return phone; });
return old;
}
public PhoneClient TryGet(string id)
{
if (id == null)
return null;
PhoneClient phone;
if (map.TryGetValue(id, out phone))
{
return phone;
}
else
{
return null;
}
}
public void Remove(string id)
{
map.TryRemove(id, out PhoneClient _);
}
public void DisconnectAll()
{
foreach (var kv in map)
{
kv.Value.Dispose();
}
}
public void PushMsg(JObject msg, String msgType)
{
foreach (var kv in map)
{
if (kv.Value.IsAlive)
{
kv.Value.SendMsg(msg, msgType);
}
}
}
public IEnumerator<PhoneClient> GetEnumerator()
{
return map.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。