You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace POSV.WindowsService
|
|
|
|
|
{
|
|
|
|
|
public static class SessionManager
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static Dictionary<string, WebSocketSessionEx> SessionDic = new Dictionary<string, WebSocketSessionEx>();
|
|
|
|
|
|
|
|
|
|
//public static List<WebSocketSessionEx> Session = new List<WebSocketSessionEx>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加连接
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="session"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Tuple<bool, string> AddSession(string name, WebSocketSessionEx session)
|
|
|
|
|
{
|
|
|
|
|
if(string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
return new Tuple<bool, string>(false, "注册名称非法");
|
|
|
|
|
}
|
|
|
|
|
if (SessionDic.ContainsKey(name))
|
|
|
|
|
{
|
|
|
|
|
return new Tuple<bool, string>(false, "注册名称已存在");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SessionDic.Add(name, session);
|
|
|
|
|
return new Tuple<bool, string>(true, "注册成功");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 移除session
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Tuple<bool, string> RemoveSession(string name)
|
|
|
|
|
{
|
|
|
|
|
if (name == null)
|
|
|
|
|
{
|
|
|
|
|
return new Tuple<bool, string>(false, "注册名称非法");
|
|
|
|
|
}
|
|
|
|
|
SessionDic.Remove(name);
|
|
|
|
|
return new Tuple<bool, string>(true, "移除成功");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|