private static Connection?CreateConnection(WebSocket ws) { var login = ws.HttpRequest.GetLogin(); if (login == null) { return(null); } if (ws.HttpRequest.RequestUri.OriginalString == "/ws/publics") { return new Connection { NeedSend = point => point.IsPublic, Lock = new AsyncLockSource(), InitData = () => PointHolder.GetPublics() } } ; if (ws.HttpRequest.RequestUri.OriginalString == "/ws/points") { return new Connection { NeedSend = point => point.User == login, Lock = new AsyncLockSource(), InitData = () => PointHolder.GetPoints(login) } } ; return(null); }
protected override Task HandleInternal(HttpListenerContext context, string login) => context.Response.WriteObjectAsync(PointHolder.GetPoints(login).Select(PointConverter.Convert).ToList());