|
6 | 6 | using System.Collections.Generic; |
7 | 7 | using System.IO; |
8 | 8 | using System.Linq; |
| 9 | +using AgGateway.ADAPT.ApplicationDataModel.ADM; |
9 | 10 | using AgGateway.ADAPT.ApplicationDataModel.Common; |
10 | 11 | using AgGateway.ADAPT.ApplicationDataModel.Equipment; |
11 | 12 | using AgGateway.ADAPT.ApplicationDataModel.LoggedData; |
@@ -347,7 +348,7 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo |
347 | 348 | Dictionary<ISODevice, HashSet<string>> loggedDeviceElementsByDevice = new Dictionary<ISODevice, HashSet<string>>(); |
348 | 349 | foreach (string deviceElementID in deviceElementIDs) |
349 | 350 | { |
350 | | - ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(deviceElementID); |
| 351 | + ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies?.GetISODeviceElementFromID(deviceElementID); |
351 | 352 | if (isoDeviceElement != null) |
352 | 353 | { |
353 | 354 | ISODevice device = isoDeviceElement.Device; |
@@ -724,16 +725,16 @@ protected virtual IEnumerable<ISOSpatialRow> ReadTimeLog(ISOTimeLog timeLog, str |
724 | 725 | return null; |
725 | 726 | } |
726 | 727 |
|
727 | | - internal static Dictionary<byte, int> ReadImplementGeometryValues(IEnumerable<byte> dlvsToRead, ISOTime templateTime, string filePath, int version) |
| 728 | + internal static Dictionary<byte, int> ReadImplementGeometryValues(IEnumerable<byte> dlvsToRead, ISOTime templateTime, string filePath, int version, IList<IError> errors) |
728 | 729 | { |
729 | | - return BinaryReader.ReadImplementGeometryValues(filePath, templateTime, dlvsToRead, version); |
| 730 | + return BinaryReader.ReadImplementGeometryValues(filePath, templateTime, dlvsToRead, version, errors); |
730 | 731 | } |
731 | 732 |
|
732 | 733 | protected class BinaryReader |
733 | 734 | { |
734 | 735 | private static readonly DateTime _firstDayOf1980 = new DateTime(1980, 01, 01); |
735 | 736 |
|
736 | | - public static Dictionary<byte, int> ReadImplementGeometryValues(string filePath, ISOTime templateTime, IEnumerable<byte> desiredDLVIndices, int version) |
| 737 | + public static Dictionary<byte, int> ReadImplementGeometryValues(string filePath, ISOTime templateTime, IEnumerable<byte> desiredDLVIndices, int version, IList<IError> errors) |
737 | 738 | { |
738 | 739 | Dictionary<byte, int> output = new Dictionary<byte, int>(); |
739 | 740 | List<byte> desiredIndexes = desiredDLVIndices.ToList(); |
@@ -775,14 +776,22 @@ public static Dictionary<byte, int> ReadImplementGeometryValues(string filePath, |
775 | 776 | { |
776 | 777 | //A desired DLV is reported here |
777 | 778 | int value = ReadInt32(null, true, false, binaryReader).GetValueOrDefault(); |
778 | | - if (!output.ContainsKey(dlvIndex)) |
| 779 | + try |
779 | 780 | { |
780 | | - output.Add(dlvIndex, value); |
| 781 | + if (!output.ContainsKey(dlvIndex)) |
| 782 | + { |
| 783 | + output.Add(dlvIndex, value); |
| 784 | + } |
| 785 | + else if (Math.Abs(value) > Math.Abs(output[dlvIndex])) |
| 786 | + { |
| 787 | + //Values should be all the same, but prefer the furthest from 0 |
| 788 | + output[dlvIndex] = value; |
| 789 | + } |
781 | 790 | } |
782 | | - else if (Math.Abs(value) > Math.Abs(output[dlvIndex])) |
| 791 | + catch (OverflowException ex) |
783 | 792 | { |
784 | | - //Values should be all the same, but prefer the furthest from 0 |
785 | | - output[dlvIndex] = value; |
| 793 | + // If value == int.MinValue, Math.Abs(value) will throw System.OverflowException: Negating the minimum value of a twos complement number is invalid. |
| 794 | + errors.Add(new Error() { Description = ex.Message, Id = ex.GetType().ToString(), Source = ex.Source, StackTrace = ex.StackTrace }); |
786 | 795 | } |
787 | 796 | } |
788 | 797 | else |
@@ -1047,7 +1056,7 @@ private static SpatialValue CreateSpatialValue(ISOTime templateTime, byte order, |
1047 | 1056 | if (matchingDlv == null) |
1048 | 1057 | return null; |
1049 | 1058 |
|
1050 | | - ISODeviceElement det = deviceHierarchies.GetISODeviceElementFromID(matchingDlv.DeviceElementIdRef); |
| 1059 | + ISODeviceElement det = deviceHierarchies?.GetISODeviceElementFromID(matchingDlv.DeviceElementIdRef); |
1051 | 1060 | ISODevice dvc = det?.Device; |
1052 | 1061 | ISODeviceProcessData dpd = dvc?.FirstOrDefaultDeviceProcessData(matchingDlv.ProcessDataIntDDI); |
1053 | 1062 |
|
|
0 commit comments