Ejemplo n.º 1
0
        public void HandleChatMessage(object sender, ChatMessage e)
        {
            string message = string.Empty;

            if (e != null)
            {
                message = e.Text;
            }

            string from = "<unknown>";

            if (sender != null)
            {
                IChatParticipant senderParticipant = sender as IChatParticipant;
                if (senderParticipant != null)
                {
                    from = senderParticipant.Id;
                }
            }

            if (!string.IsNullOrWhiteSpace(message))
            {
                Console.WriteLine($"{this.Id} - message from '{from}'> {message}");
            }
        }
Ejemplo n.º 2
0
        private void OnConnect_AtachToEventSource(IChatParticipant client)
        {
            IchatMessageEmiter emiter = client as IchatMessageEmiter;

            if (emiter == null)
            {
                throw new ArgumentException($"Class ");
            }
        }
Ejemplo n.º 3
0
        public override void Register(IChatParticipant participant)
        {
            if (!_participants.ContainsValue(participant))
            {
                _participants[participant.Name] = participant;
            }

            participant.Chatroom = this;
        }
Ejemplo n.º 4
0
        public static string GetUserIdFromParticipant(IChatParticipant partyParticipant)
        {
            var participant        = partyParticipant as ChatParticipant;
            var participantCreator = partyParticipant as ChatParticipantCreator;
            var participantAdmin   = partyParticipant as ChatParticipantAdmin;

            if (participant != null)
            {
                return(participant.UserId.ToString(CultureInfo.InvariantCulture));
            }
            else if (participantCreator != null)
            {
                return(participantCreator.UserId.ToString(CultureInfo.InvariantCulture));
            }
            else if (participantAdmin != null)
            {
                return(participantAdmin.UserId.ToString(CultureInfo.InvariantCulture));
            }
            return(null);
        }
Ejemplo n.º 5
0
        public void HandleDisconnectRequest(IChatParticipant client)
        {
            if (client == null)
            {
                // we don't accept null clients
                return;
            }

            if (!this.participants.ContainsKey(client.Id))
            {
                // client wasn't connected
                return;
            }

            client.OnChatEvent -= this.Client_OnChatEvent;

            Console.WriteLine($"User '{client.Id}' a iesit");

            this.participants.Remove(client.Id);
        }
Ejemplo n.º 6
0
        public void HandleConnectRequest(IChatParticipant client)
        {
            if (client == null)
            {
                // we don't accept null clients
                return;
            }

            if (this.participants.ContainsKey(client.Id))
            {
                // client already connected
                return;
            }

            this.participants.Add(client.Id, client);

            client.OnChatEvent += this.Client_OnChatEvent;

            Console.WriteLine($"User '{client.Id}' a intrat");
        }
Ejemplo n.º 7
0
 public abstract void Register(IChatParticipant participant);
Ejemplo n.º 8
0
 protected virtual void NotifyGroupOnNewConnection(IChatParticipant client)
 {
     Console.WriteLine($"User '{client.Id}' has joined the group chat");
 }
Ejemplo n.º 9
0
 public MessageIn(IChatParticipant sender, string text)
 {
     Sender = sender;
     Text   = text.Trim();
 }
Ejemplo n.º 10
0
 public MessageOut(IChatParticipant author, string text, HashSet <IPlayer> listeners = null)
 {
     Author    = author;
     Listeners = listeners?.ToImmutableHashSet() ?? ImmutableHashSet <IPlayer> .Empty;
     Text      = text;
 }
Ejemplo n.º 11
0
 protected virtual void NotifyGroupOnDisconnect(IChatParticipant client)
 {
     Console.WriteLine($"User '{client.Id}' has left the group chat");
 }