/// <summary> /// Adds a connector with a hitch at the given reference point, referencing the parent DeviceElement as the DeviceElementConfiguration /// </summary> /// <param name="rootDeviceHierarchy"></param> /// <param name="connectorDeviceElement"></param> /// <param name="deviceElement"></param> private void AddConnector(DeviceHierarchyElement rootDeviceHierarchy, ISODeviceElement connectorDeviceElement) { //Per the TC-GEO specification, the connector is always a child of the root device element. DeviceHierarchyElement hierarchyElement = rootDeviceHierarchy.FromDeviceElementID(connectorDeviceElement.DeviceElementId); if (hierarchyElement.Parent == rootDeviceHierarchy) { int?rootDeviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(rootDeviceHierarchy.DeviceElement.DeviceElementId); if (rootDeviceElementID.HasValue) { HitchPoint hitch = new HitchPoint(); hitch.ReferencePoint = new ReferencePoint() { XOffset = hierarchyElement.XOffsetRepresentation, YOffset = hierarchyElement.YOffsetRepresentation, ZOffset = hierarchyElement.ZOffsetRepresentation }; hitch.HitchTypeEnum = HitchTypeEnum.Unkown; DataModel.Catalog.HitchPoints.Add(hitch); //Get the DeviceElementConfiguration for the root element in order that we may link the Connector to it. DeviceElement root = DataModel.Catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == rootDeviceElementID); if (root != null) { DeviceElementConfiguration rootDeviceConfiguration = DeviceElementMapper.GetDeviceElementConfiguration(root, rootDeviceHierarchy, DataModel.Catalog); if (rootDeviceConfiguration != null) { Connector connector = new Connector(); ImportIDs(connector.Id, hierarchyElement.DeviceElement.DeviceElementId); connector.DeviceElementConfigurationId = rootDeviceConfiguration.Id.ReferenceId; connector.HitchPointId = hitch.Id.ReferenceId; DataModel.Catalog.Connectors.Add(connector); //The ID mapping will link the ADAPT Connector to the ISO Device Element TaskDataMapper.InstanceIDMap.Add(connector.Id.ReferenceId, connectorDeviceElement.DeviceElementId); } } } } }
private void UpdateCondensedWorkingDatas(List <ISOEnumeratedMeter> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceHierarchyElement isoDeviceElementHierarchy) { ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef); List <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section).ToList(); foreach (var subElement in isoDeviceElement.ChildDeviceElements) { //This handles cases where the condensed workstate is reported on a top-level boom with sub-booms in the hierarchy above the sections (e.g., ISO 11783-10:2015(E) Figure F.35) isoSectionElements.AddRange(subElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section).ToList()); } //We have some sections in the DDOP if (isoSectionElements.Count > 0) { //Update the DeviceElementReference on the Condensed WorkingDatas foreach (var workingData in condensedWorkingDatas) { if (workingData.SectionIndex - 1 >= isoSectionElements.Count) { break; } ISODeviceElement targetSection = isoSectionElements[workingData.SectionIndex - 1]; DeviceElementUse condensedDeviceElementUse = FindExistingDeviceElementUseForCondensedData(targetSection, pendingDeviceElementUses); if (condensedDeviceElementUse == null) { //Make a new DeviceElementUse condensedDeviceElementUse = new DeviceElementUse(); condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId; int?deviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId); if (deviceElementID.HasValue) { DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value); if (deviceElement != null) { //Reference the device element in its hierarchy so that we can get the depth & order DeviceHierarchyElement deviceElementInHierarchy = isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId); //Get the config id DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, deviceElementInHierarchy, DataModel.Catalog); condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId; //Set the depth & order condensedDeviceElementUse.Depth = deviceElementInHierarchy.Depth; condensedDeviceElementUse.Order = deviceElementInHierarchy.Order; } } condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> { workingData }; workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId; pendingDeviceElementUses.Add(condensedDeviceElementUse); } else { //Use the existing DeviceElementUse List <WorkingData> data = new List <WorkingData>(); IEnumerable <WorkingData> existingWorkingDatas = condensedDeviceElementUse.GetWorkingDatas(); if (existingWorkingDatas != null) { data.AddRange(existingWorkingDatas.ToList()); //Add the preexisting } data.Add(workingData); condensedDeviceElementUse.GetWorkingDatas = () => data; } } } }