42 lines
850 B
C#
42 lines
850 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ChatRoomServer.Main.Room
|
|
{
|
|
using System.Collections.Concurrent;
|
|
|
|
class RoomContainer
|
|
{
|
|
ConcurrentDictionary<ChatSession, RoomSessionContext> _contexts = new ConcurrentDictionary<ChatSession, RoomSessionContext>();
|
|
|
|
/// <summary>
|
|
/// 获得或设置房间ID
|
|
/// </summary>
|
|
public string Id { get; private set; }
|
|
|
|
public RoomContainer(string id)
|
|
{
|
|
Id = id;
|
|
}
|
|
|
|
public void Add(ChatSession session)
|
|
{
|
|
_contexts.GetOrAdd(session, new RoomSessionContext());
|
|
}
|
|
|
|
public void Remove(ChatSession session)
|
|
{
|
|
RoomSessionContext context;
|
|
_contexts.TryRemove(session, out context);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得会话数
|
|
/// </summary>
|
|
public int SessionCount => _contexts.Count;
|
|
}
|
|
}
|