Beispiel #1
0
        public void Test_TAGFilePreScan_NEEposition()
        {
            //  Lat/Long refers to the GPS_BASE_Position
            //    therefore SeedLatitude and SeedLongitude not available
            //    NE can be used along with the projects CSIB to resolve to a LL

            var preScan = new TAGFilePreScan();

            Assert.True(preScan.Execute(new FileStream(Path.Combine("TestData", "TAGFiles", "SeedPosition-usingNEE.tag"), FileMode.Open, FileAccess.Read)),
                        "Pre-scan execute returned false");

            preScan.ProcessedEpochCount.Should().Be(1);
            preScan.ReadResult.Should().Be(TAGReadResult.NoError);
            preScan.SeedLatitude.Should().Be(null);
            preScan.SeedLongitude.Should().Be(null);
            preScan.SeedHeight.Should().Be(null);
            preScan.SeedNorthing.Should().Be(5876814.5384829007);
            preScan.SeedEasting.Should().Be(7562822.7801738745);
            preScan.SeedElevation.Should().Be(127.31059507932183);
            preScan.SeedTimeUTC.Should().Be(System.DateTime.Parse("2020-06-05T23:29:53.761", System.Globalization.NumberFormatInfo.InvariantInfo));
            preScan.RadioType.Should().Be("torch");
            preScan.RadioSerial.Should().Be("5850F00892");
            preScan.MachineType.Should().Be(MachineType.Excavator);
            preScan.MachineID.Should().Be("M316F PAK115");
            preScan.HardwareID.Should().Be("1639J101YU");
            preScan.DesignName.Should().Be("L03P");
            preScan.ApplicationVersion.Should().Be("EW-1.11.0-2019_3 672");
        }
Beispiel #2
0
        /// <summary>
        /// reads and validates tagFile, returning model for multi-use
        /// </summary>
        public static ContractExecutionResult PreScanTagFile(TagFileDetail tagDetail, out TAGFilePreScan tagFilePreScan)
        {
            tagFilePreScan = new TAGFilePreScan();

            if (tagDetail.tagFileContent.Length <= minTagFileLength)
            {
                return(new ContractExecutionResult((int)TRexTagFileResultCode.TRexInvalidTagfile, TRexTagFileResultCode.TRexInvalidTagfile.ToString()));
            }

            using (var stream = new MemoryStream(tagDetail.tagFileContent))
                tagFilePreScan.Execute(stream);

            if (tagFilePreScan.ReadResult != TAGReadResult.NoError)
            {
                return(new ContractExecutionResult((int)TRexTagFileResultCode.TRexTagFileReaderError, tagFilePreScan.ReadResult.ToString()));
            }
            return(new ContractExecutionResult((int)TRexTagFileResultCode.Valid));
        }
Beispiel #3
0
        public void Test_TAGFilePreScan_Creation()
        {
            TAGFilePreScan preScan = new TAGFilePreScan();

            preScan.ReadResult.Should().Be(TAGReadResult.NoError);
            preScan.SeedLatitude.Should().BeNull();
            preScan.SeedLongitude.Should().BeNull();
            preScan.SeedNorthing.Should().BeNull();
            preScan.SeedEasting.Should().BeNull();
            preScan.SeedElevation.Should().BeNull();
            preScan.SeedTimeUTC.Should().BeNull();
            preScan.RadioType.Should().Be(string.Empty);
            preScan.RadioSerial.Should().Be(string.Empty);
            preScan.MachineType.Should().Be(CellPassConsts.MachineTypeNull);
            preScan.MachineID.Should().Be(string.Empty);
            preScan.HardwareID.Should().Be(string.Empty);
            preScan.SeedHeight.Should().BeNull();
            preScan.DesignName.Should().Be(string.Empty);
            preScan.ApplicationVersion.Should().Be(string.Empty);
        }
