/// <inhertidoc />
        public void TriggerHighlight(string alg, IMNodeInternal target)
        {
            if (Equals(_globalHighlightTarget) || Equals(_globalHighlightRoot))
            {
                TriggerHighlightReset();
                return;
            }

            ClearOld();

            _globalTargetKey       = target.ID;
            _globalHighlightTarget = (IMNode)target;
            _globalHighlightRoot   = this;
            _globalHighlightColour = Colour;
            _globalHighlightState  = HighlghtState.HighlightingSingle;
            _highlightState        = HighlghtState.HighlightingSingle;

            //If there is a route
            if (ForwardingTable.ContainsKey(_globalTargetKey))
            {
                lock (HighlightLock) {
                    _highlightedLink        = ForwardingTable[_globalTargetKey];
                    _highlightedLink.Colour = _globalHighlightColour;
                    IMNode node = ForwardingTable[_globalTargetKey].OtherEnd(this);
                    node.Highlight(this);
                }
            }
            else
            {
                _highlightedLink = null;
            }
        }
        /// <summary>
        ///   What to do when a packet relevant to the highlight flooding algorithm is received
        ///
        ///   If the node has not already received one of the highlight flooding packets flood highlight packets along all links and send a new
        ///   highlight all packet back towards the source of the received packet
        /// </summary>
        /// <param name = "packet"></param>
        public void HighlightAll(IMNodeInternal hop)
        {
            if (HighlightingAll)
            {
                return;
            }

            lock (HighlightLock) {
                _highlightedLink = ForwardingTable.ContainsKey(_globalTargetKey) ? ForwardingTable[_globalTargetKey] : null;
                _highlightState  = HighlghtState.HighlightingAll;

                if (_highlightedLink != null)
                {
                    _highlightedLink.Colour = _globalHighlightColour;
                }

                foreach (IMLink l in _links)
                {
                    IMNode neighbour = l.OtherEnd(this);
                    if (!neighbour.Equals(hop))
                    {
                        neighbour.HighlightAll(this);
                    }
                }
            }
        }
