Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
            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);
                    }
                }
            }
Exemplo n.º 5
0
            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);
                    }
                }
            }