/// <summary> /// Removes the connectable from controller and parent connection. /// </summary> /// <param name="connectable">Child</param> /// <returns>Parent network connnection if applicable</returns> public TECNetworkConnection Disconnect(IConnectable connectable) { IControllerConnection connectionToRemove = null; foreach (IControllerConnection connection in ChildrenConnections) { if (connection is TECHardwiredConnection hardwiredConnection) { if (hardwiredConnection.Child == connectable) { connectionToRemove = hardwiredConnection; connectable.SetParentConnection(null); break; } } else if (connection is TECNetworkConnection netConnect) { if (netConnect.Children.Contains(connectable)) { netConnect.RemoveChild(connectable); connectable.SetParentConnection(null); return(netConnect); } } } if (connectionToRemove != null) { this.ChildrenConnections.Remove(connectionToRemove); } return(null); }
public TECHardwiredConnection(TECHardwiredConnection linkingSource, IConnectable child, bool isTypical) : base(linkingSource) { Child = child; ParentController = linkingSource.ParentController; ConnectionTypes = linkingSource.ConnectionTypes; child.SetParentConnection(this); _guid = linkingSource.Guid; }
public TECHardwiredConnection(Guid guid, IConnectable child, TECController controller, TECHardwiredProtocol protocol) : base(guid) { this.IsTypical = false; Child = child; ConnectionTypes = new ObservableCollection <TECConnectionType>(protocol.ConnectionTypes); ConnectionTypes.CollectionChanged += connectionTypesCollectionChanged; ParentController = controller; child.SetParentConnection(this); }
public void AddChild(IConnectable connectable) { if (CanAddChild(connectable)) { connectable.SetParentConnection(this); Children.Add(connectable); } else { throw new InvalidOperationException("Connectable not compatible with Network Connection."); } }
public TECNetworkConnection(TECNetworkConnection connectionSource, TECController parent, Dictionary <Guid, Guid> guidDictionary = null) : base(connectionSource, guidDictionary) { Children.CollectionChanged += Children_CollectionChanged; foreach (IConnectable item in connectionSource.Children) { IConnectable newChild = item.Copy(guidDictionary); newChild.SetParentConnection(this); _children.Add(newChild); } ParentController = parent; this.protocol = connectionSource.protocol; }
public bool RemoveChild(IConnectable connectable) { if (Children.Contains(connectable)) { var removed = Children.Remove(connectable); connectable.SetParentConnection(null); return(removed); } else { return(false); } }