Exemple #1
0
        /// <summary>
        /// Hardwarenode sends the package to specified destination.
        /// </summary>
        /// <param name="Destination">The destination.</param>
        /// <param name="Tags">Optional tags.</param>
        /// <param name="ValInfo">Validation Info</param>
        /// <returns>
        /// The Hardwarenode which received the package or null if an error occured
        /// </returns>
        public override List <Hardwarenode> Send(Hardwarenode Destination, Dictionary <string, object> Tags, ValidationInfo ValInfo)
        {
            List <Hardwarenode> nextNodes = new List <Hardwarenode>();

            foreach (Connection c in Connections.Values)
            {
                if (c.End.HasIp(ValInfo.NextNodeIp))
                {
                    nextNodes.Add(c.End);
                    return(nextNodes);
                }
                if (!c.Start.HasIp(ValInfo.NextNodeIp))
                {
                    continue;
                }
                nextNodes.Add(c.Start);
                return(nextNodes);
            }
            //Check if the next switch can send it
            foreach (Connection c in Connections.Values)
            {
                if (c.Start.Equals(this))
                {
                    Switch s = c.End as Switch;
                    if (s == null)
                    {
                        continue;
                    }
                    if (!s.SendToIp(ValInfo, c))
                    {
                        continue;
                    }
                    nextNodes.Insert(0, s);
                    return(nextNodes);
                }
                else
                {
                    Switch s = c.Start as Switch;
                    if (s == null)
                    {
                        continue;
                    }
                    if (!s.SendToIp(ValInfo, c))
                    {
                        continue;
                    }
                    nextNodes.Insert(0, s);
                    return(nextNodes);
                }
            }
            ValInfo.Res.ErrorId   = Result.Errors.SwitchNoConnection;
            ValInfo.Res.Res       = Result.ResultStrings[(int)ValInfo.Res.ErrorId];
            ValInfo.Res.SendError = true;
            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Sends to ip.
        /// </summary>
        /// <param name="ValInfo">The value information.</param>
        /// <param name="ComingConn">The coming connection.</param>
        /// <returns>Bool if it could send</returns>
        public bool SendToIp(ValidationInfo ValInfo, Connection ComingConn)
        {
            foreach (Connection c in Connections.Values)
            {
                if (c.End.HasIp(ValInfo.NextNodeIp))
                {
                    ValInfo.NextNodes.Add(c.End);
                    return(true);
                }
                if (!c.Start.HasIp(ValInfo.NextNodeIp))
                {
                    continue;
                }
                ValInfo.NextNodes.Add(c.Start);
                return(true);
            }
            //check if the next switch can send it
            foreach (Connection c in Connections.Values)
            {
                if (c == ComingConn)
                {
                    continue;
                }
                if (c.Start.Equals(this))
                {
                    Switch s = c.End as Switch;
                    if (s == null)
                    {
                        continue;
                    }
                    if (!s.SendToIp(ValInfo, c))
                    {
                        continue;
                    }
                    ValInfo.NextNodes.Insert(0, s);
                    return(true);
                }
                else
                {
                    Switch s = c.Start as Switch;
                    if (s == null)
                    {
                        continue;
                    }
                    if (!s.SendToIp(ValInfo, c))
                    {
                        continue;
                    }
                    ValInfo.NextNodes.Insert(0, s);
                    return(true);
                }
            }

            return(false);
        }