public void Test_TAGProcessor_DoPostProcessFileAction() { var SiteModel = new SiteModel(StorageMutability.Immutable); var Machine = new Machine(); var SiteModelGridAggregator = new ServerSubGridTree(SiteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); TAGProcessor processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); // Set the state of the processor to emulate the end of processing this TAG file at which point the processor should emit // a "Stop recording event". In this instance, the NoGPSModeSet flag will also be true which should trigger emission of // a 'NoGPS' GPS mode state event and a 'UTS' positioning technology state event DateTime eventDate = DateTime.SpecifyKind(new DateTime(2000, 1, 1, 1, 1, 1), DateTimeKind.Utc); // Setting the first data time will create the start event processor.DataTime = eventDate; DateTime eventDate2 = eventDate.AddMinutes(1); processor.DataTime = eventDate2; processor.DoPostProcessFileAction(true); Assert.True(MachineTargetValueChangesAggregator.GPSModeStateEvents.LastStateValue() == GPSMode.NoGPS && MachineTargetValueChangesAggregator.GPSModeStateEvents.LastStateDate() == eventDate, "DoPostProcessFileAction did not set GPSMode event"); Assert.True(MachineTargetValueChangesAggregator.PositioningTechStateEvents.LastStateValue() == PositioningTech.UTS && MachineTargetValueChangesAggregator.PositioningTechStateEvents.LastStateDate() == eventDate, "DoPostProcessFileAction did not set positioning tech event"); Assert.True(MachineTargetValueChangesAggregator.StartEndRecordedDataEvents.LastStateValue() == ProductionEventType.EndEvent /*EndRecordedData*/ && MachineTargetValueChangesAggregator.StartEndRecordedDataEvents.LastStateDate() == eventDate2, "DoPostProcessFileAction did not set end recorded data event"); }
/// <summary> /// Execute the conversion operation on the TAG file, returning a boolean success result. /// Sets up local state detailing the pre-scan fields retrieved from the TAG file /// </summary> public bool ExecuteLegacyTAGFile(string filename, Stream tagData, Guid assetUid, bool isJohnDoe) { Log.LogInformation($"In {nameof(ExecuteLegacyTAGFile)}: reading file {filename} for asset {assetUid}, JohnDoe: {isJohnDoe}"); ReadResult = TAGReadResult.NoError; List <UTMCoordPointPair> aCSBladePositions = null; List <UTMCoordPointPair> ACSRearAxlePositions = null; List <UTMCoordPointPair> ACSTrackPositions = null; List <UTMCoordPointPair> ACSWheelPositions = null; try { Processor?.Dispose(); // Locate the machine in the local set of machines, adding one if necessary Machine = Machines.Locate(assetUid, isJohnDoe); var machineType = MachineType.Unknown; var machineHardwareId = string.Empty; var machineId = string.Empty; //Prescan to get all relevant information necessary for processing the tag file. e.g. Machinetype for swather, Type of coordinate system (ACS) var tagFilePreScan = new TAGFilePreScan(); tagFilePreScan.Execute(tagData); tagData.Position = 0; // reset if (tagFilePreScan.ReadResult == TAGReadResult.NoError) { machineType = tagFilePreScan.MachineType; // used in creation of swather machineHardwareId = tagFilePreScan.HardwareID; machineId = tagFilePreScan.MachineID; IsUTMCoordinateSystem = !tagFilePreScan.IsCSIBCoordSystemTypeOnly; // do we need to convert UTM coordinates to project coordinates if (IsUTMCoordinateSystem && tagFilePreScan.ProcessedEpochCount > 0) { Log.LogInformation($"{nameof(ExecuteLegacyTAGFile)}: ACS coordinate system detected. {filename}"); aCSBladePositions = new List <UTMCoordPointPair>(); ACSRearAxlePositions = new List <UTMCoordPointPair>(); ACSTrackPositions = new List <UTMCoordPointPair>(); ACSWheelPositions = new List <UTMCoordPointPair>(); if (!CollectAndConvertBladePostions(_targetSiteModel, ref tagData, ref aCSBladePositions, ref ACSRearAxlePositions, ref ACSTrackPositions, ref ACSWheelPositions)) { Log.LogError($"{nameof(ExecuteLegacyTAGFile)}: Failed to collect and convert blade positions for tagfile processing with ACS. TAG FILE:{filename}"); ReadResult = TAGReadResult.CoordinateConversionFailure; return(false); } } } else { Log.LogError($"Unsuccessful prescan of tagfile. {tagFilePreScan.ReadResult}"); return(false); } if (Machine == null) { // Now we know more about the machine have another go finding it Machine = Machines.Locate(assetUid, machineId, isJohnDoe); } if (Machine == null) { Log.LogDebug($"Creating new machine in common converter for AssetUid = {assetUid}, JohnDoe = {isJohnDoe}, machineId = {machineId}, machineHardwareId = {machineHardwareId}"); Machine = Machines.CreateNew(machineId, machineHardwareId, machineType, DeviceTypeEnum.MANUALDEVICE, isJohnDoe, assetUid); } if (Machine.MachineType == MachineType.Unknown && machineType != MachineType.Unknown) { Machine.MachineType = machineType; } var holdMachineType = Machine.MachineType; // Locate the aggregator, adding one if necessary var machineTargetValueChangesAggregator = MachinesTargetValueChangesAggregator[Machine.InternalSiteModelMachineIndex] as ProductionEventLists; if (machineTargetValueChangesAggregator == null) { machineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, Machine.InternalSiteModelMachineIndex); MachinesTargetValueChangesAggregator.Add(machineTargetValueChangesAggregator); } Processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, machineTargetValueChangesAggregator); // If ACS coordinate system populate converted UTM coordinates if (IsUTMCoordinateSystem && tagFilePreScan.ProcessedEpochCount > 0) { if (aCSBladePositions != null && aCSBladePositions.Count > 0) { Processor.ConvertedBladePositions.AddRange(aCSBladePositions); } if (ACSRearAxlePositions != null && ACSRearAxlePositions.Count > 0) { Processor.ConvertedRearAxlePositions.AddRange(ACSRearAxlePositions); } if (ACSTrackPositions != null && ACSTrackPositions.Count > 0) { Processor.ConvertedTrackPositions.AddRange(ACSTrackPositions); } if (ACSWheelPositions != null && ACSWheelPositions.Count > 0) { Processor.ConvertedWheelPositions.AddRange(ACSWheelPositions); } } var sink = new TAGValueSink(Processor); using (var reader = new TAGReader(tagData)) { var tagFile = new TAGFile(); ReadResult = tagFile.Read(reader, sink); // Notify the processor that all reading operations have completed for the file Processor.DoPostProcessFileAction(ReadResult == TAGReadResult.NoError); SetPublishedState(Processor); Machine.MachineType = holdMachineType; if (ReadResult != TAGReadResult.NoError) { return(false); } } } catch (Exception e) // make sure any exception is trapped to return correct response to caller { Log.LogError(e, "Exception occurred while converting a TAG file"); return(false); } return(true); }
/// <summary> /// Execute the conversion operation on the Volvo earthworks CSV file /// NOTE: This is a POC implementation and does not support some behaviours in the legacy TAG file ingest pathway /// </summary> public bool ExecuteVolvoEarthworksCSVFile(string filename, Stream tagData, Guid assetUid, bool isJohnDoe) { ReadResult = TAGReadResult.NoError; Log.LogInformation($"In {nameof(ExecuteVolvoEarthworksCSVFile)}: reading file {filename} for asset {assetUid}, JohnDoe: {isJohnDoe}"); try { var fileDescriptor = new VolvoEarthworksFileNameDescriptor(filename); Processor?.Dispose(); // Locate the machine in the local set of machines, adding one if necessary Machine = Machines.Locate(assetUid, true /*isJohnDoe - hard code Volvo machines to be John Does for POC*/); var machineType = MachineType.Unknown; var machineHardwareId = fileDescriptor.MachineID; var machineId = fileDescriptor.MachineID; if (Machine == null) { Log.LogDebug($"Creating new machine in common converter for AssetUid = {assetUid}, JohnDoe = {isJohnDoe}, machineId = {machineId}, machineHardwareId = {machineHardwareId}"); Machine = Machines.CreateNew(machineId, machineHardwareId, machineType, DeviceTypeEnum.MANUALDEVICE, isJohnDoe, assetUid); } var holdMachineType = Machine.MachineType; // Locate the aggregator, adding one if necessary var machineTargetValueChangesAggregator = MachinesTargetValueChangesAggregator[Machine.InternalSiteModelMachineIndex] as ProductionEventLists; if (machineTargetValueChangesAggregator == null) { machineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, Machine.InternalSiteModelMachineIndex); MachinesTargetValueChangesAggregator.Add(machineTargetValueChangesAggregator); } Processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, machineTargetValueChangesAggregator); var sink = new TAGValueSink(Processor); var reader = new VolvoEarthworksCSVReader(tagData); ReadResult = reader.Read(sink, Processor); // Notify the processor that all reading operations have completed for the file Processor.DoPostProcessFileAction(ReadResult == TAGReadResult.NoError); SetPublishedState(Processor); Machine.MachineType = holdMachineType; if (ReadResult != TAGReadResult.NoError) { return(false); } } catch (Exception e) // make sure any exception is trapped to return correct response to caller { Log.LogError(e, "Exception occurred while converting a Volvo CSV file"); return(false); } return(true); }