Exemple #3
0
        /// <inhertidoc />
        public void AddLink(IMLink link, Parameters parameters)
        {
            IMNode neighbour = link.OtherEnd(this);

            //Add the link referenced by both its own UUID and the ID of the neighbour it connects to
            lock (_links) {
                if (!_links.ContainsKey(neighbour.ID))
                {
                    _links.Add(neighbour.ID, link);
                }
                if (!_links.ContainsKey(link.ID))
                {
                    _links.Add(link.ID, link);
                }
            }
            lock (_neighbours)
                if (!_neighbours.ContainsKey(link.ID))
                {
                    _neighbours.Add(link.ID, neighbour);
                }

            link.OnWeightChanged += _weightDelegate;

            if (OnLinkAdded != null)
            {
                OnLinkAdded(ID, link, parameters);
                Logger.Debug(Name + " triggered OnLinkAdded for '" + link.Name + "'.");
            }
        }
 /// <inhertidoc />
 public void TriggerHighlightReset()
 {
     if (OnHighlightReset != null)
     {
         OnHighlightReset();
     }
     _globalHighlightRoot   = null;
     _globalHighlightTarget = null;
     _globalHighlightState  = HighlghtState.NotHighlighting;
 }
        private static XDocument BuildDocument(IMNode node)
        {
            Checker.CheckNotNull(node);

            XElement root = NodeToXmlBuilder.BuildElement(node);

            XDocument document = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XComment(string.Format("Generated by {0} (version {1})", Information.MatlabParser, Information.Version)),
                new XComment(Information.Copyright),
                new XComment(Information.AllRightsReserved),
                root
            );

            return document;
        }
        /// <inhertidoc />
        public void TriggerHighlightAll(string alg)
        {
            if (Equals(_globalHighlightTarget))
            {
                TriggerHighlightReset();
                return;
            }

            ClearOld();

            _globalTargetKey       = ID;
            _globalHighlightTarget = this;
            _globalHighlightRoot   = null;
            _globalHighlightColour = Colour;
            _globalHighlightState  = HighlghtState.HighlightingAll;

            HighlightAll(this);
        }
 /// <inhertidoc />
 public void TriggerHighlightReset()
 {
     if (OnHighlightReset != null)
         OnHighlightReset();
     _globalHighlightRoot = null;
     _globalHighlightTarget = null;
     _globalHighlightState = HighlghtState.NotHighlighting;
 }
        /// <inhertidoc />
        public void TriggerHighlightAll(string alg)
        {
            if (Equals(_globalHighlightTarget)) {
                TriggerHighlightReset();
                return;
            }

            ClearOld();

            _globalTargetKey = ID;
            _globalHighlightTarget = this;
            _globalHighlightRoot = null;
            _globalHighlightColour = Colour;
            _globalHighlightState = HighlghtState.HighlightingAll;

            HighlightAll(this);
        }
        /// <inhertidoc />
        public void TriggerHighlight(string alg, IMNodeInternal target)
        {
            if (Equals(_globalHighlightTarget) || Equals(_globalHighlightRoot)) {
                TriggerHighlightReset();
                return;
            }

            ClearOld();

            _globalTargetKey = target.ID;
            _globalHighlightTarget = (IMNode)target;
            _globalHighlightRoot = this;
            _globalHighlightColour = Colour;
            _globalHighlightState = HighlghtState.HighlightingSingle;
            _highlightState = HighlghtState.HighlightingSingle;

            //If there is a route
            if (ForwardingTable.ContainsKey(_globalTargetKey)) {
                lock (HighlightLock) {
                    _highlightedLink = ForwardingTable[_globalTargetKey];
                    _highlightedLink.Colour = _globalHighlightColour;
                    IMNode node = ForwardingTable[_globalTargetKey].OtherEnd(this);
                    node.Highlight(this);
                }
            } else
                _highlightedLink = null;
        }
        private static XElement BuildElement(IMNode node)
        {
            Type nodeType = node.GetType();

            string nodeName = nodeType.Name.EndsWith("Node") ? nodeType.Name.Substring(0, nodeType.Name.Length - 4) : nodeType.Name;

            XElement root = new XElement(nodeName);

            IEnumerable<PropertyInfo> informationProperties = from property in nodeType.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                              where property.IsDefined(typeof(InformationAttribute), true)
                                                              let index = ((InformationAttribute)property.GetCustomAttributes(typeof(InformationAttribute), true).First()).Index
                                                              orderby index, property.Name
                                                              select property;

            IEnumerable<XAttribute> attributes = from property in informationProperties
                                                 let value = property.GetValue(node)
                                                 where value != null
                                                 select new XAttribute(property.Name, value);

            root.Add(attributes);

            IEnumerable<PropertyInfo> structureProperties = from property in nodeType.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                            where property.IsDefined(typeof(StructureAttribute), true)
                                                            let index = ((StructureAttribute)property.GetCustomAttributes(typeof(StructureAttribute), true).First()).Index
                                                            orderby index, property.Name
                                                            select property;

            List<XElement> elements = new List<XElement>();

            foreach (PropertyInfo structureProperty in structureProperties)
            {
                object propertyValue = structureProperty.GetValue(node);

                if (propertyValue != null)
                {
                    bool modified = false;

                    XElement element = new XElement(nodeName + "." + structureProperty.Name);

                    if (propertyValue is IEnumerable<IMNode>)
                    {
                        IEnumerable<IMNode> children = (IEnumerable<IMNode>)propertyValue;

                        if (children.Count() != 0)
                        {
                            foreach (IMNode child in children)
                            {
                                element.Add(NodeToXmlBuilder.BuildElement(child));

                                modified = true;
                            }
                        }
                    }
                    else if (propertyValue is IMNode)
                    {
                        element.Add(NodeToXmlBuilder.BuildElement((IMNode)propertyValue));

                        modified = true;
                    }

                    if (modified)
                    {
                        elements.Add(element);
                    }
                }
            }

            root.Add(elements);

            return root;
        }