示例#1
0
文件: Node.cs 项目: sopel30/tsst2
        private void parseOrder(string order)
        {
            //WZOR WIADOMOSCI PRZEROBIC NA WPIS DO SWITCHING TABLE

            string[] parsed = order.Split('%');
            try
            {
                int connectionId = Convert.ToInt32(parsed[2].Split('#')[1]);
                connectionIdToMatrixConnection.Add(connectionId, parsed[1]);
            }
            catch { }

            switch (parsed[0])
            {
                case Constants.SET_LINK:
                    parsed[2] = parsed[2].Split('#')[0];
                    string[] parsed1 = parsed[1].Split('.');
                    string[] parsed2 = parsed[2].Split('.');

                    if ((ifContains(parsed1[0], parsed1[1], portsIn)))
                    {

                            if (switchTable.addLink(parsed1[0], parsed1[1], parsed2[0], parsed2[1]))
                            {
                                CrossConnection newLink = new CrossConnection(Convert.ToString(crossConnectionList.Count() + 1), parsed1[0], parsed1[1], parsed2[0], parsed2[1]);
                                crossConnectionList.Add(newLink);

                                Application.Current.Dispatcher.Invoke((Action)(() =>
                                {
                                    this.links.Items.Add(newLink);
                                }));
                            }
                            break;
                    }

                    else
                    {
                        addLog(logs, Constants.NONEXISTENT_PORT, Constants.ERROR);
                        break;
                    }

                case Constants.DELETE_LINK:
                    if (parsed[1] == "*")
                    {
                        for (int i = links.Items.Count - 1; i >= 0; i--)
                        {

                            Application.Current.Dispatcher.Invoke((Action)(() =>
                            {
                                links.Items.Remove(links.Items[i]);
                                crossConnectionList.RemoveAt(i);
                            }));
                        }

                        switchTable.removeAllLinks();
                    }
                    else if (connectionIdToMatrixConnection.ContainsKey(Convert.ToInt32(parsed[1])))
                    {

                        string[] parsedX = connectionIdToMatrixConnection[Convert.ToInt32(parsed[1])].Split('.');
                        switchTable.removeLink(parsedX[0], parsedX[1]);
                        for (int i = links.Items.Count - 1; i >= 0; i--)
                        {
                            if (parsedX[0] == crossConnectionList[i].src || parsedX[0]==crossConnectionList[i].dst)
                            {
                                Application.Current.Dispatcher.Invoke((Action)(() =>
                                {
                                    links.Items.Remove(links.Items[i]);
                                }));
                                crossConnectionList.RemoveAt(i);
                            }

                        }
                        connectionIdToMatrixConnection.Remove(Convert.ToInt32(parsed[1]));
                    }
                    else
                    {
                        string[] parsedX = parsed[1].Split('.');
                        switchTable.removeLink(parsedX[0],parsedX[1]);
                        for (int i = links.Items.Count - 1; i >= 0; i--)
                        {
                            if (parsed[1] == crossConnectionList[i].src)
                            {
                                links.Items.Remove(i);
                                crossConnectionList.RemoveAt(i);
                            }

                        }
                    }
                    break;
            }
        }
示例#2
0
文件: Node.cs 项目: admsbk/tsst2
        private void parseOrder(string order)
        {
            //WZOR WIADOMOSCI PRZEROBIC NA WPIS DO SWITCHING TABLE

            string[] parsed = order.Split('%');
            try
            {
                int connectionId = Convert.ToInt32(parsed[2].Split('#')[1]);
                connectionIdToMatrixConnection.Add(connectionId, parsed[1]);
            }
            catch { }



            switch (parsed[0])
            {
            case Constants.SET_LINK:
                parsed[2] = parsed[2].Split('#')[0];
                string[] parsed1 = parsed[1].Split('.');
                string[] parsed2 = parsed[2].Split('.');


                if ((ifContains(parsed1[0], parsed1[1], portsIn)))
                {
                    if (switchTable.addLink(parsed1[0], parsed1[1], parsed2[0], parsed2[1]))
                    {
                        CrossConnection newLink = new CrossConnection(Convert.ToString(crossConnectionList.Count() + 1), parsed1[0], parsed1[1], parsed2[0], parsed2[1]);
                        crossConnectionList.Add(newLink);

                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            this.links.Items.Add(newLink);
                        }));
                    }
                    break;
                }

                else
                {
                    addLog(logs, Constants.NONEXISTENT_PORT, Constants.ERROR);
                    break;
                }

            case Constants.DELETE_LINK:
                if (parsed[1] == "*")
                {
                    for (int i = links.Items.Count - 1; i >= 0; i--)
                    {
                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            links.Items.Remove(links.Items[i]);
                            crossConnectionList.RemoveAt(i);
                        }));
                    }

                    switchTable.removeAllLinks();
                }
                else if (connectionIdToMatrixConnection.ContainsKey(Convert.ToInt32(parsed[1])))
                {
                    string[] parsedX = connectionIdToMatrixConnection[Convert.ToInt32(parsed[1])].Split('.');
                    switchTable.removeLink(parsedX[0], parsedX[1]);
                    for (int i = links.Items.Count - 1; i >= 0; i--)
                    {
                        if (parsedX[0] == crossConnectionList[i].src || parsedX[0] == crossConnectionList[i].dst)
                        {
                            Application.Current.Dispatcher.Invoke((Action)(() =>
                            {
                                links.Items.Remove(links.Items[i]);
                            }));
                            crossConnectionList.RemoveAt(i);
                        }
                    }
                    connectionIdToMatrixConnection.Remove(Convert.ToInt32(parsed[1]));
                }
                else
                {
                    string[] parsedX = parsed[1].Split('.');
                    switchTable.removeLink(parsedX[0], parsedX[1]);
                    for (int i = links.Items.Count - 1; i >= 0; i--)
                    {
                        if (parsed[1] == crossConnectionList[i].src)
                        {
                            links.Items.Remove(i);
                            crossConnectionList.RemoveAt(i);
                        }
                    }
                }
                break;
            }
        }