예제 #1
0
        /// <summary>
        /// Execute the pre-scan operation on the TAG file, returning a boolean success result.
        /// Sets up local state detailing the pre-scan fields retried from the ATG file
        /// </summary>
        public bool Execute(Stream TAGData)
        {
            try
            {
                Initialise();

                using (var Processor = new TAGProcessorPreScanState())
                {
                    var Sink = new TAGVisionLinkPrerequisitesValueSink(Processor);
                    using (var Reader = new TAGReader(TAGData))
                    {
                        var TagFile = new TAGFile();

                        ReadResult = TagFile.Read(Reader, Sink);
                    }

                    if (ReadResult != TAGReadResult.NoError)
                    {
                        return(false);
                    }

                    IsCSIBCoordSystemTypeOnly = Processor.IsCSIBCoordSystemTypeOnly;

                    SetPublishedState(Processor);
                }
            }
            catch // (Exception E) // make sure any exception is trapped to return correct response to caller
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Execute the pre-scan operation on the TAG file, returning a boolean success result.
        /// Sets up local state detailing the pre-scan fields retried from the ATG file
        /// </summary>
        public bool Execute(Stream TAGData, ref List <UTMCoordPointPair> aCSBladePositions, ref List <UTMCoordPointPair> aCSRearAxlePositions, ref List <UTMCoordPointPair> aCSTrackPositions, ref List <UTMCoordPointPair> aCSWheelPositions)
        {
            try
            {
                Initialise();

                using (var processor = new TAGProcessorPreScanACSState())
                {
                    var Sink = new TAGVisionLinkPrerequisitesValueSink(processor);
                    using (var Reader = new TAGReader(TAGData))
                    {
                        var TagFile = new TAGFile();

                        ReadResult = TagFile.Read(Reader, Sink);
                    }

                    if (ReadResult != TAGReadResult.NoError)
                    {
                        return(false);
                    }

                    IsCSIBCoordSystemTypeOnly = processor.IsCSIBCoordSystemTypeOnly;
                    if (!IsCSIBCoordSystemTypeOnly)
                    {
                        if (processor.HaveReceivedValidTipPositions)
                        {
                            aCSBladePositions.AddRange(processor.BladePositions);
                        }
                        if (processor.HaveReceivedValidRearPositions)
                        {
                            aCSRearAxlePositions.AddRange(processor.RearAxlePositions);
                        }
                        if (processor.HaveReceivedValidTrackPositions)
                        {
                            aCSTrackPositions.AddRange(processor.TrackPositions);
                        }
                        if (processor.HaveReceivedValidWheelPositions)
                        {
                            aCSWheelPositions.AddRange(processor.WheelPositions);
                        }
                    }
                    SetPublishedState(processor);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
        public void Test_TAGFile_Read_File()
        {
            // Create the TAG file and reader classes
            TAGFile file = new TAGFile();

            // Create the state and sink
            TAGProcessorStateBase stateBase = new TAGProcessorStateBase(); // Derivatives to construct later
            TAGValueSink          sink      = new TAGValueSink(stateBase);

            //Read the TAG file
            TAGReadResult result = file.Read(Path.Combine("TestData", "TAGFiles", "TestTAGFile-TAGFile-Read-File.tag"), sink);

            Assert.Equal(TAGReadResult.NoError, result);
        }
예제 #4
0
        public void Test_TAGFile_Read_Stream()
        {
            // Create the TAG file and reader classes
            TAGFile file = new TAGFile();

            using (var reader = new TAGReader(new FileStream(
                                                  Path.Combine("TestData", "TAGFiles", "TestTAGFile-TAGFile-Read-Stream.tag"), FileMode.Open,
                                                  FileAccess.Read)))
            {
                // Create the state and sink
                TAGProcessorStateBase stateBase = new TAGProcessorStateBase(); // Derivatives to construct later
                TAGValueSink          sink      = new TAGValueSink(stateBase);

                //Read the TAG file
                TAGReadResult result = file.Read(reader, sink);

                Assert.Equal(TAGReadResult.NoError, result);
            }
        }
예제 #5
0
        private static void ProcessTagFiles(string directoryToProcess, string[] dataList)
        {
            if (dataList == null)
            {
                Console.WriteLine($"No specific tag attributes requested, using defaults of {DEFAULT_DATA_LIST}");
            }
            var files = new List <string>();

            CollectTagFilesInFolder(directoryToProcess, files);

            TAGReader       reader    = null;
            FileStream      fs        = null;
            CSVTAGProcessor stateBase = null;

            foreach (var filename in files)
            {
                // Create the TAG file and reader classes
                var file = new TAGFile();

                try
                {
                    fs     = new FileStream(Path.GetFullPath(filename), FileMode.Open, FileAccess.Read);
                    reader = new TAGReader(fs);

                    // Create the state and sink
                    stateBase = new CSVTAGProcessor(dataList ?? DEFAULT_DATA_LIST, Path.GetFullPath(filename));
                    var sink = new TAGValueSink(stateBase);

                    //Read the TAG file
                    var result = file.Read(reader, sink);
                    Console.WriteLine($"File {filename} processed with result {result}");
                }
                finally
                {
                    fs?.Dispose();
                    reader?.Dispose();
                    stateBase?.Dispose();
                }
            }

            Console.WriteLine("Complete");
        }
예제 #6
0
        public void Test_TAGFile_Creation()
        {
            TAGFile file = new TAGFile();

            Assert.NotNull(file);
        }
예제 #7
0
        /// <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);
        }