public void AppoinmentCreated(AppointmentDTO appointmentDTO)
            {
                var appointmentNotification = _iAppointmentBus.MakeAppointment(appointmentDTO);
                var send = JsonConvert.SerializeObject(appointmentNotification);

                _clients.FirstOrDefault(r => ((AppointmentWebSocketHandler)r)._userId == appointmentDTO.AdvertismentOwnerId).Send(send);
            }
Example #2
0
        private WebSocketHandler GetUser(string clientKey)
        {
            if (Users.Count == 0)
            {
                return(null);
            }

            var user = Users.FirstOrDefault(u =>
            {
                var ctx = u as PairWebSocketHandler;
                if (ctx == null)
                {
                    return(false);
                }

                return(ctx._clientKey == clientKey);
            });

            return(user);
        }
Example #3
0
        private void AtualizarBarcos(MicrosoftWebSockets client, string jogada)
        {
            ((MicrosoftWebSockets)clients.FirstOrDefault(x => ((MicrosoftWebSockets)x).Id == client.Id)).Barcos = client.Barcos;

            client.Send(JsonConvert.SerializeObject(new Retorno(TipoMensagemRetorno.Atingido, string.Format("VocĂȘ foi atingindo !!! |{0}", jogada))));
        }
Example #4
0
        public override void OnMessage(string message)
        {
            dynamic jsonMessage;

            try
            {
                jsonMessage = Json.Decode(message);
            }
            catch (Exception ex)
            {
                // TODO: Error handling.
                throw ex;
            }
            string type = jsonMessage.Type;

            if (type == null)
            {
                // TODO: Error handling.
                return;
            }
            switch (type)
            {
            case "ConnectionType":
            {
                ConnectionType = Enum.Parse(typeof(ConnectionTypes), jsonMessage.ConnectionType);
                var random    = new Random();
                var sessionID = random.Next(0, 999).ToString().PadLeft(3, '0') + " " + random.Next(0, 999).ToString().PadLeft(3, '0');
                SessionID = sessionID.Replace(" ", "");
                var request = new
                {
                    Type      = "SessionID",
                    SessionID = sessionID
                };
                Send(Json.Encode(request));
                break;
            }

            case "Connect":
            {
                var client = SocketCollection.FirstOrDefault(sock => ((Viewer)sock).SessionID == jsonMessage.SessionID.Replace(" ", "") && ((Viewer)sock).ConnectionType == ConnectionTypes.ClientApp);
                if (client != null)
                {
                    Partner = (Viewer)client;
                    ((Viewer)client).Partner = this;
                    SessionID = (client as Viewer).SessionID;
                    client.Send(message);
                }
                else
                {
                    var request = new
                    {
                        Type   = "Connect",
                        Status = "InvalidID"
                    };
                    Send(Json.Encode(request));
                }
                break;
            }

            case "PartnerClose":
                Partner = null;
                Partner.Send(message);
                break;

            case "PartnerError":
                Partner = null;
                Partner.Send(message);
                break;

            default:
            {
                Partner.Send(message);
                break;
            }
            }
        }