Beispiel #4
0
        public async Task Test_PlatformSerialNoValidationOk()
        {
            // This test ensures platformSerialNumber (serial/deviceid) is extracted and used in validation. Note this Tagfile has no Radio Serial id. Only Serial id.
            var projectUid = Guid.NewGuid();
            var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), string.Empty, 40, 50);
            var moqResult  = new GetProjectUidsResult(projectUid.ToString(), null, null, 0, "success");

            SetupDITfa(true, moqRequest, moqResult);

            byte[] tagContent;
            using (var tagFileStream =
                       new FileStream(Path.Combine("TestData", "TAGFiles", "2415J078SW-Serial-Test.tag"), FileMode.Open, FileAccess.Read))
            {
                tagContent = new byte[tagFileStream.Length];
                tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length);
            }

            var td = new TagFileDetail()
            {
                assetId        = null,
                projectId      = null, // force validation on serial id
                tagFileName    = "2415J078SW-Serial-Test.tag",
                tagFileContent = tagContent,
                tccOrgId       = "",
                IsJohnDoe      = false
            };

            var tagFilePreScan = new TAGFilePreScan();

            await using (var stream = new MemoryStream(td.tagFileContent))
                tagFilePreScan.Execute(stream);
            var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false);

            Assert.True(result.Code == (int)TRexTagFileResultCode.Valid, "Failed to return a Valid request");
            Assert.True(td.projectId != null, "Failed to return a Valid projectID");
            Assert.Equal("success", result.Message);
        }
Beispiel #5
0
        public async Task DeviceLKS_CB460_SentOk()
        {
            var projectUid = Guid.NewGuid();

            SetupDIDeviceGateay(true);

            byte[] tagContent;
            using (var tagFileStream =
                       new FileStream(Path.Combine("TestData", "TAGFiles", "TestTAGFile.tag"),
                                      FileMode.Open, FileAccess.Read))
            {
                tagContent = new byte[tagFileStream.Length];
                tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length);
            }

            var td = new TagFileDetail()
            {
                assetId        = null,
                projectId      = projectUid,
                tagFileName    = "Test.tag",
                tagFileContent = tagContent,
                tccOrgId       = "",
                IsJohnDoe      = false
            };

            var tagFilePreScan = new TAGFilePreScan();

            await using (var stream = new MemoryStream(td.tagFileContent))
                tagFilePreScan.Execute(stream);
            Assert.NotNull(tagFilePreScan);
            Assert.Equal("0523J019SW", tagFilePreScan.HardwareID);

            var executor = new SubmitTAGFileExecutor();

            executor.SendDeviceStatusToDeviceGateway(td, tagFilePreScan);
        }
Beispiel #6
0
        public void Test_TAGFilePreScan_Execute_JapaneseDesign()
        {
            TAGFilePreScan preScan = new TAGFilePreScan();

            Assert.True(preScan.Execute(new FileStream(Path.Combine("TestData", "TAGFiles", "JapaneseDesignTagfileTest.tag"), FileMode.Open, FileAccess.Read)),
                        "Pre-scan execute returned false");

            preScan.ProcessedEpochCount.Should().Be(1222);
            preScan.ReadResult.Should().Be(TAGReadResult.NoError);
            preScan.SeedLatitude.Should().Be(0.65955923731934751);
            preScan.SeedLongitude.Should().Be(2.45317108556434);
            preScan.SeedHeight.Should().Be(159.53982475668218);
            preScan.SeedNorthing.Should().Be(198863.25259713328);
            preScan.SeedEasting.Should().Be(63668.71188769384);
            preScan.SeedElevation.Should().Be(114.32995182440192);
            preScan.SeedTimeUTC.Should().Be(System.DateTime.Parse("2019-06-17T01:43:14.8640000", System.Globalization.NumberFormatInfo.InvariantInfo));
            preScan.RadioType.Should().Be("torch");
            preScan.RadioSerial.Should().Be("5750F00368");
            preScan.MachineType.Should().Be(25);
            preScan.MachineID.Should().Be("320E03243");
            preScan.HardwareID.Should().Be("3337J201SW");
            preScan.DesignName.Should().Be("所沢地区 NO.210-NO.255");
            preScan.ApplicationVersion.Should().Be("13.11-RC1");
        }
