Esempio n. 1
0
        private CompactionReportResult ConvertTRexGridResult(CompactionReportGridRequest request, Stream stream)
        {
            log.LogDebug($"{nameof(ConvertTRexGridResult)}: Retrieving response data from TRex");

            var griddedReportResult = new GriddedReportResult(ReportType.Gridded);

            griddedReportResult.Read((stream as MemoryStream)?.ToArray());

            var gridRows = new GridRow[griddedReportResult.GriddedData.NumberOfRows];

            // Populate an array of grid rows from the data
            for (var i = 0; i < griddedReportResult.GriddedData.NumberOfRows; i++)
            {
                gridRows[i] = GridRow.CreateRow(griddedReportResult.GriddedData.Rows[i], request);
            }

            var startTime = request.Filter != null && request.Filter.StartUtc.HasValue
        ? request.Filter.StartUtc.Value
        : DateTime.Now;
            var endTime = request.Filter != null && request.Filter.EndUtc.HasValue
        ? request.Filter.EndUtc.Value
        : DateTime.Now;

            var gridReport = GridReport.CreateGridReport(startTime, endTime, gridRows);

            return(CompactionReportResult.CreateExportDataResult(gridReport, 1));
        }
Esempio n. 2
0
        public void CutFillResult_Population_Successful()
        {
            var original       = new GriddedReportResult(ReportType.Gridded);
            var griddedDataRow = new GriddedReportDataRow()
            {
                Northing    = 1.0,
                Easting     = 2.0,
                Elevation   = 3.0,
                CutFill     = 4.0,
                Cmv         = 5,
                Mdp         = 6,
                PassCount   = 7,
                Temperature = 8
            };

            original.GriddedData.Rows.Add(griddedDataRow);
            original.GriddedData.ReportElevation   = true;
            original.GriddedData.ReportCutFill     = true;
            original.GriddedData.ReportCmv         = false;
            original.GriddedData.ReportMdp         = true;
            original.GriddedData.ReportPassCount   = false;
            original.GriddedData.ReportTemperature = true;

            var byteArrayOfOriginal = original.Write();
            var copyOfOrig          = new GriddedReportResult();

            copyOfOrig.Read(byteArrayOfOriginal);

            Assert.True(original.ReportType == copyOfOrig.ReportType, "Invalid report type");
            Assert.True(original.GriddedData.Rows.Count == copyOfOrig.GriddedData.Rows.Count, "Invalid number of rows");
            Assert.True(original.GriddedData.ReportCutFill == copyOfOrig.GriddedData.ReportCutFill, "Invalid ReportCutFull setting");
        }
Esempio n. 3
0
        public void CutFillResult_Streaming_Successful()
        {
            // When Response returned via MasterData Proxies,
            //  it is converted to byte[], then stream then file stream, then back
            var original       = new GriddedReportResult(ReportType.Gridded);
            var griddedDataRow = new GriddedReportDataRow()
            {
                Northing    = 1.0,
                Easting     = 2.0,
                Elevation   = 3.0,
                CutFill     = 4.0,
                Cmv         = 5,
                Mdp         = 6,
                PassCount   = 7,
                Temperature = 8
            };

            original.GriddedData.Rows.Add(griddedDataRow);
            original.GriddedData.ReportElevation   = true;
            original.GriddedData.ReportCutFill     = true;
            original.GriddedData.ReportCmv         = false;
            original.GriddedData.ReportMdp         = true;
            original.GriddedData.ReportPassCount   = false;
            original.GriddedData.ReportTemperature = true;

            var byteArrayOfOriginal = original.Write();
            var copyOfOrig          = new GriddedReportResult();

            copyOfOrig.Read(byteArrayOfOriginal);

            // Graceful WebReq
            var fileStream       = new FileStreamResult(new MemoryStream(byteArrayOfOriginal), ContentTypeConstants.ApplicationOctetStream);
            var memoryStream     = (MemoryStream)fileStream.FileStream;
            var resultFromStream = new GriddedReportResult();

            resultFromStream.Read(memoryStream.ToArray());

            Assert.True(ReportType.Gridded == resultFromStream.ReportType, "Invalid report type");
            Assert.True(original.GriddedData.Rows.Count == resultFromStream.GriddedData.Rows.Count, "Invalid number of rows");
            Assert.True(original.GriddedData.ReportCutFill == resultFromStream.GriddedData.ReportCutFill, "Invalid ReportCutFull setting");
        }
