Exemple #1
0
        protected void handleSubScopeRemoval(TECSubScope removed)
        {
            TECController controller = removed.Connection?.ParentController;

            if (controller != null)
            {
                controller.Disconnect(removed);
            }
        }
 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);
     }
 }