Beispiel #7
0
        public void Test_TAGFilePreScan_Execute()
        {
            TAGFilePreScan preScan = new TAGFilePreScan();

            Assert.True(preScan.Execute(new FileStream(Path.Combine("TestData", "TAGFiles", "TestTAGFile.tag"), FileMode.Open, FileAccess.Read)),
                        "Pre-scan execute returned false");

            preScan.ProcessedEpochCount.Should().Be(1478);
            preScan.ReadResult.Should().Be(TAGReadResult.NoError);
            preScan.SeedLatitude.Should().Be(0.8551829920414814);
            preScan.SeedLongitude.Should().Be(-2.1377653549870974);
            preScan.SeedHeight.Should().Be(25.045071376845993);
            preScan.SeedNorthing.Should().Be(5427420.4410656113);
            preScan.SeedEasting.Should().Be(537671.61978842877);
            preScan.SeedElevation.Should().Be(41.549531624124079);
            preScan.SeedTimeUTC.Should().Be(System.DateTime.Parse("2014-08-26T17:40:39.3550000", System.Globalization.NumberFormatInfo.InvariantInfo));
            preScan.RadioType.Should().Be("torch");
            preScan.RadioSerial.Should().Be("5411502448");
            preScan.MachineType.Should().Be(39);
            preScan.MachineID.Should().Be("CB54XW  JLM00885");
            preScan.HardwareID.Should().Be("0523J019SW");
            preScan.DesignName.Should().Be("CAT DAY 22");
            preScan.ApplicationVersion.Should().Be("12.61-75222");
        }
Beispiel #8
0
        public void Test_TAGFilePreScan_Execute_NoSeedLLH()
        {
            var preScan = new TAGFilePreScan();

            Assert.True(preScan.Execute(new FileStream(Path.Combine("TestData", "TAGFiles", "TestTagFile_NoSeedLLHandNoUTM.tag"), FileMode.Open, FileAccess.Read)),
                        "Pre-scan execute returned false");

            preScan.ProcessedEpochCount.Should().Be(272);
            preScan.ReadResult.Should().Be(TAGReadResult.NoError);
            preScan.SeedLatitude.Should().BeNull();
            preScan.SeedLongitude.Should().BeNull();
            preScan.SeedHeight.Should().BeNull();
            preScan.SeedNorthing.Should().Be(121931.74737617122);
            preScan.SeedEasting.Should().Be(564022.58097323333);
            preScan.SeedElevation.Should().Be(398.75510795260766);
            preScan.SeedTimeUTC.Should().Be(System.DateTime.Parse("2012-07-26T08:52:46.0350000", System.Globalization.NumberFormatInfo.InvariantInfo));
            preScan.RadioType.Should().Be("torch");
            preScan.RadioSerial.Should().Be("5123545219");
            preScan.MachineType.Should().Be(25);
            preScan.MachineID.Should().Be("B LHR934 S33251");
            preScan.HardwareID.Should().Be("1112J010SW");
            preScan.DesignName.Should().Be("Monthey Kontaktboden C2c6");
            preScan.ApplicationVersion.Should().Be("12.20-53094");
        }
Beispiel #9
0
        public async Task Test_ValidateFailed_InvalidManualProjectType()
        {
            var projectUid = Guid.NewGuid();
            var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), string.Empty, 0, 0);
            var moqResult  = new GetProjectUidsResult(string.Empty, string.Empty, string.Empty, 3044, "Manual Import: cannot import to a Civil type project");

            SetupDITfa(true, moqRequest, moqResult);

            byte[] tagContent;
            using (var tagFileStream =
                       new FileStream(Path.Combine("TestData", "TAGFiles", "TestTAGFile.tag"),
                                      FileMode.Open, FileAccess.Read))
            {
                tagContent = new byte[tagFileStream.Length];
                tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length);
            }

            var td = new TagFileDetail()
            {
                assetId        = null,
                projectId      = projectUid,
                tagFileName    = "Test.tag",
                tagFileContent = tagContent,
                tccOrgId       = "",
                IsJohnDoe      = false
            };

            var tagFilePreScan = new TAGFilePreScan();

            await using (var stream = new MemoryStream(td.tagFileContent))
                tagFilePreScan.Execute(stream);
            var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false);

            Assert.True(result.Code == 3044, "Failed to return correct error code");
            Assert.Equal("Manual Import: cannot import to a Civil type project", result.Message);
        }
