public TECNetworkConnection(Guid guid, TECController parent, TECProtocol protocol) : base(guid)
 {
     this.IsTypical              = false;
     ParentController            = parent;
     this.protocol               = protocol;
     Children.CollectionChanged += Children_CollectionChanged;
 }
Пример #2
0
        protected void handleSubScopeRemoval(TECSubScope removed)
        {
            TECController controller = removed.Connection?.ParentController;

            if (controller != null)
            {
                controller.Disconnect(removed);
            }
        }
Пример #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);
 }
Пример #4
0
 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);
 }
Пример #5
0
 public void AddController(TECController controller)
 {
     _controllers.Add(controller);
     if (this.IsTypical)
     {
         ((ITypicalable)controller).MakeTypical();
     }
     notifyTECChanged(Change.Add, "Controllers", this, controller);
     notifyCostChanged(controller.CostBatch);
 }
Пример #6
0
 private void handleControllerChanged(TECController controller, string propertyName)
 {
     if (propertyName == "Type" && controller is TECProvidedController provided)
     {
         foreach (var instance in GetInstancesFromTypical(provided))
         {
             if (instance.CanChangeType(provided.Type))
             {
                 instance.ChangeType(provided.Type);
             }
         }
     }
 }
 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;
 }
Пример #8
0
 public void RemoveController(TECController controller)
 {
     controller.DisconnectAll();
     _controllers.Remove(controller);
     foreach (TECPanel panel in this.Panels)
     {
         if (panel.Controllers.Contains(controller))
         {
             panel.Controllers.Remove(controller);
         }
     }
     notifyCombinedChanged(Change.Remove, "Controllers", this, controller);
     CostChanged?.Invoke(-controller.CostBatch);
 }
Пример #9
0
        public bool RemoveController(TECController controller)
        {
            controller.DisconnectAll();
            bool success = _controllers.Remove(controller);

            foreach (TECPanel panel in this.Panels)
            {
                if (panel.Controllers.Contains(controller))
                {
                    panel.Controllers.Remove(controller);
                }
            }
            notifyTECChanged(Change.Remove, "Controllers", this, controller);
            notifyCostChanged(-controller.CostBatch);
            return(success);
        }
Пример #10
0
 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);
         }
     }
 }
Пример #11
0
 private void collectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, string collectionName)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         int       pointNumber  = 0;
         CostBatch costs        = new CostBatch();
         bool      pointChanged = false;
         bool      costChanged  = false;
         foreach (object item in e.NewItems)
         {
             if (item is INotifyPointChanged pointItem)
             {
                 pointNumber += pointItem.PointNumber;
                 pointChanged = true;
             }
             if (item is INotifyCostChanged costItem)
             {
                 costs      += costItem.CostBatch;
                 costChanged = true;
             }
             notifyCombinedChanged(Change.Add, collectionName, this, item);
             if (item is TECTypical typical)
             {
                 costChanged  = false;
                 pointChanged = false;
             }
         }
         if (pointChanged)
         {
             PointChanged?.Invoke(pointNumber);
         }
         if (costChanged)
         {
             CostChanged?.Invoke(costs);
         }
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         int       pointNumber  = 0;
         CostBatch costs        = new CostBatch();
         bool      pointChanged = false;
         bool      costChanged  = false;
         foreach (object item in e.OldItems)
         {
             if (item is INotifyPointChanged pointItem)
             {
                 pointNumber += pointItem.PointNumber;
                 pointChanged = true;
             }
             if (item is INotifyCostChanged costItem)
             {
                 costs      += costItem.CostBatch;
                 costChanged = true;
             }
             notifyCombinedChanged(Change.Remove, collectionName, this, item);
             if (item is TECTypical typ)
             {
                 if (typ.Instances.Count == 0)
                 {
                     costChanged  = false;
                     pointChanged = false;
                 }
                 foreach (TECSystem instance in typ.Instances)
                 {
                     foreach (TECSubScope subScope in instance.GetAllSubScope())
                     {
                         TECController parentController = subScope.Connection?.ParentController;
                         if (parentController != null && this.Controllers.Contains(parentController))
                         {
                             parentController.Disconnect(subScope);
                         }
                     }
                     foreach (TECController controller in instance.Controllers)
                     {
                         TECController parentController = controller.ParentConnection?.ParentController;
                         if (parentController != null && this.Controllers.Contains(parentController))
                         {
                             parentController.Disconnect(controller);
                         }
                     }
                 }
             }
         }
         if (pointChanged)
         {
             PointChanged?.Invoke(pointNumber * -1);
         }
         if (costChanged)
         {
             CostChanged?.Invoke(costs * -1);
         }
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move)
     {
         notifyCombinedChanged(Change.Edit, collectionName, this, sender, sender);
     }
 }
Пример #12
0
 public void AddController(TECController controller)
 {
     _controllers.Add(controller);
     notifyCombinedChanged(Change.Add, "Controllers", this, controller);
     CostChanged?.Invoke(controller.CostBatch);
 }
Пример #13
0
 public TECHardwiredConnection(IConnectable child, TECController parent, TECHardwiredProtocol protocol) : this(Guid.NewGuid(), child, parent, protocol)
 {
 }
 public TECNetworkConnection(TECController parent, TECProtocol protocol) : this(Guid.NewGuid(), parent, protocol)
 {
 }