private static SpatialValue CreateSpatialValue(ISOTime templateTime, byte order, int value) { var dataLogValues = templateTime.DataLogValues; var matchingDlv = dataLogValues.ElementAtOrDefault(order); if (matchingDlv == null) { return(null); } var ddis = DdiLoader.Ddis; var resolution = 1d; if (matchingDlv.ProcessDataDDI != null && ddis.ContainsKey(matchingDlv.ProcessDataDDI.AsInt32DDI())) { resolution = ddis[matchingDlv.ProcessDataDDI.AsInt32DDI()].Resolution; } var spatialValue = new SpatialValue { Id = order, DataLogValue = matchingDlv, Value = value * resolution, }; return(spatialValue); }
public void SetHitchOffsetsFromSpatialData(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, HitchPoint hitchPoint, RepresentationMapper representationMapper) { if (hitchPoint.ReferencePoint == null) { hitchPoint.ReferencePoint = new ReferencePoint(); } if (XOffset == null) { XOffset = GetXOffsetFromSpatialData(time, isoRecords, DeviceElement.DeviceElementId, representationMapper); hitchPoint.ReferencePoint.XOffset = XOffsetRepresentation; } if (YOffset == null) { YOffset = GetYOffsetFromSpatialData(time, isoRecords, DeviceElement.DeviceElementId, representationMapper); hitchPoint.ReferencePoint.YOffset = YOffsetRepresentation; } if (ZOffset == null) { ZOffset = GetZOffsetFromSpatialData(time, isoRecords, DeviceElement.DeviceElementId, representationMapper); hitchPoint.ReferencePoint.ZOffset = ZOffsetRepresentation; } }
private OperationTypeEnum GetOperationTypeFromLoggingDevices(ISOTime time) { HashSet <DeviceOperationType> representedTypes = new HashSet <DeviceOperationType>(); IEnumerable <string> distinctDeviceElementIDs = time.DataLogValues.Select(d => d.DeviceElementIdRef).Distinct(); foreach (string isoDeviceElementID in distinctDeviceElementIDs) { int?deviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID); if (deviceElementID.HasValue) { DeviceElement deviceElement = DataModel.Catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == deviceElementID.Value); if (deviceElement != null && deviceElement.DeviceClassification != null) { DeviceOperationType deviceOperationType = DeviceOperationTypes.FirstOrDefault(d => d.MachineEnumerationMember.ToModelEnumMember().Value == deviceElement.DeviceClassification.Value.Value); if (deviceOperationType != null) { representedTypes.Add(deviceOperationType); } } } } DeviceOperationType deviceType = representedTypes.FirstOrDefault(t => t.ClientNAMEMachineType >= 2 && t.ClientNAMEMachineType <= 11); if (deviceType != null) { //2-11 represent known types of operations //These will map to implement devices and will govern the actual operation type. //Return the first such device type return(deviceType.OperationType); } return(OperationTypeEnum.Unknown); }
private List <TimeLogWrapperGroup> GroupByDataLogValueCount(ISOTask loggedTask, string dataPath) { // All consequent time logs with 255 DLVs are kept together as a group. var timeLogGroups = new List <TimeLogWrapperGroup>(); var logGroup = new TimeLogWrapperGroup(); foreach (var timeLog in loggedTask.TimeLogs) { ISOTime templateTime = timeLog.GetTimeElement(dataPath); if (templateTime != null) { logGroup.Add(new TimeLogWrapper { DataLogValues = templateTime.DataLogValues, ISOTimeLog = timeLog }); // A time log with less than 255 DLVs found. Add it to current group // and start a new one. if (templateTime.DataLogValues.Count < 255) { timeLogGroups.Add(logGroup); logGroup = new TimeLogWrapperGroup(); } } } // Add remaning log group if (logGroup.Count > 0) { timeLogGroups.Add(logGroup); } return(timeLogGroups); }
private static SpatialValue CreateSpatialValue(ISOTime templateTime, byte order, int value, DeviceElementHierarchies deviceHierarchies) { var dataLogValues = templateTime.DataLogValues; var matchingDlv = dataLogValues.ElementAtOrDefault(order); if (matchingDlv == null) { return(null); } ISODeviceElement det = deviceHierarchies.GetISODeviceElementFromID(matchingDlv.DeviceElementIdRef); ISODevice dvc = det?.Device; ISODeviceProcessData dpd = dvc?.DeviceProcessDatas?.FirstOrDefault(d => d.DDI == matchingDlv.ProcessDataDDI); var ddis = DdiLoader.Ddis; var resolution = 1d; if (matchingDlv.ProcessDataDDI != null && ddis.ContainsKey(matchingDlv.ProcessDataDDI.AsInt32DDI())) { resolution = ddis[matchingDlv.ProcessDataDDI.AsInt32DDI()].Resolution; } var spatialValue = new SpatialValue { Id = order, DataLogValue = matchingDlv, Value = value * resolution, DeviceProcessData = dpd }; return(spatialValue); }
private int?GetZOffsetFromSpatialData(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, string isoDeviceElementID, RepresentationMapper representationMapper) { if (time.DataLogValues.Any(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0088")) { ISODataLogValue dlv = time.DataLogValues.First(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0088"); if (dlv.ProcessDataValue.HasValue) { //Fixed value return(dlv.ProcessDataValue.Value); } else { //Look for first matching record in binary ISOSpatialRow firstZOffset = isoRecords.FirstOrDefault(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0088")); if (firstZOffset != null) { double offset = firstZOffset.SpatialValues.First(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0088").Value; return((int)offset); } } } return(null); }
public List <WorkingData> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoSpatialRows, DeviceElementUse deviceElementUse, DeviceElementHierarchy isoDeviceElementHierarchy, List <DeviceElementUse> pendingDeviceElementUses) { var workingDatas = new List <WorkingData>(); //Set orders on the collection of DLVs var allDLVs = time.DataLogValues; for (int order = 0; order < allDLVs.Count(); order++) { var dlv = allDLVs.ElementAt(order); dlv.Order = order; } //Add the Working Datas for this DeviceElement IEnumerable <ISODataLogValue> deviceElementDLVs = allDLVs.Where(dlv => dlv.DeviceElementIdRef == isoDeviceElementHierarchy.DeviceElement.DeviceElementId); foreach (ISODataLogValue dlv in deviceElementDLVs) { IEnumerable <WorkingData> newWorkingDatas = Map(dlv, isoSpatialRows, deviceElementUse, dlv.Order, pendingDeviceElementUses, isoDeviceElementHierarchy); if (newWorkingDatas.Count() > 0) { int ddi = dlv.ProcessDataDDI.AsInt32DDI(); if (!EnumeratedMeterFactory.IsCondensedMeter(ddi)) { //We skip adding Condensed WorkingDatas to this DeviceElementUse since they were added separately below to their specific DeviceElementUse workingDatas.AddRange(newWorkingDatas); } } } return(workingDatas); }
private IEnumerable <OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLog isoTimeLog, int?prescriptionID) { WorkingDataMapper workingDataMapper = new WorkingDataMapper(new EnumeratedMeterFactory(), TaskDataMapper); SectionMapper sectionMapper = new SectionMapper(workingDataMapper, TaskDataMapper); SpatialRecordMapper spatialMapper = new SpatialRecordMapper(new RepresentationValueInterpolator(), sectionMapper, workingDataMapper); IEnumerable <ISOSpatialRow> isoRecords = ReadTimeLog(isoTimeLog, this.TaskDataPath); if (isoRecords != null) { isoRecords = isoRecords.ToList(); //Avoids multiple reads ISOTime time = isoTimeLog.GetTimeElement(this.TaskDataPath); //Identify unique devices represented in this TimeLog data IEnumerable <string> deviceElementIDs = time.DataLogValues.Where(d => d.ProcessDataDDI != "DFFF" && d.ProcessDataDDI != "DFFE").Select(d => d.DeviceElementIdRef); Dictionary <ISODevice, HashSet <string> > loggedDeviceElementsByDevice = new Dictionary <ISODevice, HashSet <string> >(); foreach (string deviceElementID in deviceElementIDs) { ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(deviceElementID); if (isoDeviceElement != null) { ISODevice device = isoDeviceElement.Device; if (!loggedDeviceElementsByDevice.ContainsKey(device)) { loggedDeviceElementsByDevice.Add(device, new HashSet <string>()); } loggedDeviceElementsByDevice[device].Add(deviceElementID); } } //Split all devices in the same TimeLog into separate OperationData objects to handle multi-implement scenarios //This will ensure implement geometries/DeviceElementUse Depths & Orders do not get confused between implements List <OperationData> operationDatas = new List <OperationData>(); foreach (ISODevice dvc in loggedDeviceElementsByDevice.Keys) { OperationData operationData = new OperationData(); //This line will necessarily invoke a spatial read in order to find //1)The correct number of CondensedWorkState working datas to create //2)Any Widths and Offsets stored in the spatial data IEnumerable <DeviceElementUse> sections = sectionMapper.Map(time, isoRecords, operationData.Id.ReferenceId, loggedDeviceElementsByDevice[dvc]); var workingDatas = sections != null?sections.SelectMany(x => x.GetWorkingDatas()).ToList() : new List <WorkingData>(); var sectionsSimple = sectionMapper.ConvertToBaseTypes(sections.ToList()); operationData.GetSpatialRecords = () => spatialMapper.Map(isoRecords, workingDatas); operationData.MaxDepth = sections.Count() > 0 ? sections.Select(s => s.Depth).Max() : 0; operationData.GetDeviceElementUses = x => x == 0 ? sectionsSimple : new List <DeviceElementUse>(); operationData.PrescriptionId = prescriptionID; operationData.OperationType = GetOperationTypeFromLoggingDevices(time); operationData.ProductId = GetProductIDForOperationData(loggedTask, dvc); operationData.SpatialRecordCount = isoRecords.Count(); operationDatas.Add(operationData); } return(operationDatas); } return(null); }
public override IEnumerable <OperationData> ImportTimeLogs(ISOTask loggedTask, IEnumerable <ISOTimeLog> timeLogs, int?prescriptionID) { _timeLogs = timeLogs; // Combine ISOTime elements from each TimeLog into one. _combinedTime = CreateCombinedTime(); // Read data from all timelogs as if it was a single file. // Pass first available TimeLog to avoid breaking base class. return(ImportTimeLog(loggedTask, timeLogs.First(), prescriptionID)); }
public List <DeviceElementUse> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, int operationDataId, IEnumerable <string> isoDeviceElementIDs) { var sections = new List <DeviceElementUse>(); foreach (string isoDeviceElementID in isoDeviceElementIDs) { DeviceElementHierarchy hierarchy = TaskDataMapper.DeviceElementHierarchies.GetRelevantHierarchy(isoDeviceElementID); if (hierarchy != null) { DeviceElementUse deviceElementUse = null; List <WorkingData> workingDatas = new List <WorkingData>(); //Get the relevant DeviceElementConfiguration int adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value; DeviceElement adaptDeviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId); if (adaptDeviceElement != null) { DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchy, DataModel.Catalog); int depth = hierarchy.Depth; int order = hierarchy.Order; if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId) { //The configuration references the parent ISO element depth = hierarchy.Parent.Depth; order = hierarchy.Parent.Order; } //Read any spatially-listed widths/offsets on this data onto the DeviceElementConfiguration objects hierarchy.SetWidthsAndOffsetsFromSpatialData(isoRecords, config, RepresentationMapper); //Create the DeviceElementUse deviceElementUse = new DeviceElementUse(); deviceElementUse.Depth = depth; deviceElementUse.Order = order; deviceElementUse.OperationDataId = operationDataId; deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId; //Add Working Data for any data on this device element List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections); if (data.Any()) { workingDatas.AddRange(data); } deviceElementUse.GetWorkingDatas = () => workingDatas; if (!sections.Contains(deviceElementUse)) { sections.Add(deviceElementUse); } } } } return(sections); }
private IEnumerable <ISOSpatialRow> ReadTimeLog(ISOTimeLog timeLog, string dataPath) { ISOTime templateTime = timeLog.GetTimeElement(dataPath); string filePath = Path.Combine(dataPath, string.Concat(timeLog.Filename, ".bin")); if (templateTime != null && File.Exists(filePath)) { BinaryReader reader = new BinaryReader(); return(reader.Read(filePath, templateTime)); } return(null); }
protected virtual IEnumerable <ISOSpatialRow> ReadTimeLog(ISOTimeLog timeLog, string dataPath) { ISOTime templateTime = timeLog.GetTimeElement(dataPath); string binName = string.Concat(timeLog.Filename, ".bin"); string filePath = dataPath.GetDirectoryFiles(binName, SearchOption.TopDirectoryOnly).FirstOrDefault(); if (templateTime != null && filePath != null) { return(BinaryReader.Read(filePath, templateTime, TaskDataMapper.DeviceElementHierarchies)); } return(null); }
public List <WorkingData> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoSpatialRows, DeviceElementUse deviceElementUse, DeviceElementHierarchy isoDeviceElementHierarchy, List <DeviceElementUse> pendingDeviceElementUses, Dictionary <string, List <ISOProductAllocation> > isoProductAllocations) { var workingDatas = new List <WorkingData>(); //Set orders on the collection of DLVs var allDLVs = time.DataLogValues; for (int order = 0; order < allDLVs.Count(); order++) { var dlv = allDLVs.ElementAt(order); dlv.Order = order; } //Create vrProductIndex on relevant device elements if more than one product on this OperationData if (TimeLogMapper.GetDistinctProductIDs(TaskDataMapper, isoProductAllocations).Count > 1 && isoProductAllocations.Keys.Contains(isoDeviceElementHierarchy.DeviceElement.DeviceElementId)) { WorkingData workingData = CreateProductIndexWorkingData(deviceElementUse.Id.ReferenceId); ISODeviceElementIDsByWorkingDataID.Add(workingData.Id.ReferenceId, isoDeviceElementHierarchy.DeviceElement.DeviceElementId); workingDatas.Add(workingData); } //Add the Working Datas for this DeviceElement IEnumerable <ISODataLogValue> deviceElementDLVs = allDLVs.Where(dlv => dlv.DeviceElementIdRef == isoDeviceElementHierarchy.DeviceElement.DeviceElementId); foreach (ISODataLogValue dlv in deviceElementDLVs) { IEnumerable <WorkingData> newWorkingDatas = Map(dlv, isoSpatialRows, deviceElementUse, dlv.Order, pendingDeviceElementUses, isoDeviceElementHierarchy); if (newWorkingDatas.Count() > 0) { int ddi = dlv.ProcessDataDDI.AsInt32DDI(); if (!EnumeratedMeterFactory.IsCondensedMeter(ddi)) { //We skip adding Condensed WorkingDatas to this DeviceElementUse since they were added separately below to their specific DeviceElementUse workingDatas.AddRange(newWorkingDatas); } } } return(workingDatas); }
private IEnumerable <ISOSpatialRow> ReadTimeLog(ISOTimeLog timeLog, string dataPath) { ISOTime templateTime = timeLog.GetTimeElement(dataPath); string binName = string.Concat(timeLog.Filename, ".bin"); string filePath = dataPath.GetDirectoryFiles(binName, SearchOption.TopDirectoryOnly).FirstOrDefault(); if (templateTime != null && filePath != null) { BinaryReader reader = new BinaryReader(); return(reader.Read(filePath, templateTime)); } return(null); }
private List <ISOTime> ExportSummary(Summary summary) { List <ISOTime> times = new List <ISOTime>(); foreach (StampedMeteredValues values in summary.SummaryData) { ISOTime time = new ISOTime(); time.Start = values.Stamp.TimeStamp1; time.Stop = values.Stamp.TimeStamp2; if (values.Stamp.Duration.HasValue) { time.Duration = (uint)values.Stamp.Duration.Value.TotalSeconds; } time.Type = values.Stamp.DateContext == DateContextEnum.ProposedStart ? ISOEnumerations.ISOTimeType.Planned : ISOEnumerations.ISOTimeType.Effective; foreach (MeteredValue value in values.Values) { if (value.Value != null && value.Value is NumericRepresentationValue) { NumericRepresentationValue numericValue = value.Value as NumericRepresentationValue; ISODataLogValue dlv = new ISODataLogValue(); int?ddi = RepresentationMapper.Map(numericValue.Representation); if (ddi.HasValue) { dlv.ProcessDataDDI = ddi.Value.AsHexDDI(); DdiDefinition DdiDefinition = DDIs[ddi.Value]; dlv.ProcessDataValue = (int)(numericValue.Value.Value / (DdiDefinition.Resolution != 0 ? DdiDefinition.Resolution : 1d)); } else { if (numericValue.Representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI) { dlv.ProcessDataDDI = numericValue.Representation.Code; dlv.ProcessDataValue = (int)numericValue.Value.Value; } } if (value.DeviceConfigurationId.HasValue) { DeviceElementConfiguration config = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(c => c.Id.ReferenceId == value.DeviceConfigurationId.Value); if (config != null) { dlv.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(config.DeviceElementId); } } time.DataLogValues.Add(dlv); } } times.Add(time); } return(times); }
private DateTime GetStartTime(ISOTime templateTime, System.IO.BinaryReader binaryReader) { if (templateTime.HasStart && templateTime.Start == null) { var milliseconds = (double)binaryReader.ReadInt32(); var daysFrom1980 = binaryReader.ReadInt16(); return(_firstDayOf1980.AddDays(daysFrom1980).AddMilliseconds(milliseconds)); } else if (templateTime.HasStart) { return((DateTime)templateTime.Start.Value); } return(_firstDayOf1980); }
private static DateTime?GetStartTime(ISOTime templateTime, System.IO.BinaryReader binaryReader) { if (templateTime.HasStart && templateTime.Start == null) { var milliseconds = ReadInt32(null, true, binaryReader); var daysFrom1980 = ReadUShort(null, true, binaryReader); return(!milliseconds.HasValue || !daysFrom1980.HasValue ? null : (DateTime?)_firstDayOf1980.AddDays(daysFrom1980.Value).AddMilliseconds(milliseconds.Value)); } else if (templateTime.HasStart) { return(templateTime.Start); } return(_firstDayOf1980); }
private ISOTimeLog ExportTimeLog(OperationData operation, IEnumerable <SpatialRecord> spatialRecords, string dataPath) { ISOTimeLog isoTimeLog = new ISOTimeLog(); //ID string id = operation.Id.FindIsoId() ?? GenerateId(5); isoTimeLog.Filename = id; isoTimeLog.TimeLogType = 1; // TimeLogType TLG.C is a required attribute. Currently only the value "1" is defined. ExportIDs(operation.Id, id); List <DeviceElementUse> deviceElementUses = operation.GetAllSections(); List <WorkingData> workingDatas = deviceElementUses.SelectMany(x => x.GetWorkingDatas()).ToList(); ISOTime isoTime = new ISOTime(); isoTime.HasStart = true; isoTime.Type = ISOTimeType.Effective; isoTime.DataLogValues = ExportDataLogValues(workingDatas, deviceElementUses).ToList(); //Set the timelog data definition for PTN ISOPosition position = new ISOPosition(); position.HasPositionNorth = true; position.HasPositionEast = true; position.HasPositionUp = true; position.HasPositionStatus = true; position.HasPDOP = false; position.HasHDOP = false; position.HasNumberOfSatellites = false; position.HasGpsUtcTime = false; position.HasGpsUtcTime = false; isoTime.Positions.Add(position); //Write XML TaskDocumentWriter xmlWriter = new TaskDocumentWriter(); xmlWriter.WriteTimeLog(dataPath, isoTimeLog, isoTime); //Write BIN var binFilePath = Path.Combine(dataPath, isoTimeLog.Filename + ".bin"); BinaryWriter writer = new BinaryWriter(_dataLogValueOrdersByWorkingDataID); writer.Write(binFilePath, workingDatas.ToList(), spatialRecords); return(isoTimeLog); }
public XmlWriter WriteTimeLog(string exportPath, ISOTimeLog timeLog, ISOTime time) { BaseFolder = exportPath; CreateFolderStructure(); XmlStream = new MemoryStream(); RootWriter = CreateWriter(XmlStream); RootWriter.WriteStartDocument(); time.WriteXML(RootWriter); RootWriter.WriteEndDocument(); RootWriter.Flush(); var xml = Encoding.UTF8.GetString(XmlStream.ToArray()); File.WriteAllText(Path.Combine(BaseFolder, timeLog.Filename + ".xml"), xml); return(RootWriter); }
public List <WorkingData> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoSpatialRows, DeviceElementUse deviceElementUse, DeviceHierarchyElement isoDeviceElementHierarchy, List <DeviceElementUse> pendingDeviceElementUses, Dictionary <string, List <ISOProductAllocation> > isoProductAllocations) { var workingDatas = new List <WorkingData>(); //Create vrProductIndex on relevant device elements if more than one product on this OperationData if (TimeLogMapper.GetDistinctProductIDs(TaskDataMapper, isoProductAllocations).Count > 1 && isoProductAllocations.Keys.Contains(isoDeviceElementHierarchy.DeviceElement.DeviceElementId)) { WorkingData workingData = CreateProductIndexWorkingData(deviceElementUse.Id.ReferenceId); ISODeviceElementIDsByWorkingDataID.Add(workingData.Id.ReferenceId, isoDeviceElementHierarchy.DeviceElement.DeviceElementId); workingDatas.Add(workingData); } //Add the Working Datas for this DeviceElement IEnumerable <ISODataLogValue> deviceElementDLVs = time.DataLogValues.Where(dlv => dlv.DeviceElementIdRef == isoDeviceElementHierarchy.DeviceElement.DeviceElementId || //DLV DET reference matches the primary DET for the ADAPT element isoDeviceElementHierarchy.MergedElements.Any(e => e.DeviceElementId == dlv.DeviceElementIdRef)); //DLV DET reference matches one of the merged DETs on the ADAPT element foreach (ISODataLogValue dlv in deviceElementDLVs) { IEnumerable <WorkingData> newWorkingDatas = Map(dlv, isoSpatialRows, deviceElementUse, dlv.Index, pendingDeviceElementUses, isoDeviceElementHierarchy); if (newWorkingDatas.Count() > 0) { int ddi = dlv.ProcessDataDDI.AsInt32DDI(); if (!EnumeratedMeterFactory.IsCondensedMeter(ddi)) { //We skip adding Condensed WorkingDatas to this DeviceElementUse since they were added separately below to their specific DeviceElementUse workingDatas.AddRange(newWorkingDatas); } } } return(workingDatas); }
private ISOTime CreateCombinedTime() { ISOTime result = null; foreach (var timeLog in _timeLogs) { var time = timeLog.GetTimeElement(TaskDataPath); result = ISOTime.Merge(result, time); } var duplicateDataLogValues = result.DataLogValues .Where(x => x.DataLogPGN == null) .GroupBy(x => new { x.DeviceElementIdRef, x.ProcessDataDDI }) .Where(x => x.Count() > 1) .SelectMany(x => x.Skip(1)) .ToList(); duplicateDataLogValues.ForEach(x => result.DataLogValues.Remove(x)); return(result); }
public static Dictionary <byte, int> ReadImplementGeometryValues(string filePath, ISOTime templateTime, IEnumerable <byte> desiredDLVIndices) { Dictionary <byte, int> output = new Dictionary <byte, int>(); List <byte> desiredIndexes = desiredDLVIndices.ToList(); //Determine the number of header bytes in each position short headerCount = 0; SkipBytes(templateTime.HasStart && templateTime.Start == null, 6, ref headerCount); ISOPosition templatePosition = templateTime.Positions.FirstOrDefault(); if (templatePosition != null) { SkipBytes(templatePosition.HasPositionNorth && templatePosition.PositionNorth == null, 4, ref headerCount); SkipBytes(templatePosition.HasPositionEast && templatePosition.PositionEast == null, 4, ref headerCount); SkipBytes(templatePosition.HasPositionUp && templatePosition.PositionUp == null, 4, ref headerCount); SkipBytes(templatePosition.HasPositionStatus && templatePosition.PositionStatus == null, 1, ref headerCount); SkipBytes(templatePosition.HasPDOP && templatePosition.PDOP == null, 2, ref headerCount); SkipBytes(templatePosition.HasHDOP && templatePosition.HDOP == null, 2, ref headerCount); SkipBytes(templatePosition.HasNumberOfSatellites && templatePosition.NumberOfSatellites == null, 1, ref headerCount); SkipBytes(templatePosition.HasGpsUtcTime && templatePosition.GpsUtcTime == null, 4, ref headerCount); SkipBytes(templatePosition.HasGpsUtcDate && templatePosition.GpsUtcDate == null, 2, ref headerCount); } using (var binaryReader = new System.IO.BinaryReader(File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))) { while (ContinueReading(binaryReader)) { binaryReader.BaseStream.Position += headerCount; //Skip over the header if (ContinueReading(binaryReader)) { var numberOfDLVs = ReadByte(null, true, binaryReader).GetValueOrDefault(0); if (ContinueReading(binaryReader)) { numberOfDLVs = ConfirmNumberOfDLVs(binaryReader, numberOfDLVs); //Validate we are not at the end of a truncated file for (byte i = 0; i < numberOfDLVs; i++) { byte dlvIndex = ReadByte(null, true, binaryReader).GetValueOrDefault(); //This is the current DLV reported if (desiredIndexes.Contains(dlvIndex)) { //A desired DLV is reported here int value = ReadInt32(null, true, binaryReader).GetValueOrDefault(); if (!output.ContainsKey(dlvIndex)) { output.Add(dlvIndex, value); } else if (Math.Abs(value) > Math.Abs(output[dlvIndex])) { //Values should be all the same, but prefer the furthest from 0 output[dlvIndex] = value; } } else { binaryReader.BaseStream.Position += 4; } } } } } } return(output); }
public List <DeviceElementUse> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, int operationDataId, IEnumerable <string> isoDeviceElementIDs, Dictionary <string, List <ISOProductAllocation> > isoProductAllocations) { var sections = new List <DeviceElementUse>(); foreach (string isoDeviceElementID in isoDeviceElementIDs) { DeviceHierarchyElement hierarchyElement = TaskDataMapper.DeviceElementHierarchies.GetMatchingElement(isoDeviceElementID); if (hierarchyElement != null) { DeviceElementUse deviceElementUse = null; List <WorkingData> workingDatas = new List <WorkingData>(); //Get the relevant DeviceElementConfiguration int adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value; DeviceElement adaptDeviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId); if (adaptDeviceElement != null) { DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchyElement, DataModel.Catalog); int depth = hierarchyElement.Depth; int order = hierarchyElement.Order; if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId) { //The configuration references the parent ISO element depth = hierarchyElement.Parent.Depth; order = hierarchyElement.Parent.Order; } deviceElementUse = sections.FirstOrDefault(d => d.DeviceConfigurationId == config.Id.ReferenceId); if (deviceElementUse == null) { //Create the DeviceElementUse deviceElementUse = new DeviceElementUse(); deviceElementUse.Depth = depth; deviceElementUse.Order = order; deviceElementUse.OperationDataId = operationDataId; deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId; //Add Working Data for any data on this device element List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchyElement, sections, isoProductAllocations); if (data.Any()) { workingDatas.AddRange(data); } } else { workingDatas = deviceElementUse.GetWorkingDatas().ToList(); //Add Additional Working Data List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchyElement, sections, isoProductAllocations); if (data.Any()) { workingDatas.AddRange(data); } } deviceElementUse.GetWorkingDatas = () => workingDatas; if (!sections.Contains(deviceElementUse)) { sections.Add(deviceElementUse); } } } } return(sections); }
public static IEnumerable <ISOSpatialRow> Read(string fileName, ISOTime templateTime, DeviceElementHierarchies deviceHierarchies) { if (templateTime == null) { yield break; } if (!File.Exists(fileName)) { yield break; } using (var binaryReader = new System.IO.BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))) { while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { ISOPosition templatePosition = templateTime.Positions.FirstOrDefault(); var record = new ISOSpatialRow { TimeStart = GetStartTime(templateTime, binaryReader).GetValueOrDefault() }; if (templatePosition != null) { //North and East are required binary data record.NorthPosition = ReadInt32((double?)templatePosition.PositionNorth, templatePosition.HasPositionNorth, binaryReader).GetValueOrDefault(0); record.EastPosition = ReadInt32((double?)templatePosition.PositionEast, templatePosition.HasPositionEast, binaryReader).GetValueOrDefault(0); //Optional position attributes will be included in the binary only if a corresponding attribute is present in the PTN element record.Elevation = ReadInt32(templatePosition.PositionUp, templatePosition.HasPositionUp, binaryReader); //Position status is required record.PositionStatus = ReadByte((byte?)templatePosition.PositionStatus, templatePosition.HasPositionStatus, binaryReader); record.PDOP = ReadUShort((double?)templatePosition.PDOP, templatePosition.HasPDOP, binaryReader); record.HDOP = ReadUShort((double?)templatePosition.HDOP, templatePosition.HasHDOP, binaryReader); record.NumberOfSatellites = ReadByte(templatePosition.NumberOfSatellites, templatePosition.HasNumberOfSatellites, binaryReader); record.GpsUtcTime = ReadUInt32(templatePosition.GpsUtcTime, templatePosition.HasGpsUtcTime, binaryReader).GetValueOrDefault(); record.GpsUtcDate = ReadUShort(templatePosition.GpsUtcDate, templatePosition.HasGpsUtcDate, binaryReader); if (record.GpsUtcDate != null && record.GpsUtcTime != null) { record.GpsUtcDateTime = _firstDayOf1980.AddDays((double)record.GpsUtcDate).AddMilliseconds((double)record.GpsUtcTime); } } //Some datasets end here if (binaryReader.BaseStream.Position >= binaryReader.BaseStream.Length) { break; } var numberOfDLVs = ReadByte(null, true, binaryReader).GetValueOrDefault(0); // There should be some values but no more data exists in file, stop processing if (numberOfDLVs > 0 && binaryReader.BaseStream.Position >= binaryReader.BaseStream.Length) { break; } //If the reported number of values does not fit into the stream, correct the numberOfDLVs numberOfDLVs = ConfirmNumberOfDLVs(binaryReader, numberOfDLVs); record.SpatialValues = new List <SpatialValue>(); bool unexpectedEndOfStream = false; //Read DLVs out of the TLG.bin for (int i = 0; i < numberOfDLVs; i++) { var order = ReadByte(null, true, binaryReader).GetValueOrDefault(); var value = ReadInt32(null, true, binaryReader).GetValueOrDefault(); // Can't read either order or value or both, stop processing if (i < numberOfDLVs - 1 && binaryReader.BaseStream.Position >= binaryReader.BaseStream.Length) { unexpectedEndOfStream = true; break; } SpatialValue spatialValue = CreateSpatialValue(templateTime, order, value, deviceHierarchies); if (spatialValue != null) { record.SpatialValues.Add(spatialValue); } } // Unable to read some of the expected DLVs, stop processing if (unexpectedEndOfStream) { break; } //Add any fixed values from the TLG.xml foreach (ISODataLogValue fixedValue in templateTime.DataLogValues.Where(dlv => dlv.ProcessDataValue.HasValue && !EnumeratedMeterFactory.IsCondensedMeter(dlv.ProcessDataDDI.AsInt32DDI()))) { byte order = (byte)templateTime.DataLogValues.IndexOf(fixedValue); if (record.SpatialValues.Any(s => s.Id == order)) //Check to ensure the binary data didn't already write this value { //Per the spec, any fixed value in the XML applies to all rows; as such, replace what was read from the binary SpatialValue matchingValue = record.SpatialValues.Single(s => s.Id == order); matchingValue.DataLogValue = fixedValue; } } yield return(record); } } }
public IEnumerable <ISOSpatialRow> Read(string fileName, ISOTime templateTime) { if (templateTime == null) { yield break; } if (!File.Exists(fileName)) { yield break; } using (var binaryReader = new System.IO.BinaryReader(File.Open(fileName, FileMode.Open))) { while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { ISOPosition templatePosition = templateTime.Positions.FirstOrDefault(); var record = new ISOSpatialRow { TimeStart = GetStartTime(templateTime, binaryReader) }; if (templatePosition != null) { //North and East are required binary data record.NorthPosition = ReadInt32((double?)templatePosition.PositionNorth, templatePosition.HasPositionNorth, binaryReader).GetValueOrDefault(0); record.EastPosition = ReadInt32((double?)templatePosition.PositionEast, templatePosition.HasPositionEast, binaryReader).GetValueOrDefault(0); if (templatePosition.HasPositionUp) //Optional position attributes will be included in the binary only if a corresponding attribute is present in the PTN element { record.Elevation = ReadInt32(templatePosition.PositionUp, templatePosition.HasPositionUp, binaryReader); } //Position status is required record.PositionStatus = ReadByte((byte?)templatePosition.PositionStatus, templatePosition.HasPositionStatus, binaryReader); if (templatePosition.HasPDOP) { record.PDOP = ReadUShort((double?)templatePosition.PDOP, templatePosition.HasPDOP, binaryReader); } if (templatePosition.HasHDOP) { record.HDOP = ReadUShort((double?)templatePosition.HDOP, templatePosition.HasHDOP, binaryReader); } if (templatePosition.HasNumberOfSatellites) { record.NumberOfSatellites = ReadByte(templatePosition.NumberOfSatellites, templatePosition.HasNumberOfSatellites, binaryReader); } if (templatePosition.HasGpsUtcTime) { if (templatePosition.GpsUtcTime.HasValue) { record.GpsUtcTime = Convert.ToUInt32(templatePosition.GpsUtcTime.Value); } else { record.GpsUtcTime = binaryReader.ReadUInt32(); } } if (templatePosition.HasGpsUtcDate) { if (templatePosition.GpsUtcDate.HasValue) { record.GpsUtcDate = (ushort)templatePosition.GpsUtcDate.Value; } else { record.GpsUtcDate = binaryReader.ReadUInt16(); } } if (record.GpsUtcDate != null && record.GpsUtcTime != null) { record.GpsUtcDateTime = _firstDayOf1980.AddDays((double)record.GpsUtcDate).AddMilliseconds((double)record.GpsUtcTime); } } var numberOfDLVs = binaryReader.ReadByte(); record.SpatialValues = new List <SpatialValue>(); //Read DLVs out of the TLG.bin for (int i = 0; i < numberOfDLVs; i++) { var order = binaryReader.ReadByte(); var value = binaryReader.ReadInt32(); record.SpatialValues.Add(CreateSpatialValue(templateTime, order, value)); } //Add any fixed values from the TLG.xml foreach (ISODataLogValue fixedValue in templateTime.DataLogValues.Where(dlv => dlv.ProcessDataValue.HasValue && !EnumeratedMeterFactory.IsCondensedMeter(dlv.ProcessDataDDI.AsInt32DDI()))) { byte order = (byte)templateTime.DataLogValues.IndexOf(fixedValue); if (record.SpatialValues.Any(s => s.Id == order)) //Check to ensure the binary data didn't already write this value { //Per the spec, any fixed value in the XML applies to all rows; as such, replace what was read from the binary SpatialValue matchingValue = record.SpatialValues.Single(s => s.Id == order); matchingValue.DataLogValue = fixedValue; } } yield return(record); } } }
private IEnumerable <OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLog isoTimeLog, int?prescriptionID) { WorkingDataMapper workingDataMapper = new WorkingDataMapper(new EnumeratedMeterFactory(), TaskDataMapper); SectionMapper sectionMapper = new SectionMapper(workingDataMapper, TaskDataMapper); SpatialRecordMapper spatialMapper = new SpatialRecordMapper(new RepresentationValueInterpolator(), sectionMapper, workingDataMapper, TaskDataMapper); IEnumerable <ISOSpatialRow> isoRecords = ReadTimeLog(isoTimeLog, this.TaskDataPath); bool useDeferredExecution = false; if (isoRecords != null) { try { if (TaskDataMapper.Properties != null) { //Set this property to override the default behavior of pre-iterating the data bool.TryParse(TaskDataMapper.Properties.GetProperty("SpatialRecordDeferredExecution"), out useDeferredExecution); } if (!useDeferredExecution) { isoRecords = isoRecords.ToList(); //Avoids multiple reads } //Set a UTC "delta" from the first record where possible. We set only one per data import. if (!TaskDataMapper.GPSToLocalDelta.HasValue) { var firstRecord = isoRecords.FirstOrDefault(); if (firstRecord != null && firstRecord.GpsUtcDateTime.HasValue) { //Local - UTC = Delta. This value will be rough based on the accuracy of the clock settings but will expose the ability to derive the UTC times from the exported local times. TaskDataMapper.GPSToLocalDelta = (firstRecord.TimeStart - firstRecord.GpsUtcDateTime.Value).TotalHours; } } } catch (Exception ex) { TaskDataMapper.AddError($"Timelog file {isoTimeLog.Filename} is invalid. Skipping.", ex.Message, null, ex.StackTrace); return(null); } ISOTime time = isoTimeLog.GetTimeElement(this.TaskDataPath); //Identify unique devices represented in this TimeLog data IEnumerable <string> deviceElementIDs = time.DataLogValues.Where(d => d.ProcessDataDDI != "DFFF" && d.ProcessDataDDI != "DFFE").Select(d => d.DeviceElementIdRef); Dictionary <ISODevice, HashSet <string> > loggedDeviceElementsByDevice = new Dictionary <ISODevice, HashSet <string> >(); foreach (string deviceElementID in deviceElementIDs) { ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(deviceElementID); if (isoDeviceElement != null) { ISODevice device = isoDeviceElement.Device; if (!loggedDeviceElementsByDevice.ContainsKey(device)) { loggedDeviceElementsByDevice.Add(device, new HashSet <string>()); } loggedDeviceElementsByDevice[device].Add(deviceElementID); } } //Split all devices in the same TimeLog into separate OperationData objects to handle multi-implement scenarios //This will ensure implement geometries/DeviceElementUse Depths & Orders do not get confused between implements List <OperationData> operationDatas = new List <OperationData>(); foreach (ISODevice dvc in loggedDeviceElementsByDevice.Keys) { OperationData operationData = new OperationData(); //Determine products Dictionary <string, List <ISOProductAllocation> > productAllocations = GetProductAllocationsByDeviceElement(loggedTask, dvc); List <int> productIDs = GetDistinctProductIDs(TaskDataMapper, productAllocations); //This line will necessarily invoke a spatial read in order to find //1)The correct number of CondensedWorkState working datas to create //2)Any Widths and Offsets stored in the spatial data IEnumerable <DeviceElementUse> sections = sectionMapper.Map(time, isoRecords, operationData.Id.ReferenceId, loggedDeviceElementsByDevice[dvc], productAllocations); var workingDatas = sections != null?sections.SelectMany(x => x.GetWorkingDatas()).ToList() : new List <WorkingData>(); operationData.GetSpatialRecords = () => spatialMapper.Map(isoRecords, workingDatas, productAllocations); operationData.MaxDepth = sections.Count() > 0 ? sections.Select(s => s.Depth).Max() : 0; operationData.GetDeviceElementUses = x => sectionMapper.ConvertToBaseTypes(sections.Where(s => s.Depth == x).ToList()); operationData.PrescriptionId = prescriptionID; operationData.OperationType = GetOperationTypeFromLoggingDevices(time); operationData.ProductIds = productIDs; operationData.SpatialRecordCount = isoRecords.Count(); operationDatas.Add(operationData); } //Set the CoincidentOperationDataIds property identifying Operation Datas from the same TimeLog. operationDatas.ForEach(o => o.CoincidentOperationDataIds = operationDatas.Where(o2 => o2.Id.ReferenceId != o.Id.ReferenceId).Select(o3 => o3.Id.ReferenceId).ToList()); return(operationDatas); } return(null); }
public IEnumerable <ISOSpatialRow> Read(string fileName, ISOTime templateTime) { if (templateTime == null) { yield break; } if (!File.Exists(fileName)) { yield break; } using (var binaryReader = new System.IO.BinaryReader(File.Open(fileName, FileMode.Open))) { while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { ISOPosition templatePosition = templateTime.Positions.FirstOrDefault(); var record = new ISOSpatialRow { TimeStart = GetStartTime(templateTime, binaryReader) }; if (templatePosition != null) { //North and East are required binary data record.NorthPosition = ReadInt32((double?)templatePosition.PositionNorth, templatePosition.HasPositionNorth, binaryReader).GetValueOrDefault(0); record.EastPosition = ReadInt32((double?)templatePosition.PositionEast, templatePosition.HasPositionEast, binaryReader).GetValueOrDefault(0); if (templatePosition.HasPositionUp) //Optional position attributes will be included in the binary only if a corresponding attribute is present in the PTN element { record.Elevation = ReadInt32(templatePosition.PositionUp, templatePosition.HasPositionUp, binaryReader); } //Position status is required record.PositionStatus = ReadByte((byte?)templatePosition.PositionStatus, templatePosition.HasPositionStatus, binaryReader); if (templatePosition.HasPDOP) { record.PDOP = ReadUShort((double?)templatePosition.PDOP, templatePosition.HasPDOP, binaryReader); } if (templatePosition.HasHDOP) { record.HDOP = ReadUShort((double?)templatePosition.HDOP, templatePosition.HasHDOP, binaryReader); } if (templatePosition.HasNumberOfSatellites) { record.NumberOfSatellites = ReadByte(templatePosition.NumberOfSatellites, templatePosition.HasNumberOfSatellites, binaryReader); } if (templatePosition.HasGpsUtcTime) { if (templatePosition.GpsUtcTime.HasValue) { record.GpsUtcTime = Convert.ToUInt32(templatePosition.GpsUtcTime.Value); } else { record.GpsUtcTime = binaryReader.ReadUInt32(); } } if (templatePosition.HasGpsUtcDate) { if (templatePosition.GpsUtcDate.HasValue) { record.GpsUtcDate = (ushort)templatePosition.GpsUtcDate.Value; } else { record.GpsUtcDate = binaryReader.ReadUInt16(); } } if (record.GpsUtcDate != null && record.GpsUtcTime != null) { record.GpsUtcDateTime = _firstDayOf1980.AddDays((double)record.GpsUtcDate).AddMilliseconds((double)record.GpsUtcTime); } } var numberOfDLVs = binaryReader.ReadByte(); record.SpatialValues = new List <SpatialValue>(); for (int i = 0; i < numberOfDLVs; i++) { var order = binaryReader.ReadByte(); var value = binaryReader.ReadInt32(); record.SpatialValues.Add(CreateSpatialValue(templateTime, order, value)); } yield return(record); } } }
/// <summary> /// Perform a targeted read of the Timelog binary files to obtain implement geometry details logged via DeviceProcessData /// </summary> /// <param name="missingDefinitions"></param> /// <param name="timeLogTimeElements"></param> /// <param name="taskDataPath"></param> /// <param name="allDeviceHierarchyElements"></param> public void FillDPDGeometryDefinitions(Dictionary <string, List <string> > missingDefinitions, IEnumerable <ISOTimeLog> timeLogs, string taskDataPath) { Dictionary <string, int?> reportedValues = new Dictionary <string, int?>(); //DLV signature / value foreach (ISOTimeLog timeLog in timeLogs) { ISOTime time = timeLog.GetTimeElement(taskDataPath); if (time != null && time.DataLogValues.Any(dlv => missingDefinitions.ContainsKey(dlv.DeviceElementIdRef))) { List <ISODataLogValue> dlvsToRead = time.DataLogValues.Where(dlv => missingDefinitions.ContainsKey(dlv.DeviceElementIdRef) && missingDefinitions[dlv.DeviceElementIdRef].Contains(dlv.ProcessDataDDI)).ToList(); foreach (string deviceElementID in missingDefinitions.Keys) { List <string> ddis = missingDefinitions[deviceElementID]; if (ddis.Any(d => d == "0046")) { //We used 0046 generically for a missing width. Check for any 0044 or 0043 var defaultWidthDLV = time.DataLogValues.FirstOrDefault(gt => gt.ProcessDataDDI == "0044" && gt.DeviceElementIdRef == deviceElementID); if (defaultWidthDLV != null) { dlvsToRead.Add(defaultWidthDLV); } else { var workingWidthDLV = time.DataLogValues.FirstOrDefault(gt => gt.ProcessDataDDI == "0043" && gt.DeviceElementIdRef == deviceElementID); if (workingWidthDLV != null) { dlvsToRead.Add(workingWidthDLV); } } } } if (dlvsToRead.Any()) { string binaryPath = System.IO.Path.Combine(taskDataPath, timeLog.Filename + ".bin"); Dictionary <byte, int> timelogValues = Mappers.TimeLogMapper.ReadImplementGeometryValues(dlvsToRead.Select(d => d.Index), time, binaryPath); foreach (byte reportedDLVIndex in timelogValues.Keys) { ISODataLogValue reportedDLV = dlvsToRead.First(d => d.Index == reportedDLVIndex); string dlvKey = DeviceHierarchyElement.GetDataLogValueKey(reportedDLV); if (!reportedValues.ContainsKey(dlvKey)) { //First occurence of this DET and DDI in the timelogs //We take the max width/max (from 0) offset from the 1st timelog. This matches existing functionality, and is workable for foreseeable cases where working width is the only dynamic value. //ISOXML supports changing widths and offsets dynamically throughout and across timelogs. //Should max width and/or offset parameters change dynamically, data consumers will need to obtain this information via the OperationData.SpatialRecords as is commonly done with 0043 (working width) today //An alternative would be to enhance this logic to clone the entire DeviceModel hierarchy for each variation in offset value, should such data ever occur in the field. reportedValues.Add(dlvKey, timelogValues[reportedDLV.Index]); //Add to this element var matchingElement = GetMatchingElement(reportedDLV.DeviceElementIdRef); if (matchingElement != null) { switch (reportedDLV.ProcessDataDDI) { case "0046": case "0044": case "0043": if (matchingElement.Width == null || timelogValues[reportedDLV.Index] > matchingElement.Width) { //If max 0043 is greater than 0046, then take max 0043 matchingElement.Width = timelogValues[reportedDLV.Index]; matchingElement.WidthDDI = reportedDLV.ProcessDataDDI; } break; case "0086": matchingElement.XOffset = timelogValues[reportedDLV.Index]; break; case "0087": matchingElement.YOffset = timelogValues[reportedDLV.Index]; break; case "0088": matchingElement.ZOffset = timelogValues[reportedDLV.Index]; break; } } } } } } } }
public List <DeviceElementUse> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, int operationDataId, IEnumerable <string> isoDeviceElementIDs, Dictionary <string, List <ISOProductAllocation> > isoProductAllocations) { var sections = new List <DeviceElementUse>(); foreach (string isoDeviceElementID in isoDeviceElementIDs) { DeviceElementHierarchy hierarchy = TaskDataMapper.DeviceElementHierarchies.GetRelevantHierarchy(isoDeviceElementID); if (hierarchy != null) { DeviceElementUse deviceElementUse = null; List <WorkingData> workingDatas = new List <WorkingData>(); //Get the relevant DeviceElementConfiguration int adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value; DeviceElement adaptDeviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId); if (adaptDeviceElement != null) { DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchy, DataModel.Catalog); int depth = hierarchy.Depth; int order = hierarchy.Order; if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId) { //The configuration references the parent ISO element depth = hierarchy.Parent.Depth; order = hierarchy.Parent.Order; } //Read any spatially-listed widths/offsets on this data onto the DeviceElementConfiguration objects hierarchy.SetWidthsAndOffsetsFromSpatialData(time, isoRecords, config, RepresentationMapper); deviceElementUse = sections.FirstOrDefault(d => d.DeviceConfigurationId == config.Id.ReferenceId); if (deviceElementUse == null) { //Create the DeviceElementUse deviceElementUse = new DeviceElementUse(); deviceElementUse.Depth = depth; deviceElementUse.Order = order; deviceElementUse.OperationDataId = operationDataId; deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId; //Add Working Data for any data on this device element List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections, isoProductAllocations); if (data.Any()) { workingDatas.AddRange(data); } } else { workingDatas = deviceElementUse.GetWorkingDatas().ToList(); //Add Additional Working Data List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections, isoProductAllocations); if (data.Any()) { workingDatas.AddRange(data); } } deviceElementUse.GetWorkingDatas = () => workingDatas; if (!sections.Contains(deviceElementUse)) { sections.Add(deviceElementUse); } } else if (hierarchy.DeviceElement.DeviceElementType == ISOEnumerations.ISODeviceElementType.Connector) { int?connectorID = TaskDataMapper.InstanceIDMap.GetADAPTID(hierarchy.DeviceElement.DeviceElementId).Value; if (connectorID.HasValue) { Connector adaptConnector = DataModel.Catalog.Connectors.FirstOrDefault(c => c.Id.ReferenceId == connectorID.Value); if (adaptConnector != null) { HitchPoint hitch = DataModel.Catalog.HitchPoints.FirstOrDefault(h => h.Id.ReferenceId == adaptConnector.HitchPointId); if (hitch != null) { hierarchy.SetHitchOffsetsFromSpatialData(time, isoRecords, hitch, RepresentationMapper); } } } } } } return(sections); }
internal static Dictionary <byte, int> ReadImplementGeometryValues(IEnumerable <byte> dlvsToRead, ISOTime templateTime, string filePath) { return(BinaryReader.ReadImplementGeometryValues(filePath, templateTime, dlvsToRead)); }