Exemplo n.º 1
0
        internal void Publish(Type type, object message)
        {
            if (type == message.GetType())
            {
                System.Reflection.PropertyInfo pi = message.GetType().GetProperty("RoomType");
                int roomType = (int)(pi.GetValue(message, null));

                System.Reflection.PropertyInfo pt = message.GetType().GetProperty("Text");
                string text = (string)(pt.GetValue(message, null));

                var clientsId = clientRoomRepository.GetSocketsIdListForRoomType(roomType);

                var listOfSubscribers = new List <SocketModel>();
                foreach (int id in clientsId)
                {
                    var subscriber = socketRepository.GetById(id);
                    if (subscriber != null)
                    {
                        listOfSubscribers.Add(subscriber);
                    }
                }

                if (listOfSubscribers != null && listOfSubscribers.Count > 0)
                {
                    foreach (var client in listOfSubscribers)
                    {
                        text = FormatText(text);
                        connectionService.SendMessage(client.IpAddress, client.Port, text);
                    }
                }
            }
        }