Beispiel #10
0
        public async Task Test_UsingNEE_ValidateOk()
        {
            var projectUid = Guid.NewGuid();
            var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), "1639J101YU", 0, 0, 5876814.5384829007, 7562822.7801738745);
            var moqResult  = new GetProjectUidsResult(projectUid.ToString(), string.Empty, string.Empty, 0, "success");

            SetupDITfa(true, moqRequest, moqResult);

            byte[] tagContent;
            using (var tagFileStream =
                       new FileStream(Path.Combine("TestData", "TAGFiles", "SeedPosition-usingNEE.tag"),
                                      FileMode.Open, FileAccess.Read))
            {
                tagContent = new byte[tagFileStream.Length];
                tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length);
            }

            var td = new TagFileDetail()
            {
                assetId        = null,
                projectId      = projectUid,
                tagFileName    = "Bug ccssscon-401 NEE SeedPosition.tag",
                tagFileContent = tagContent,
                tccOrgId       = "",
                IsJohnDoe      = false
            };

            var tagFilePreScan = new TAGFilePreScan();

            await using (var stream = new MemoryStream(td.tagFileContent))
                tagFilePreScan.Execute(stream);
            var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false);

            Assert.True(result.Code == (int)TRexTagFileResultCode.Valid, "Failed to return a Valid request");
            Assert.Equal("success", result.Message);
        }
Beispiel #11
0
        /// <summary>
        /// this needs to be public, only for unit tests
        /// </summary>
        public static async Task <GetProjectUidsResult> CheckFileIsProcessable(TagFileDetail tagDetail, TAGFilePreScan preScanState)
        {
            /*
             * Three different types of tagfile submission
             * Type A: Automatic submission.
             * This is where a tagfile comes in from a known org and the system works out what Asset and Project it belongs to. Licensing is checked
             *
             * Type B:  Manual submission.
             * This is where the project is known and supplied as an override projectid value. The Asset is worked out via TFA service or assigned a JohnDoe id if not known.
             * Licensing is checked for manual subscription
             *
             * Type C: Override submission.
             * This is where the ProjectId and AssetId is both supplied. It bypasses TFA service and providing the tagfile is valid, is processed straight into the project.
             * This is not a typical submission but is handy for testing and in a situation where a known third party source other than NG could determine the AssetId and Project. Typical NG users could not submit via this method thus avoiding our license check.
             */

            var platformSerialNumber = string.Empty;

            if (preScanState.PlatformType >= CWSDeviceTypeEnum.EC520 && preScanState.PlatformType <= CWSDeviceTypeEnum.TMC)
            {
                platformSerialNumber = preScanState.HardwareID;
            }


            // Type C. Do we have what we need already (Most likely test tool submission)
            if (tagDetail.assetId != null && tagDetail.projectId != null)
            {
                if (tagDetail.assetId != Guid.Empty && tagDetail.projectId != Guid.Empty)
                {
                    return(new GetProjectUidsResult(tagDetail.projectId.ToString(), tagDetail.assetId.ToString(), string.Empty, 0, "success"));
                }
            }

            if ((tagDetail.projectId == null || tagDetail.projectId == Guid.Empty) && string.IsNullOrEmpty(platformSerialNumber))
            {
                // this is a TFA code. This check is also done as a pre-check as the scenario is very frequent, to avoid the API call overhead.
                var message = "#Progress# CheckFileIsProcessable. Must have either a valid platformSerialNumber or ProjectUID";
                Log.LogWarning(message);
                return(new GetProjectUidsResult(tagDetail.projectId.ToString(), tagDetail.assetId.ToString(), string.Empty, (int)TRexTagFileResultCode.TRexMissingProjectUidAndPlatformSerial, message));
            }

            var seedLatitude  = MathUtilities.RadiansToDegrees(preScanState.SeedLatitude ?? 0.0);
            var seedLongitude = MathUtilities.RadiansToDegrees(preScanState.SeedLongitude ?? 0.0);
            var seedNorthing  = preScanState.SeedNorthing;
            var seedEasting   = preScanState.SeedEasting;

            if (Math.Abs(seedLatitude) < Consts.TOLERANCE_DECIMAL_DEGREE && Math.Abs(seedLongitude) < Consts.TOLERANCE_DECIMAL_DEGREE && (seedNorthing == null || seedEasting == null))
            {
                // This check is also done as a pre-check as the scenario is very frequent, to avoid the TFA API call overhead.
                var message = $"#Progress# CheckFileIsProcessable. Unable to determine a tag file seed position. projectID {tagDetail.projectId} serialNumber {platformSerialNumber} filename {tagDetail.tagFileName} Lat {preScanState.SeedLatitude} Long {preScanState.SeedLongitude} northing {preScanState.SeedNorthing} easting {preScanState.SeedNorthing}";
                Log.LogWarning(message);
                return(new GetProjectUidsResult(tagDetail.projectId.ToString(), tagDetail.assetId.ToString(), string.Empty, (int)TRexTagFileResultCode.TRexInvalidLatLong, message));
            }

            var tfaRequest = new GetProjectUidsRequest(
                tagDetail.projectId == null ? string.Empty : tagDetail.projectId.ToString(),
                platformSerialNumber,
                seedLatitude, seedLongitude,
                preScanState.SeedNorthing, preScanState.SeedEasting);

            Log.LogInformation($"#Progress# CheckFileIsProcessable. tfaRequest {JsonConvert.SerializeObject(tfaRequest)}");

            var tfaResult = await ValidateWithTfa(tfaRequest).ConfigureAwait(false);

            Log.LogInformation($"#Progress# CheckFileIsProcessable. TFA validate returned for {tagDetail.tagFileName} tfaResult: {JsonConvert.SerializeObject(tfaResult)}");
            if (tfaResult?.Code == (int)TRexTagFileResultCode.Valid)
            {
                // if not overriding take TFA projectid
                if ((tagDetail.projectId == null || tagDetail.projectId == Guid.Empty) && (Guid.Parse(tfaResult.ProjectUid) != Guid.Empty))
                {
                    tagDetail.projectId = Guid.Parse(tfaResult.ProjectUid);
                }

                // take what TFA gives us including an empty guid which is a JohnDoe
                tagDetail.assetId = string.IsNullOrEmpty(tfaResult.DeviceUid) ? Guid.Empty : (Guid.Parse(tfaResult.DeviceUid));

                // Check For JohnDoe machines. if you get a valid pass and no assetid it means it had a manual3dlicense
                if (tagDetail.assetId == Guid.Empty)
                {
                    tagDetail.IsJohnDoe = true; // JohnDoe Machine and OK to process
                }
            }

            return(tfaResult);
        }
