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 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 void RemoveAllChildNetworkConnections()
        {
            List <IControllerConnection> networkConnections = new List <IControllerConnection>(ChildrenConnections.Where(connection => connection is TECNetworkConnection));

            networkConnections.ForEach(netConnect => RemoveNetworkConnection(netConnect as TECNetworkConnection));
        }