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);
        }
Example #2
0
 public TECHardwiredConnection(TECHardwiredConnection linkingSource, IConnectable child, bool isTypical) : base(linkingSource)
 {
     Child            = child;
     ParentController = linkingSource.ParentController;
     ConnectionTypes  = linkingSource.ConnectionTypes;
     child.SetParentConnection(this);
     _guid = linkingSource.Guid;
 }
Example #3
0
 public TECHardwiredConnection(TECHardwiredConnection connectionSource, TECController parent, Dictionary <Guid, Guid> guidDictionary = null)
     : base(connectionSource, guidDictionary)
 {
     Child            = connectionSource.Child.Copy(guidDictionary);
     ParentController = parent;
     ConnectionTypes  = new ObservableCollection <TECConnectionType>(connectionSource.ConnectionTypes);
     ConnectionTypes.CollectionChanged += connectionTypesCollectionChanged;
     Child.SetParentConnection(this);
 }
 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);
         }
     }
 }