/// <summary> /// Hardwarenode sends the package to specified destination. /// </summary> /// <param name="Destination">The destination.</param> /// <param name="Tags">Optional tags.</param> /// <param name="ValInfo"></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) { ValInfo.NextNodes = new List <Hardwarenode>(); ValInfo.Iface = null; for (int i = Layerstack.GetSize() - 1; i >= 0; i--) { int customLayerCount = 0; //Calculate the custom layer count before this layer for (int j = 0; j < i; j++) { if (Layerstack.GetLayer(j) is CustomLayer) { customLayerCount++; } } if (ValInfo.NextNodes == null) { continue; } Workstation dest = Destination as Workstation; if (dest != null) { Layerstack.GetLayer(i).ValidateSend(dest, this, ValInfo, Tags, i - customLayerCount); } else { throw new ArgumentException("Destination is no Workstation."); } } return(ValInfo.NextNodes); }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="Other">The other.</param> /// <returns></returns> public bool Equals(Hardwarenode Other) { if (Other == null) { return(false); } return(string.Equals(Name, Other.Name)); }
/// <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); }
/// <summary> /// Determines whether the specified <see cref="System.Object" />, is equal to this instance. /// </summary> /// <param name="Obj">The <see cref="System.Object" /> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>. /// </returns> public override bool Equals(object Obj) { // If parameter cannot be cast to Hardwarenode return false. Hardwarenode h = Obj as Hardwarenode; if (h == null) { return(false); } // Return true if the fields match: return(string.Equals(Name, h.Name)); }
/// <summary> /// Hardwarenode receives the package. /// </summary> /// <param name="Tags">Optional tags.</param> /// <param name="ValInfo">The validation Info</param> /// <param name="Destination">The destination</param> /// <returns> /// bool that indicates if the Hardwarenode received the package /// </returns> public override bool Receive(Dictionary <string, object> Tags, ValidationInfo ValInfo, Hardwarenode Destination) { bool res = true; int customLayerCount = 0; for (int i = 0; i < Layerstack.GetSize(); i++) { if (!res) { continue; } res = Layerstack.GetLayer(i).ValidateReceive(this, ValInfo, Tags, Destination, i - customLayerCount); if (Layerstack.GetLayer(i) is CustomLayer) { customLayerCount++; } } return(res); }
/// <summary> /// Initializes a new instance of the <see cref="Connection" /> class. /// </summary> /// <param name="Source">The sourcenode.</param> /// <param name="Target">The targetnode.</param> public Connection(Hardwarenode Source, Hardwarenode Target) { Start = Source; End = Target; Name = Guid.NewGuid().ToString("N"); }
/// <summary> /// Gets the index of the port. /// </summary> /// <param name="Node">The node.</param> /// <returns>Portindex</returns> public int GetPortIndex(Hardwarenode Node) { return(Node.GetPortIndexOfConnection(this)); }
/// <summary> /// Adds a hardwarenode. /// </summary> /// <param name="NewNode">The new node.</param> public void AddHardwarenode(Hardwarenode NewNode) { nodes.Add(NewNode); }
/// <summary> /// Hardwarenode receives the package. /// </summary> /// <param name="Tags">Optional tags.</param> /// <param name="ValInfo">The validation Info</param> /// <param name="Destination">The destination.</param> /// <returns> /// If the Hardwarenode could receive the package /// </returns> public virtual bool Receive(Dictionary <string, object> Tags, ValidationInfo ValInfo, Hardwarenode Destination) { return(true); }
/// <summary> /// Hardwarenode sends the package to specified destination. /// </summary> /// <param name="Destination">The destination.</param> /// <param name="Tags">Optional tags.</param> /// <param name="ValInfo"></param> /// <returns>The Hardwarenode which received the package or null if an error occured</returns> public virtual List <Hardwarenode> Send(Hardwarenode Destination, Dictionary <string, object> Tags, ValidationInfo ValInfo) { return(null); }