Exemplo n.º 1
0
        public override void switchNetwork(Network from, Network to, bool silently)
        {
            bool change_label = false;
            String name = LabelString.Substring(0, LabelString.IndexOf('_')-1);
            int instance = Int32.Parse(LabelString.Substring(LabelString.IndexOf('_')));

            if (name != null && name == NameString && instance != InstanceNumber)
            {
                change_label = true;
            }

            String new_name = "";

            List<Node> rnl = to.makeClassifiedNodeList(typeof(ProbeNode), false);
            if (rnl != null && !change_label)
            {
                foreach (Node n in rnl)
                {
                    if (!change_label)
                    {
                        if (n.LabelString == LabelString)
                        {
                            change_label = true;
                            break;
                        }
                    }
                }
            }

            if (change_label)
            {
                String new_label = NameString + "_" + InstanceNumber;
                if (!silently)
                {
                    InfoDialog id = new InfoDialog();
                    id.post("{0} {1} has been relabled {2}", NameString, LabelString, new_label);
                }
                setLabelString(new_label);
            }
            base.switchNetwork(from, to, silently);
        }
Exemplo n.º 2
0
        public override void switchNetwork(Network from, Network to, bool silently)
        {
            String conflict = to.nameConflictExists(this, LabelString);
            String new_name = "";
            bool name_change_required = false;
            if (conflict != null)
            {
                new_name = String.Format("wireless_{0}", InstanceNumber);
                name_change_required = true;
            }

            List<Node> rnl = to.makeClassifiedNodeList(typeof(TransmitterNode), false);
            String cp = (name_change_required ? new_name : LabelString);
            if (rnl != null)
            {
                foreach (Node n in rnl)
                {
                    ReceiverNode rn = (ReceiverNode)n;
                    if (!rn.IsTransmitterConnected &&
                        rn.LabelString == cp)
                    {
                        if (to.checkForCycle(this, rn))
                        {
                            new_name = String.Format("cyclic_connection_{0}", InstanceNumber);
                            name_change_required = true;
                            break;
                        }
                    }
                }
            }

            if (name_change_required)
            {
                if (!silently)
                {
                    InfoDialog id = new InfoDialog();
                    id.post("Transmitter {0} has been relabled {1}", LabelString, new_name);
                }
                setLabelString(new_name);
            }
            rnl = to.makeClassifiedNodeList(typeof(ReceiverNode), false);
            if (rnl != null)
            {
                foreach (Node n in rnl)
                {
                    ReceiverNode rn = (ReceiverNode)n;
                    if (!rn.IsTransmitterConnected &&
                        rn.LabelString == LabelString)
                    {
                        new Ark(this, 0, rn, 0);
                    }
                }
            }
            base.switchNetwork(from, to, silently);
        }