Beispiel #1
0
        private void handleInstanceRemoved(TECSystem instance)
        {
            connectionInstances.RemoveValuesForKeys(instance.Controllers.SelectMany(x => x.ChildrenConnections), this.Controllers.SelectMany(x => x.ChildrenConnections));
            instance.Controllers.ForEach(x => x.DisconnectAll());
            TypicalInstanceDictionary.RemoveValuesForKeys(instance.Panels, Panels);
            TypicalInstanceDictionary.RemoveValuesForKeys(instance.Equipment, Equipment);

            var typicalSubScope = GetAllSubScope();

            foreach (TECEquipment instanceEquip in instance.Equipment)
            {
                TypicalInstanceDictionary.RemoveValuesForKeys(instanceEquip.SubScope, typicalSubScope);
                foreach (TECSubScope instanceSubScope in instanceEquip.SubScope)
                {
                    if (instanceSubScope.Connection != null && !instance.Controllers.Contains(instanceSubScope.Connection.ParentController))
                    {
                        instanceSubScope.Connection.ParentController.Disconnect(instanceSubScope);
                    }
                    foreach (TECSubScope subScope in typicalSubScope)
                    {
                        TypicalInstanceDictionary.RemoveValuesForKeys(instanceSubScope.Points, subScope.Points);
                        TypicalInstanceDictionary.RemoveValuesForKeys(instanceSubScope.Interlocks, subScope.Interlocks);
                    }
                }
            }
            TypicalInstanceDictionary.RemoveValuesForKeys(instance.Controllers, Controllers);
            TypicalInstanceDictionary.RemoveValuesForKeys(instance.MiscCosts, MiscCosts);
            TypicalInstanceDictionary.RemoveValuesForKeys(instance.ScopeBranches, ScopeBranches);
        }
Beispiel #2
0
 private void buildConnectionDictionary(TECSystem system, ObservableListDictionary <IControllerConnection> currentDictionary)
 {
     foreach (TECController controller in Controllers)
     {
         var controllerInstances = TypicalInstanceDictionary.GetInstances(controller);
         foreach (IControllerConnection connection in controller.ChildrenConnections)
         {
             List <IConnectable> instanceConnectables = system.GetAll <IConnectable>();
             if (connection is TECNetworkConnection netConnect)
             {
                 var instanceConnection = controllerInstances.Where(x => system.Controllers.Contains(x))
                                          .SelectMany(x => x.ChildrenConnections)
                                          .OfType <TECNetworkConnection>()
                                          .Where(x => x.Children.SequenceEqual(netConnect.Children.SelectMany(y => TypicalInstanceDictionary.GetInstances(y).Where(z => instanceConnectables.Contains(z)))))
                                          .FirstOrDefault();
                 currentDictionary.AddItem(connection, instanceConnection);
             }
             else if (connection is TECHardwiredConnection hardConnect)
             {
                 var instanceConnection = controllerInstances.Where(x => system.Controllers.Contains(x))
                                          .SelectMany(x => x.ChildrenConnections)
                                          .OfType <TECHardwiredConnection>()
                                          .Where(x => x.Child == TypicalInstanceDictionary.GetInstances(hardConnect.Child).Where(z => instanceConnectables.Contains(z)).FirstOrDefault())
                                          .FirstOrDefault();
                 currentDictionary.AddItem(connection, instanceConnection);
             }
         }
     }
 }
Beispiel #3
0
        public TECSystem AddInstance()
        {
            Dictionary <Guid, Guid> guidDictionary = new Dictionary <Guid, Guid>();
            var newSystem = new TECSystem();

            newSystem.CopyPropertiesFromScope(this);
            if (this.Location != null)
            {
                newSystem.Location = this.Location;
            }
            foreach (TECEquipment equipment in Equipment)
            {
                var toAdd = new TECEquipment(equipment, guidDictionary, TypicalInstanceDictionary);
                TypicalInstanceDictionary.AddItem(equipment, toAdd);
                newSystem.Equipment.Add(toAdd);
            }
            foreach (TECController controller in Controllers)
            {
                var toAdd = controller.CopyController(guidDictionary);
                TypicalInstanceDictionary.AddItem(controller, toAdd);
                newSystem.AddController(toAdd);
            }
            foreach (TECPanel panel in Panels)
            {
                var toAdd = new TECPanel(panel, guidDictionary);
                TypicalInstanceDictionary.AddItem(panel, toAdd);
                newSystem.Panels.Add(toAdd);
            }
            foreach (TECMisc misc in MiscCosts)
            {
                var toAdd = new TECMisc(misc);
                TypicalInstanceDictionary.AddItem(misc, toAdd);
                newSystem.MiscCosts.Add(toAdd);
            }
            foreach (TECScopeBranch branch in ScopeBranches)
            {
                var toAdd = new TECScopeBranch(branch);
                TypicalInstanceDictionary.AddItem(branch, toAdd);
                newSystem.ScopeBranches.Add(toAdd);
            }
            //Proposal items are not currently synced to instances
            //foreach(TECProposalItem propItem in ProposalItems)
            //{
            //    var toAdd = new TECProposalItem(propItem);
            //    TypicalInstanceDictionary.AddItem(propItem, toAdd);
            //    newSystem.ProposalItems.Add(toAdd);
            //}
            ModelLinkingHelper.LinkSystem(newSystem, guidDictionary);

            Instances.Add(newSystem);
            return(newSystem);
        }
Beispiel #4
0
        private void handleAdd(TECChangedEventArgs args)
        {
            ITypicalable      sender          = args.Sender as ITypicalable;
            List <ITECObject> parentInstances = new List <ITECObject>();

            if (args.Sender is TECTypical typ)
            {
                parentInstances.AddRange(Instances);
            }
            else
            {
                parentInstances = TypicalInstanceDictionary.GetInstances(sender as ITECObject);
            }
            foreach (ITECObject parentInstance in parentInstances)
            {
                ITypicalable instanceSender = parentInstance as ITypicalable;

                if (instanceSender == null)
                {
                    throw new Exception("Change occured from object which is not typicalable");
                }
                ITECObject instanceValue = args.Value as ITECObject;
                if (instanceValue == null)
                {
                    throw new Exception("Value to add is not ITECObject");
                }
                if (args.Value is ITypicalable typicalChild)
                {
                    if (sender is IRelatable relSender && relSender.IsDirectChildProperty(args.PropertyName))
                    {
                        instanceValue = typicalChild.CreateInstance(TypicalInstanceDictionary);
                        if (instanceValue != null)
                        {
                            TypicalInstanceDictionary.AddItem(args.Value as ITECObject, instanceValue);
                        }
                    }
                    else
                    {
                        var parentSystem = this.Instances
                                           .Where(x => x.IsDirectDescendant(parentInstance))
                                           .FirstOrDefault();

                        instanceValue = this.TypicalInstanceDictionary.GetInstances(typicalChild)
                                        .Where(x => parentSystem.IsDirectDescendant(x)).FirstOrDefault();
                    }
                }
                if (instanceValue != null)
                {
                    instanceSender.AddChildForProperty(args.PropertyName, instanceValue);
                }
            }
Beispiel #5
0
        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));
                    }
                }
            }
        }
Beispiel #6
0
 public List <T> GetInstancesFromTypical <T>(T typical) where T : ITECObject
 {
     return(TypicalInstanceDictionary.GetInstances(typical));
 }