Beispiel #12
0
        /// <summary>
        /// Inputs a tagfile for validation and asset licensing checks
        ///      includes already scanned tagfile
        /// </summary>
        public static async Task <ContractExecutionResult> ValidSubmission(TagFileDetail tagDetail, TAGFilePreScan tagFilePreScan)
        {
            // TAG file contents are OK so proceed
            if (!tfaServiceEnabled) // allows us to bypass a TFA service
            {
                if (WarnOnTFAServiceDisabled)
                {
                    Log.LogWarning("SubmitTAGFileResponse.ValidSubmission. EnableTFAService disabled. Bypassing TFS validation checks");
                }

                if (tagDetail.projectId != null && tagDetail.projectId != Guid.Empty) // do we have what we need
                {
                    if (tagDetail.assetId == null || tagDetail.assetId == Guid.Empty)
                    {
                        tagDetail.IsJohnDoe = true;
                    }
                    return(new ContractExecutionResult((int)TRexTagFileResultCode.Valid));
                }

                // cannot process without asset and project id
                return(new ContractExecutionResult((int)TRexTagFileResultCode.TRexBadRequestMissingProjectUid, "TRexTagFileResultCode.TRexBadRequestMissingProjectUid"));
            }

            // If the TFA service is enabled, but the TAG file has attributes that allow project and asset (or JohnDoe status) to be determined, then
            // allow the TAG file to be processed without additional TFA involvement

            if (tagDetail.projectId != null && tagDetail.projectId != Guid.Empty)
            {
                if ((tagDetail.assetId != null && tagDetail.assetId == Guid.Empty) || tagDetail.IsJohnDoe)
                {
                    return(new ContractExecutionResult((int)TRexTagFileResultCode.Valid));
                }
            }

            // Contact TFA service to validate tag file details
            var tfaResult = await CheckFileIsProcessable(tagDetail, tagFilePreScan).ConfigureAwait(false);

            return(new ContractExecutionResult((int)tfaResult.Code, tfaResult.Message));
        }