public virtual IControllerConnection Connect(IConnectable connectable, IProtocol protocol) { if (!CanConnect(connectable, protocol)) { return(null); } IControllerConnection connection; bool isNew = true; if (protocol is TECHardwiredProtocol wired) { connection = new TECHardwiredConnection(connectable, this, wired); } else if (protocol is TECProtocol network) { TECNetworkConnection netConnect = ChildrenConnections.Where(x => x.Protocol == protocol).FirstOrDefault() as TECNetworkConnection; isNew = netConnect == null; if (isNew) { netConnect = new TECNetworkConnection(this, network); } netConnect.AddChild(connectable); connection = netConnect; } else { throw new NotSupportedException("Unrecognized type implements IProtocol"); } if (isNew) { this.ChildrenConnections.Add(connection); } return(connection); }
protected override CostBatch getCosts() { if (!IsTypical) { CostBatch costs = base.getCosts(); foreach (IControllerConnection connection in ChildrenConnections.Where(connection => !connection.IsTypical)) { costs += connection.CostBatch; } return(costs); } else { return(new CostBatch()); } }
public void RemoveAllChildNetworkConnections() { List <IControllerConnection> networkConnections = new List <IControllerConnection>(ChildrenConnections.Where(connection => connection is TECNetworkConnection)); networkConnections.ForEach(netConnect => RemoveNetworkConnection(netConnect as TECNetworkConnection)); }