public void LoadFile() { using var stream = new FileStream(FILENAME, FileMode.Open, FileAccess.Read); var file = new VolvoEarthworksCSVReader(stream); 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); var processor = new TAGProcessor(siteModel, machine, siteModelGridAggregator, machineTargetValueChangesAggregator); file.Read(null, processor); processor.ProcessedEpochCount.Should().Be(19325); siteModelGridAggregator.CountLeafSubGridsInMemory().Should().Be(11); }
public void Creation() { var file = new VolvoEarthworksCSVReader(null); file.Should().NotBeNull(); }
/// <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); }