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); } } } }
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); } }
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)); } } } }
public List <T> GetInstancesFromTypical <T>(T typical) where T : ITECObject { return(TypicalInstanceDictionary.GetInstances(typical)); }