예제 #1
0
        public void Creation_Fail()
        {
            var descriptor = new VolvoEarthworksFileNameDescriptor("An Invalid FileName.csv");

            descriptor.Should().NotBeNull();
            descriptor.DecodedOK.Should().BeFalse();
        }
예제 #2
0
        public void Creation()
        {
            var descriptor = new VolvoEarthworksFileNameDescriptor(TEST_FILE_NAME);

            descriptor.Should().NotBeNull();
            descriptor.DecodedOK.Should().BeTrue();
        }
예제 #3
0
        public void Creation2()
        {
            var descriptor = new VolvoEarthworksFileNameDescriptor(TEST_FILE_NAME);

            descriptor.Lift.Should().Be("lift1");
            descriptor.DesignName.Should().Be("Lag 1");
            descriptor.Counter.Should().Be(1);
            descriptor.CSName.Should().Be("utm27W");
            descriptor.Date.Should().Be(DateTime.SpecifyKind(new DateTime(2020, 3, 11, 14, 19, 7), DateTimeKind.Utc));
            descriptor.MachineID.Should().Be("S135B556186");

            descriptor.DecodedOK.Should().BeTrue();
        }
예제 #4
0
        /// <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);
        }