Esempio n. 4
0
        private ExportResult ConvertTRexGridResult(Stream stream)
        {
            log.LogDebug($"{nameof(ConvertTRexGridResult)}: Retrieving response data from TRex");

            try
            {
                var griddedReportResult = new GriddedReportResult(ReportType.Gridded);
                griddedReportResult.Read((stream as MemoryStream)?.ToArray());

                var outputStream = new MemoryStream();
                var sb           = new StringBuilder();

                sb.Append($"{STR_NORTHING}, {STR_EASTING}");

                if (griddedReportResult.GriddedData.ReportElevation)
                {
                    sb.Append($", {STR_ELEVATION}");
                }
                if (griddedReportResult.GriddedData.ReportCutFill)
                {
                    sb.Append($", {STR_CUT_FILL}");
                }
                if (griddedReportResult.GriddedData.ReportCmv)
                {
                    sb.Append($", {STR_CMV}");
                }
                if (griddedReportResult.GriddedData.ReportMdp)
                {
                    sb.Append($", {STR_MDP}");
                }
                if (griddedReportResult.GriddedData.ReportPassCount)
                {
                    sb.Append($", {STR_PASS_COUNT}");
                }
                if (griddedReportResult.GriddedData.ReportTemperature)
                {
                    sb.Append($", {STR_TEMPERATURE}");
                }
                sb.Append(STR_INSERT_LINE);

                // Write a header...
                var bytes = Encoding.ASCII.GetBytes(sb.ToString());
                outputStream.Write(bytes, 0, bytes.Length);

                // Write a series of CSV records from the data...
                foreach (GriddedReportDataRowBase row in griddedReportResult.GriddedData.Rows)
                {
                    sb.Clear();

                    sb.Append(string.Format(CultureInfo.InvariantCulture, "{0:F3}, {1:F3}", row.Northing, row.Easting));
                    if (griddedReportResult.GriddedData.ReportElevation)
                    {
                        sb.Append(string.Format(CultureInfo.InvariantCulture, ", {0:F3}", row.Elevation));
                    }
                    if (griddedReportResult.GriddedData.ReportCutFill)
                    {
                        sb.Append(row.CutFill == VelociraptorConstants.NULL_SINGLE
              ? ", "
              : string.Format(CultureInfo.InvariantCulture, ", {0:F3}", row.CutFill));
                    }
                    if (griddedReportResult.GriddedData.ReportCmv)
                    {
                        sb.Append(row.Cmv == VelociraptorConstants.NO_CCV
              ? ", "
              : string.Format(CultureInfo.InvariantCulture, ", {0}", row.Cmv));
                    }
                    if (griddedReportResult.GriddedData.ReportMdp)
                    {
                        sb.Append(row.Mdp == VelociraptorConstants.NO_MDP
              ? ", "
              : string.Format(CultureInfo.InvariantCulture, ", {0}", row.Mdp));
                    }
                    if (griddedReportResult.GriddedData.ReportPassCount)
                    {
                        sb.Append(row.PassCount == VelociraptorConstants.NO_PASSCOUNT
              ? ", "
              : string.Format(CultureInfo.InvariantCulture, ", {0}", row.PassCount));
                    }
                    if (griddedReportResult.GriddedData.ReportTemperature)
                    {
                        sb.Append(row.Temperature == VelociraptorConstants.NO_TEMPERATURE
              ? ", "
              : string.Format(CultureInfo.InvariantCulture, ", {0}", row.Temperature));
                    }
                    sb.Append(STR_INSERT_LINE);

                    bytes = Encoding.ASCII.GetBytes(sb.ToString());
                    outputStream.Write(bytes, 0, bytes.Length);
                }

                outputStream.Close();

                return(ExportResult.Create(outputStream.ToArray(), 1));
            }
            catch
            {
                throw CreateServiceException <ExportGridCSVExecutor>();
            }
        }