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); }
public TECNetworkConnection AddNetworkConnection(TECProtocol protocol) { if (!CanAddNetworkConnection(protocol)) { return(null); } TECNetworkConnection netConnect = new TECNetworkConnection(this, protocol); this.ChildrenConnections.Add(netConnect); return(netConnect); }
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 RemoveNetworkConnection(TECNetworkConnection connection) { if (this.ChildrenConnections.Contains(connection)) { List <IConnectable> children = new List <IConnectable>(connection.Children); foreach (IConnectable child in children) { connection.RemoveChild(child); } return(this.ChildrenConnections.Remove(connection)); } else { return(false); } }
public void UpdateInstanceConnections() { foreach (TECSystem system in Instances) { var systemConnectables = system.GetAll <IConnectable>(); foreach (TECController controller in Controllers) { var instanceController = TypicalInstanceDictionary.GetInstances(controller).First(x => system.Controllers.Contains(x)); instanceController.RemoveAllChildConnections(); foreach (IControllerConnection connection in controller.ChildrenConnections) { List <IControllerConnection> instanceConnections = new List <IControllerConnection>(); if (connection is TECNetworkConnection netConnection) { TECNetworkConnection netInstanceConnection = instanceController.AddNetworkConnection(netConnection.NetworkProtocol); var instanceChildren = netConnection.Children.SelectMany(x => TypicalInstanceDictionary.GetInstances(x)); foreach (IConnectable instanceChild in instanceChildren) { if (systemConnectables.Contains(instanceChild)) { netInstanceConnection.AddChild(instanceChild); } } instanceConnections.Add(netInstanceConnection); } else if (connection is TECHardwiredConnection hardwired) { var instanceChildren = TypicalInstanceDictionary.GetInstances(hardwired.Child); foreach (IConnectable instanceChild in instanceChildren) { if (systemConnectables.Contains(instanceChild)) { instanceConnections.Add(instanceController.Connect(instanceChild, connection.Protocol)); } } } instanceConnections.Where(x => x != null).ForEach(x => x.UpdatePropertiesBasedOn(connection)); } } } }
public TECController(TECController controllerSource, Dictionary <Guid, Guid> guidDictionary = null) : this() { if (guidDictionary != null) { guidDictionary[_guid] = controllerSource.Guid; } copyPropertiesFromLocated(controllerSource); foreach (IControllerConnection connection in controllerSource.ChildrenConnections) { if (connection is TECHardwiredConnection) { TECHardwiredConnection connectionToAdd = new TECHardwiredConnection(connection as TECHardwiredConnection, this, guidDictionary); ChildrenConnections.Add(connectionToAdd); } else if (connection is TECNetworkConnection) { TECNetworkConnection connectionToAdd = new TECNetworkConnection(connection as TECNetworkConnection, this, guidDictionary); ChildrenConnections.Add(connectionToAdd); } } }
public bool CanConnectToNetwork(TECNetworkConnection netConnect) { return(this.AvailableProtocols.Contains(netConnect.Protocol)); }