protected override async Task OnReceiveMessage(string uid, ServerSocketResponse package) { string key, json; SessionSocket socket = Get(uid); if (socket == null) { return; } try { string data = await package.GetTextAsync(); if (string.IsNullOrEmpty(data) || !data.Contains('#')) { return; } key = data.Substring(0, data.IndexOf('#')); json = data.Substring(data.IndexOf('#') + 1); socket.OnInteraction(); SessionType sessionType = Get(uid).SessionType; switch (key) { // // shared channels // case "register": if (sessionType == SessionType.Lander) { ((LanderCommunication)Get(uid).Channels[SessionSocketChannel.Lander]) .OnRegistration(key, JsonConvert.DeserializeObject <ReceivingRegistrationModel>(json)); } else if (sessionType == SessionType.Prelander) { ((PrelanderCommunication)Get(uid).Channels[SessionSocketChannel.Prelander]) .OnRegistration(key, JsonConvert.DeserializeObject <ReceivingRegistrationModel>(json)); } break; // // lander channels // case "user-create": case "user-subscribe": case "user-redirected": LanderCommunicationChannel channel = new LanderCommunicationChannel(Get(uid)); await channel.Start(key, json); break; // // prelander channels // case "pl-init": case "pl-tag": case "pl-q": PrelanderCommunicationChannel prelanderCommunication = new PrelanderCommunicationChannel(Get(uid)); await prelanderCommunication.Call(key, json); break; } } catch (Exception e) { CloseSession(socket); OnException("ApiSocket.OnReceiveMessage", uid, e); return; } }
public async Task <IActionResult> Index(string type, string data) { SocketBackupControllerLogger logger = new SocketBackupControllerLogger( this.Context.CookiesGet(Constants.ActionID), this.Context.CookiesGet(Constants.UserGuidCookie), this.Context.CookiesGetInt(Constants.CountryID), this.Context.HttpContext.Request.Headers["User-Agent"]); SessionType sessionType = (type.Equals("lp") ? Sockets.ApiSockets.Models.SessionType.Lander : Sockets.ApiSockets.Models.SessionType.Prelander); SessionSocket socket = new SessionSocket(this.Context, sessionType); ActionDM action = socket.Action.Data; if (action == null) { logger.StartLoggin("") .Add("type", type) .Add("data", data) .OnException(new Exception("Could not load action")); return(this.ReturnObject(new DistributionModel() { Status = false })); } string[] split = data.Split('|'); if (split.Length != 2) { logger.StartLoggin("") .Add("type", type) .Add("data", data) .OnException(new Exception("Could not get data from object")); return(this.ReturnObject(new DistributionModel() { Status = false })); } string userID = socket.User.Key; int? country = socket.CountryID; if (action.http_flow == false) { action.http_flow = true; action.UpdateLater(); } try { if (type.Equals("pl")) { PrelanderCommunicationChannel channel = new PrelanderCommunicationChannel(logger, action, userID, country, this.Database); return(this.ReturnObject(await channel.Call(split[0], split[1]))); } else if (type.Equals("lp")) { LanderCommunicationChannel channel = new LanderCommunicationChannel(logger, action, userID, country, this.Database); return(this.ReturnObject(await channel.Call(split[0], split[1]))); } else { logger.StartLoggin("") .Add("type", type) .Add("data", data) .OnException(new Exception("Type was not present ")); return(this.ReturnObject(new DistributionModel() { Status = false })); } } catch (Exception e) { logger.StartLoggin("") .Add("type", type) .Add("data", data) .OnException(e); return(this.ReturnObject(new DistributionModel() { Status = false })); } }