Exemplo n.º 1
0
        private void ProcessNotification(notificationType notification)
        {
            SupervisorMonitoringChannel monitoringChannel = _monitoringChannel;

            if (!string.IsNullOrEmpty(notification.sessionId) &&
                monitoringChannel != null &&
                notification.sessionId.Equals(monitoringChannel.SessionId))
            {
                monitoringChannel.ProcessNotification(notification);
            }
            else
            {
                if (notification.agentinfos.Length > 0 || notification.agentsremoved.Length > 0)
                {
                    lock (_agents)
                    {
                        foreach (agentType notificationAgentinfo in notification.agentinfos)
                        {
                            _agents[notificationAgentinfo.uri] = notificationAgentinfo;
                        }

                        foreach (string uri in notification.agentsremoved)
                        {
                            _agents.Remove(uri);
                        }

                        AgentsChangedEventArgs e = new AgentsChangedEventArgs(notification.agentinfos, notification.agentsremoved);

                        EventHandler <AgentsChangedEventArgs> agentsChangedHandler = AgentsChanged;

                        if (agentsChangedHandler != null)
                        {
                            agentsChangedHandler(this, e);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        internal void ProcessNotification(notificationType notification)
        {
            if (notification.agentinfos.Length > 0 || notification.agentsremoved.Length > 0)
            {
                lock (_agents)
                {
                    foreach (agentType notificationAgentinfo in notification.agentinfos)
                    {
                        _agents[notificationAgentinfo.uri] = notificationAgentinfo;
                    }

                    foreach (string uri in notification.agentsremoved)
                    {
                        _agents.Remove(uri);
                    }
                }

                AgentsChangedEventArgs e = new AgentsChangedEventArgs(notification.agentinfos, notification.agentsremoved);

                EventHandler<AgentsChangedEventArgs> agentsChangedHandler = AgentsChanged;

                if (agentsChangedHandler != null)
                {
                    agentsChangedHandler(this, e);
                }


            }

            if (notification.participantinfos.Length > 0 || notification.partcicipantsremoved.Length > 0)
            {
                List<participantType> customersUpdated = new List<participantType>();
                List<participantType> participantsUpdated = new List<participantType>();
                List<string> customersRemoved = new List<string>();
                List<string> participantsRemoved = new List<string>();

                lock (_participants)
                {
                    foreach (participantType notificationParticipantinfo in notification.participantinfos)
                    {
                        if (notificationParticipantinfo.iscustomer)
                        {
                            _customers[notificationParticipantinfo.uri] = notificationParticipantinfo;
                            customersUpdated.Add(notificationParticipantinfo);
                        }
                        else
                        {
                            _participants[notificationParticipantinfo.uri] = notificationParticipantinfo;
                            participantsUpdated.Add(notificationParticipantinfo);
                        }
                    }

                    foreach (string uri in notification.partcicipantsremoved)
                    {
                        if (_customers.Remove(uri))
                        {
                            customersRemoved.Add(uri);
                        }

                        if (_participants.Remove(uri))
                        {
                            participantsRemoved.Add(uri);
                        }
                    }

                }

                if (participantsRemoved.Count > 0 || participantsUpdated.Count > 0)
                {
                    ParticipantsChangedEventArgs e = new ParticipantsChangedEventArgs(participantsUpdated, participantsRemoved);

                    EventHandler<ParticipantsChangedEventArgs> participantsChangedHandler = ParticipantsChanged;

                    if (participantsChangedHandler != null)
                    {
                        participantsChangedHandler(this, e);
                    }
                }

                if (customersRemoved.Count > 0 || customersUpdated.Count > 0)
                {
                    ParticipantsChangedEventArgs e = new ParticipantsChangedEventArgs(customersUpdated, customersRemoved);

                    EventHandler<ParticipantsChangedEventArgs> customersChangedHandler = CustomersChanged;

                    if (customersChangedHandler != null)
                    {
                        customersChangedHandler(this, e);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static notificationType ParseNotification(string notificationData)
        {
            notificationType notification = new notificationType();

            if (!string.IsNullOrEmpty(notificationData))
            {
                XElement element = XElement.Parse(notificationData);

                if (element.Attribute("sessionId") != null)
                {
                    notification.sessionId = element.Attribute("sessionId").Value;
                }

                List <participantType> participantInfos    = new List <participantType>();
                List <string>          participantsRemoved = new List <string>();
                List <agentType>       agentInfos          = new List <agentType>();
                List <string>          agentsRemoved       = new List <string>();

                if (element.Element("participant-infos") != null)
                {
                    foreach (XElement participantInfo in element.Element("participant-infos").Elements("participant-info"))
                    {
                        participantType notificationParticipantinfo = new participantType();
                        notificationParticipantinfo.uri         = participantInfo.Element("uri") == null ? String.Empty : participantInfo.Element("uri").Value;
                        notificationParticipantinfo.displayname = participantInfo.Element("displayname") == null ? "Anonymous" : participantInfo.Element("displayname").Value;
                        notificationParticipantinfo.iscustomer  = participantInfo.Element("iscustomer") == null ? false : Convert.ToBoolean(participantInfo.Element("iscustomer").Value);

                        List <string> mediaTypes = new List <string>();
                        if (participantInfo.Element("media-types") != null)
                        {
                            foreach (XElement mediaType in participantInfo.Element("media-types").Elements("media-type"))
                            {
                                if (mediaType != null)
                                {
                                    mediaTypes.Add(mediaType.Value);
                                }
                            }
                        }
                        notificationParticipantinfo.mediatypes = mediaTypes.ToArray();
                        participantInfos.Add(notificationParticipantinfo);
                    }
                }

                if (element.Element("partcicipants-removed") != null)
                {
                    foreach (XElement removedParticipant in element.Element("partcicipants-removed").Elements("uri"))
                    {
                        if (removedParticipant != null)
                        {
                            participantsRemoved.Add(removedParticipant.Value);
                        }
                    }
                }

                if (element.Element("agent-infos") != null)
                {
                    foreach (XElement agentInfo in element.Element("agent-infos").Elements("agent-info"))
                    {
                        agentType notificationAgentinfo = new agentType();
                        notificationAgentinfo.uri               = agentInfo.Element("uri") == null ? String.Empty : agentInfo.Element("uri").Value;
                        notificationAgentinfo.displayname       = agentInfo.Element("displayname") == null ? String.Empty : agentInfo.Element("displayname").Value;
                        notificationAgentinfo.status            = agentInfo.Element("status") == null ? String.Empty : agentInfo.Element("status").Value;
                        notificationAgentinfo.statuschangedtime = agentInfo.Element("status-changed-time") == null ? String.Empty : agentInfo.Element("status-changed-time").Value;

                        List <string> mediaTypes = new List <string>();
                        if (agentInfo.Element("media-types") != null)
                        {
                            foreach (XElement mediaType in agentInfo.Element("media-types").Elements("media-type"))
                            {
                                if (mediaType != null)
                                {
                                    mediaTypes.Add(mediaType.Value);
                                }
                            }
                        }

                        notificationAgentinfo.mediatypes = mediaTypes.ToArray();
                        agentInfos.Add(notificationAgentinfo);
                    }
                }

                if (element.Element("agents-removed") != null)
                {
                    foreach (XElement removedAgent in element.Element("agents-removed").Elements("uri"))
                    {
                        if (removedAgent != null)
                        {
                            agentsRemoved.Add(removedAgent.Value);
                        }
                    }
                }

                notification.agentinfos           = agentInfos.ToArray();
                notification.agentsremoved        = agentsRemoved.ToArray();
                notification.participantinfos     = participantInfos.ToArray();
                notification.partcicipantsremoved = participantsRemoved.ToArray();
            }

            return(notification);
        }