Exemplo n.º 1
0
 private void newMessageRecived(object a, MessageArgs e)
 {
     if (e.Message.Contains("CO"))
     {
         string getSenderId = clientSockets.FirstOrDefault(x => x.Value == e.ID).Key;
         addLog(this.logs, Constants.NEW_MSG_RECIVED + " from " + getSenderId + " " + e.Message, Constants.LOG_INFO);
         try
         {
             string   forwarded   = switchBox.forwardMessage(getSenderId + "%" + e.Message);
             string[] getNextNode = forwarded.Split('%');
             server.sendMessage(clientSockets[getNextNode[0]], getSenderId + "%" + getNextNode[1]);
             addLog(this.logs, Constants.FORWARD_MESSAGE + " " + forwarded, Constants.LOG_INFO);
         }
         catch
         {
             addLog(this.logs, Constants.UNREACHABLE_DST + " " + switchBox.forwardMessage(getSenderId + "%" + e.Message), Constants.LOG_ERROR);
         }
     }
Exemplo n.º 2
0
        //mozna to przerobic na jakies bardziej obiektowe
        private void newMessageRecived(object a, MessageArgs e)
        {
            string getSenderId = null;

            try
            {
                getSenderId = clientSockets.FirstOrDefault(x => x.Value == e.ID).Key;
            }
            catch { }
            if (e.message.Contains("CP") && !getSenderId.Contains("CallControl"))
            {
                addLog(this.logs, Constants.NEW_MSG_RECEIVED + " from " + getSenderId + " " + e.message, Constants.LOG_INFO);
                try
                {
                    string[] msg         = e.message.Split('^');
                    string   forwarded   = switchBox.forwardMessage(getSenderId + "%" + msg[0] + "&" + e.message);
                    string[] getNextNode = forwarded.Split('%');
                    server.sendMessage(clientSockets[getNextNode[0]], getSenderId + "%" + getNextNode[1] + msg[1].Split('&')[1]);
                    addLog(this.logs, Constants.FORWARD_MESSAGE + " " + forwarded, Constants.LOG_INFO);
                }
                catch
                {
                    addLog(this.logs, Constants.UNREACHABLE_DST + " " + switchBox.forwardMessage(getSenderId + "%" + e.message), Constants.LOG_ERROR);
                }
            }

            else if (e.message.Split('#').Length == 1 && e.message.Split('/').Length != 2 && e.message.Split(':').Length > 1 && !getSenderId.Contains("CallControl"))
            {
                addLog(this.logs, Constants.NEW_MSG_RECEIVED + " from " + getSenderId + " " + e.message, Constants.LOG_INFO);
                try
                {
                    string   forwarded   = switchBox.forwardMessage(getSenderId + "%" + e.message);
                    string[] getNextNode = forwarded.Split('%');
                    server.sendMessage(clientSockets[getNextNode[0]], getSenderId + "%" + getNextNode[1]);
                    addLog(this.logs, Constants.FORWARD_MESSAGE + " " + forwarded, Constants.LOG_INFO);
                }
                catch
                {
                    addLog(this.logs, Constants.UNREACHABLE_DST + " " + switchBox.forwardMessage(getSenderId + "%" + e.message), Constants.LOG_ERROR);
                }
            }

            else if (e.message.Split('#').Length == 1 && e.message.Split('/').Length == 2 && !getSenderId.Contains("CallControl"))
            {
                string[] receivedSlots = SynchronousTransportModule.getSlots(e.message.Split('/')[0]);
                if (receivedSlots != null)
                {
                    addLog(this.logs, Constants.NEW_MSG_RECEIVED + " from " + getSenderId + " " + e.message, Constants.LOG_INFO);
                    try
                    {
                        string forwarded = switchBox.forwardMessage(getSenderId + "%" + e.message);
                        addLog(this.logs, Constants.FORWARD_MESSAGE + " " + forwarded, Constants.LOG_INFO);
                        string[] getNextNode = forwarded.Split('%');
                        server.sendMessage(clientSockets[getNextNode[0]], getSenderId + "%" + getNextNode[1]);
                        addLog(this.logs, Constants.FORWARD_MESSAGE + " " + forwarded, Constants.LOG_INFO);
                    }
                    catch
                    {
                        addLog(this.logs, Constants.UNREACHABLE_DST + " " + switchBox.forwardMessage(getSenderId + "%" + e.message), Constants.LOG_ERROR);
                    }
                }
            }

            else if (getSenderId != null)
            {
                if (getSenderId.Contains("CallControl"))
                {
                    addLog(this.logs, Constants.NEW_MSG_RECEIVED + " from " + getSenderId + " " + e.message, Constants.LOG_INFO);
                    if (getSenderId.Contains("NetworkNode") && getSenderId.Contains("rtadd"))
                    {
                        try
                        {
                            string[] getNextNode = e.message.Split('#');
                            string   pdu         = "";
                            for (int i = 1; i < getNextNode.Length; i++)
                            {
                                pdu += "#" + getNextNode[i];
                            }
                            server.sendMessage(clientSockets[getNextNode[0]], getSenderId + "%" + pdu);
                            addLog(this.logs, Constants.FORWARD_MESSAGE + " " + getSenderId + "%" + pdu, Constants.LOG_INFO);
                        }
                        catch
                        {
                            addLog(this.logs, Constants.UNREACHABLE_DST + " ", Constants.LOG_ERROR);
                        }
                    }
                    else
                    {
                        try
                        {
                            string[] getNextNode = e.message.Split('#');
                            string   pdu         = "";
                            for (int i = 1; i < getNextNode.Length; i++)
                            {
                                pdu += "#" + getNextNode[i];
                            }
                            server.sendMessage(clientSockets[getNextNode[0]], getSenderId + "%" + pdu);
                            addLog(this.logs, Constants.FORWARD_MESSAGE + " " + getSenderId + "%" + pdu, Constants.LOG_INFO);
                        }
                        catch
                        {
                            addLog(this.logs, Constants.UNREACHABLE_DST + " ", Constants.LOG_ERROR);
                        }
                    }
                }
            }
            else
            {
                addNewClient(e.message, e);
            }
        }