Ejemplo n.º 1
0
        /// <summary>
        /// Executor that implements requesting and rendering sub grid information to create the cell datum
        /// </summary>
        public async Task <CellDatumResponse_ApplicationService> ExecuteAsync(CellDatumRequestArgument_ApplicationService arg)
        {
            Log.LogInformation($"Performing Execute for DataModel:{arg.ProjectID}, Mode={arg.Mode}");

            var result = new CellDatumResponse_ApplicationService
            {
                ReturnCode = CellDatumReturnCode.UnexpectedError, DisplayMode = arg.Mode, Northing = arg.Point.Y, Easting = arg.Point.X
            };

            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(arg.ProjectID);

            if (siteModel == null)
            {
                Log.LogError($"Failed to locate site model {arg.ProjectID}");
                return(result);
            }

            if (!arg.CoordsAreGrid)
            {
                //WGS84 coords need to be converted to NEE
                var pointToConvert = new XYZ(arg.Point.X, arg.Point.Y, 0);
                arg.Point       = DIContext.Obtain <ICoreXWrapper>().LLHToNEE(siteModel.CSIB(), pointToConvert.ToCoreX_XYZ(), CoreX.Types.InputAs.Radians).ToTRex_XYZ();
                result.Northing = arg.Point.Y;
                result.Easting  = arg.Point.X;
            }

            var existenceMap = siteModel.ExistenceMap;

            // Determine the on-the-ground cell
            siteModel.Grid.CalculateIndexOfCellContainingPosition(arg.Point.X, arg.Point.Y, out int OTGCellX, out int OTGCellY);

            if (!existenceMap[OTGCellX >> SubGridTreeConsts.SubGridIndexBitsPerLevel, OTGCellY >> SubGridTreeConsts.SubGridIndexBitsPerLevel])
            {
                result.ReturnCode = CellDatumReturnCode.NoValueFound;
                return(result);
            }

            //Now get the production data for this cell
            var argClusterCompute = new CellDatumRequestArgument_ClusterCompute(
                arg.ProjectID, arg.Mode, arg.Point, OTGCellX, OTGCellY, arg.Filters, arg.ReferenceDesign, arg.Overrides, arg.LiftParams);
            var request  = new CellDatumRequest_ClusterCompute();
            var response = await request.ExecuteAsync(argClusterCompute, new SubGridSpatialAffinityKey(SubGridSpatialAffinityKey.DEFAULT_SPATIAL_AFFINITY_VERSION_NUMBER_TICKS, arg.ProjectID, OTGCellX, OTGCellY));

            result.ReturnCode   = response.ReturnCode;
            result.Value        = response.Value;
            result.TimeStampUTC = response.TimeStampUTC;

            return(result);
        }
Ejemplo n.º 2
0
        public async Task StationOffsetReportExecutor_GotSiteAndFilter()
        {
            bool   reportElevation      = true;
            bool   reportCmv            = true;
            bool   reportMdp            = true;
            bool   reportPassCount      = true;
            bool   reportTemperature    = true;
            bool   reportCutFill        = false;
            Guid?  cutFillDesignUid     = null;
            double?cutFillDesignOffset  = null;
            var    alignmentDesignUid   = Guid.NewGuid();
            double crossSectionInterval = 1.0;
            double startStation         = 100;
            double endStation           = 200;

            double[] offsets = { -1, 0, 1 };

            var filter = new Productivity3D.Filter.Abstractions.Models.Filter(
                DateTime.SpecifyKind(new DateTime(2018, 1, 10), DateTimeKind.Utc),
                DateTime.SpecifyKind(new DateTime(2019, 2, 11), DateTimeKind.Utc), "", "",
                new List <MachineDetails>(), null, null, null, null, null, null
                );
            var filterResult = new FilterResult(null, filter, null, null, null, null, null, null, null);
            var siteModel    = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();

            var request = CompactionReportStationOffsetTRexRequest.CreateRequest(
                siteModel.ID, filterResult,
                reportElevation, reportCmv, reportMdp, reportPassCount, reportTemperature, reportCutFill,
                cutFillDesignUid, cutFillDesignOffset, alignmentDesignUid,
                crossSectionInterval, startStation, endStation, offsets, null, null);

            request.Validate();

            // Mock the export request functionality to return an empty report reponse to stimulate the desired success
            var mockCompute = IgniteMock.Immutable.mockCompute;

            mockCompute.Setup(x => x.ApplyAsync(It.IsAny <StationOffsetReportRequestComputeFunc_ApplicationService>(), It.IsAny <StationOffsetReportRequestArgument_ApplicationService>(), It.IsAny <CancellationToken>()))
            .Returns((StationOffsetReportRequestComputeFunc_ApplicationService func, StationOffsetReportRequestArgument_ApplicationService argument, CancellationToken token) => Task.FromResult(new StationOffsetReportRequestResponse_ApplicationService()));

            var executor = RequestExecutorContainer
                           .Build <StationOffsetReportExecutor>(DIContext.Obtain <IConfigurationStore>(),
                                                                DIContext.Obtain <ILoggerFactory>(),
                                                                DIContext.Obtain <IServiceExceptionHandler>());
            var result = await executor.ProcessAsync(request) as GriddedReportDataResult;

            result.Code.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            result.GriddedData.Should().NotBeNull();
            result.GriddedData.Should().NotBeEmpty();
        }
Ejemplo n.º 3
0
        public async Task CSVExportExecutor_GotSiteAndFilter()
        {
            bool   reportElevation     = true;
            bool   reportCmv           = true;
            bool   reportMdp           = true;
            bool   reportPassCount     = true;
            bool   reportTemperature   = true;
            bool   reportCutFill       = false;
            Guid?  cutFillDesignUid    = null;
            double?cutFillDesignOffset = null;
            double?gridInterval        = null;
            var    gridReportOption    = GridReportOption.Automatic;
            double startNorthing       = 800000;
            double startEasting        = 400000;
            double endNorthing         = 800010;
            double endEasting          = 400010;
            double azimuth             = 4;

            var filter = new Productivity3D.Filter.Abstractions.Models.Filter(
                DateTime.SpecifyKind(new DateTime(2018, 1, 10), DateTimeKind.Utc),
                DateTime.SpecifyKind(new DateTime(2019, 2, 11), DateTimeKind.Utc), "", "",
                new List <MachineDetails>(), null, null, null, null, null, null
                );
            var filterResult = new FilterResult(null, filter, null, null, null, null, null, null, null);
            var siteModel    = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();

            var request = new CompactionReportGridTRexRequest(
                siteModel.ID, filterResult,
                reportElevation, reportCmv, reportMdp, reportPassCount, reportTemperature, reportCutFill,
                cutFillDesignUid, cutFillDesignOffset,
                gridInterval, gridReportOption, startNorthing, startEasting, endNorthing, endEasting, azimuth, null, null);

            request.Validate();

            // Mock the export request functionality to return an empty gridded report reponse to stimulate the desired success
            var mockCompute = IgniteMock.Immutable.mockCompute;

            mockCompute.Setup(x => x.ApplyAsync(It.IsAny <GriddedReportRequestComputeFunc>(), It.IsAny <GriddedReportRequestArgument>(), It.IsAny <CancellationToken>())).Returns((GriddedReportRequestComputeFunc func, GriddedReportRequestArgument argument, CancellationToken token) => Task.FromResult(new GriddedReportRequestResponse()));

            var executor = RequestExecutorContainer
                           .Build <GriddedReportExecutor>(DIContext.Obtain <IConfigurationStore>(),
                                                          DIContext.Obtain <ILoggerFactory>(),
                                                          DIContext.Obtain <IServiceExceptionHandler>());
            var result = await executor.ProcessAsync(request) as GriddedReportDataResult;

            result?.Code.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            result?.GriddedData.Should().NotBeNull();
            result?.GriddedData.Should().NotBeEmpty();
        }
Ejemplo n.º 4
0
        public async void Remove()
        {
            AddApplicationRouting();

            var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();

            // Add te design to be removed
            var designID     = Guid.NewGuid();
            var existenceMap = new TRex.SubGridTrees.SubGridTreeSubGridExistenceBitMask();

            existenceMap[0, 0] = true;

            var addRequest  = new AddTTMDesignRequest();
            var addResponse = await addRequest.ExecuteAsync(new AddTTMDesignArgument
            {
                ProjectID        = siteModel.ID,
                DesignDescriptor = new DesignDescriptor(designID, "folder", "filename"),
                Extents          = new TRex.Geometry.BoundingWorldExtent3D(0, 0, 1, 1),
                ExistenceMap     = existenceMap
            });

            addResponse.Should().NotBeNull();
            addResponse.DesignUid.Should().Be(designID);
            addResponse.RequestResult.Should().Be(DesignProfilerRequestResult.OK);

            // Re-request the sitemodel to reflect the change
            siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(siteModel.ID, false);
            siteModel.Designs.Count.Should().Be(1);

            var removeRequest  = new RemoveTTMDesignRequest();
            var removeResponse = await removeRequest.ExecuteAsync(new RemoveTTMDesignArgument
            {
                ProjectID = siteModel.ID,
                DesignID  = designID
            });

            removeResponse.Should().NotBeNull();
            removeResponse.DesignUid.Should().Be(designID);
            removeResponse.RequestResult.Should().Be(DesignProfilerRequestResult.OK);

            // Re-request the sitemodel to reflect the change
            siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(siteModel.ID, false);
            siteModel.Designs.Count.Should().Be(0);

            var readExistenceMap = DIContext.Obtain <IExistenceMapServer>().GetExistenceMap(new NonSpatialAffinityKey(siteModel.ID,
                                                                                                                      BaseExistenceMapRequest.CacheKeyString(TRex.ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, designID)));

            readExistenceMap.Should().BeNull();
        }
Ejemplo n.º 5
0
        public void CSVExportHelper_StartEndDate()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            var startTime = DateTime.UtcNow.AddHours(-5);
            var endTime   = startTime.AddHours(2);

            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].StartEndRecordedDataEvents.PutValueAtDate(startTime, ProductionEventType.StartEvent);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].StartEndRecordedDataEvents.PutValueAtDate(endTime, ProductionEventType.EndEvent);

            var startEndDate = CSVExportHelper.GetDateRange(siteModel, null);

            startEndDate.startUtc.Should().Be(startTime);
            startEndDate.endUtc.Should().Be(endTime);
        }
Ejemplo n.º 6
0
        public static void SetMaxExportRowsConfig(int rowCount)
        {
            // this Fixture sets to Consts.DEFAULT_MAX_EXPORT_ROWS. Some tests need it to be something different.
            var moqConfiguration = DIContext.Obtain <Mock <IConfigurationStore> >();

            moqConfiguration.Setup(x => x.GetValueInt("MAX_EXPORT_ROWS")).Returns(rowCount);
            moqConfiguration.Setup(x => x.GetValueInt("MAX_EXPORT_ROWS", It.IsAny <int>())).Returns(rowCount);

            DIBuilder.Continue().Add(x => x.AddSingleton(moqConfiguration.Object)).Complete();

            var configuration = DIContext.Obtain <IConfigurationStore>();

            configuration.GetValueInt("MAX_EXPORT_ROWS").Should().Be(rowCount);
            configuration.GetValueInt("MAX_EXPORT_ROWS", 1).Should().Be(rowCount);
        }
Ejemplo n.º 7
0
        public void GatewayHelper_ContributingMachineMissing()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?>
            {
                new Guid(Guid.NewGuid().ToString())
            };
            var result = Assert.Throws <ServiceException>(() => GatewayHelper.ValidateMachines(contributingMachines, siteModel));

            result.Code.Should().Be(HttpStatusCode.BadRequest);
            result.GetResult.Code.Should().Be(ContractExecutionStatesEnum.ValidationError);
            result.GetResult.Message.Should().Be($"ValidateMachines: SiteModel: {siteModel.ID} machineUid not found: {contributingMachines[0]}");
        }
Ejemplo n.º 8
0
        public void GatewayHelper_ContributingMachineMultiExists()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine1  = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            var machine2  = siteModel.Machines.CreateNew("Test Machine 2", "", MachineType.Dozer, DeviceTypeEnum.SNM940, true, Guid.NewGuid());
            var machine3  = siteModel.Machines.CreateNew("Test Machine 3", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?>
            {
                new Guid(machine3.ID.ToString()),
                new Guid(machine2.ID.ToString())
            };

            GatewayHelper.ValidateMachines(contributingMachines, siteModel);
        }
Ejemplo n.º 9
0
        public SiteModelRebuilderManagerTests(DITAGFileAndSubGridRequestsWithIgniteFixture fixture)
        {
            DIContext.Obtain <ISiteModelRebuilderManager>().AbortAll();

            fixture.ClearDynamicFixtureContent();
            fixture.ResetDynamicMockedIgniteContent();

            // Modify the SiteModels instance to be mutable, rather than immutable to mimic the mutable context
            // project deletion operates in
            DIBuilder
            .Continue()
            .RemoveSingle <ISiteModels>()
            .Add(x => x.AddSingleton <ISiteModels>(new TRex.SiteModels.SiteModels(StorageMutability.Mutable)))
            .Complete();
        }
Ejemplo n.º 10
0
 private static void DependencyInjection()
 {
     DIBuilder
     .New()
     .AddLogging()
     .Add(x => x.AddSingleton <ITRexGridFactory>(new TRexGridFactory()))
     .Add(x => x.AddSingleton <IStorageProxyFactory>(new StorageProxyFactory()))
     .Build()
     .Add(x => x.AddSingleton <ISiteModels>(new SiteModels(() => DIContext.Obtain <IStorageProxyFactory>().ImmutableGridStorage())))
     .Add(x => x.AddSingleton <ISiteModelFactory>(new SiteModelFactory()))
     .Add(x => x.AddSingleton <IExistenceMaps>(new ExistenceMaps()))
     .Add(x => x.AddSingleton(new CalculateDesignElevationsServer()))
     .Add(x => x.AddSingleton <IDesignsService>(new DesignsService(StorageMutability.Immutable)))
     .Complete();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Executor that implements rebuilding of the project
        /// <returns></returns>
        /// </summary>
        public Task <bool> ExecuteAsync()
        {
            _log.LogInformation($"Performing Rebuild for DataModel:{_rebuildSiteModelRequestArgument?.ProjectID}, with deletion selectivity {_rebuildSiteModelRequestArgument.DeletionSelectivity}");

            if (Response.RebuildResult != RebuildSiteModelResult.OK)
            {
                _log.LogInformation($"Rebuilding site model {_rebuildSiteModelRequestArgument?.ProjectID}: Initial execution response state not OK ({Response.RebuildResult}) - aborting request");
                return(Task.FromResult(false));
            }

            //***********************************
            // TODO: LOTS OF STUFF HAPPENING HERE

            /*
             * Prerequisite: The request saves progress state and metadata into a special cache to monitor. Phase state changes should
             * cause notification to be send to the push notification service.
             *
             * 0(a). Check that the project referenced in the request is not already undergoing a rebuild operation. If there is an existing
             *       rebuild process active then abort. If there is an existing entry in the Complete state then continue with the rebuild.
             * <- At this point the request may return to the caller all steps after this point execute asynchronously outside the context of this executor ->
             * 1(a). Set phase state to Deleting
             * 1(b). Perform project deletion step and record result from that. Abort if there is an issue.
             * 2. Set phase state to Scanning
             * 2(b). Scan S3 Tag file archive bucket looking for entries in the form "[/Projects]/{projectUid}[/Machines]/{machineUid}/*.tag
             * 3. Sort all Tag file based on date, according to the same logic present in the TagFileSubmitter utility in TRex
             * 4(a). Set phase state to Submitting
             * 4(b). Submit all discovered, sorted, tag files using the SubmitTagFile request. Each request defines the project Uid (from the
             *    request) and the {machineUid} from the key for the Tag file. As each batch of TAG files are submitted this progress is updated in the
             *    tracking metadata to aid in restarting the process if it is interrupted
             * 5. Once all tag files are submitted then the tracking state is update to reflect the submission phase is complete
             *    -> Set phase state to Monitoring
             * 6. Determination of rebuild completion or progress estimation is not yet defined, but this could be managed by tagging TAG files
             *    in the processing queue with state that causes the TAG file processor to emit message based on on the tracking indication state on that file.
             * 7. An additional progress tracking request will be implemented to return the progress/tracking state metadata to allow a client to
             *    track and display this to a user if required.
             * 8. Set phase state to complete
             */
            //***********************************

            var result = DIContext.Obtain <ISiteModelRebuilderManager>().Rebuild(_siteModel.ID, false, _rebuildSiteModelRequestArgument.OriginS3TransferProxy);

            Response.RebuildResult = result ? RebuildSiteModelResult.OK : RebuildSiteModelResult.Pending;

            // Return to caller - all operations now are asynchronous
            _log.LogInformation($"Rebuild site model {_siteModel.ID} with selectivity = {_rebuildSiteModelRequestArgument.DeletionSelectivity}: In progress");

            return(Task.FromResult(true));
        }
Ejemplo n.º 12
0
        static async Task <int> Main(string[] args)
        {
            try
            {
                Console.WriteLine($"TRex service starting at {DateTime.Now}");

                ThreadPool.GetMinThreads(out var minWorkerThreads, out var minCompletionPortThreads);
                ThreadPool.GetMaxThreads(out var maxWorkerThreads, out var maxCompletionPortThreads);
                Console.WriteLine($"Thread pool: min threads {minWorkerThreads}/{minCompletionPortThreads}, max threads {maxWorkerThreads}/{maxCompletionPortThreads}");

                EnsureAssemblyDependenciesAreLoaded();
                DependencyInjection();

                DisplayEnvironmentVariablesToConsole();
                if (string.IsNullOrEmpty(DIContext.Obtain <IConfigurationStore>().GetValueString("ENABLE_TFA_SERVICE")))
                {
                    Console.WriteLine("*** Warning! **** Check for missing configuration values. e.g ENABLE_TFA_SERVICE");
                }

                var cancelTokenSource = new CancellationTokenSource();
                AppDomain.CurrentDomain.ProcessExit += (s, e) =>
                {
                    Console.WriteLine("Exiting");
                    DIContext.Obtain <ITRexGridFactory>().StopGrids();
                    cancelTokenSource.Cancel();
                };

                AppDomain.CurrentDomain.UnhandledException += TRexAppDomainUnhandledExceptionHandler.Handler;

                DoServiceInitialisation();

                await Task.Delay(-1, cancelTokenSource.Token);

                return(0);
            }
            catch (TaskCanceledException)
            {
                // Don't care as this is thrown by Task.Delay()
                Console.WriteLine("Process exit via TaskCanceledException (SIGTERM)");
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Unhandled exception: {e}");
                Console.WriteLine($"Stack trace: {e.StackTrace}");
                return(-1);
            }
        }
Ejemplo n.º 13
0
        public virtual void Initialise()
        {
            // Todo: Only first filter in filter set is currently used for surface & alignment mask designs or surveyed surface restriction driven by date range
            var PassFilter = FilterSet.Filters[0].AttributeFilter;
            var CellFilter = FilterSet.Filters[0].SpatialFilter;

            if (CellFilter.SurfaceDesignMaskDesignUid != Guid.Empty)
            {
                SurfaceDesignMaskDesign = SiteModel.Designs.Locate(CellFilter.SurfaceDesignMaskDesignUid);
                if (SurfaceDesignMaskDesign == null)
                {
                    throw new ArgumentException($"Design {CellFilter.SurfaceDesignMaskDesignUid} not found in project {SiteModel.ID}");
                }
            }

            if (SiteModel.SurveyedSurfaces?.Count > 0)
            {
                // Filter out any surveyed surfaces which don't match current filter (if any)
                // - realistically, this is time filters we're thinking of here

                FilteredSurveyedSurfaces = DIContext.Obtain <ISurveyedSurfaces>();

                SiteModel.SurveyedSurfaces?.FilterSurveyedSurfaceDetails(PassFilter.HasTimeFilter, PassFilter.StartTime,
                                                                         PassFilter.EndTime, PassFilter.ExcludeSurveyedSurfaces(), FilteredSurveyedSurfaces,
                                                                         PassFilter.SurveyedSurfaceExclusionList);

                if (FilteredSurveyedSurfaces?.Count == 0)
                {
                    FilteredSurveyedSurfaces = null;
                }
            }

            // Instantiate a single instance of the argument object for the surface elevation patch requests to obtain composite
            // elevation sub grids and populate it with the common elements for this set of sub grids being requested.
            SurfaceElevationPatchArg = new SurfaceElevationPatchArgument
                                           (siteModelID:  SiteModel.ID,
                                           oTGCellBottomLeftX: int.MaxValue,
                                           oTGCellBottomLeftY: int.MaxValue,
                                           cellSize: SiteModel.CellSize,
                                           includedSurveyedSurfaces: FilteredSurveyedSurfaces,
                                           surveyedSurfacePatchType: SurveyedSurfacePatchType.CompositeElevations,
                                           processingMap: new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Filled));

            var _cache   = DIContext.Obtain <ITRexSpatialMemoryCache>();
            var _context = _cache?.LocateOrCreateContext(SiteModel.ID, GridDataType.SurveyedSurfaceHeightAndTime, SurfaceElevationPatchArg.CacheFingerprint());

            SurfaceElevationPatchRequest = SurfaceElevationPatchRequestFactory(_cache, _context);
        }
Ejemplo n.º 14
0
        public void DeleteModel_WithSurveyedSurfaces(DeleteSiteModelSelectivity selectivity)
        {
            AddApplicationGridRouting();

            var model = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel(false);

            model.Should().NotBeNull();

            // TODO: Convert to request per designs
            DIContext.Obtain <ISurveyedSurfaceManager>().Add(model.ID, new DesignDescriptor(Guid.NewGuid(), "", ""), DateTime.UtcNow, new BoundingWorldExtent3D(0, 0, 1, 1),
                                                             new SubGridTreeSubGridExistenceBitMask());
            SaveAndVerifyNotEmpty(model);

            DeleteTheModel(ref model, selectivity, selectivity == DeleteSiteModelSelectivity.All);
            (model?.SurveyedSurfaces?.Count ?? 0).Should().Be(0);
        }
Ejemplo n.º 15
0
        public CalculateDesignElevationSpotResponse Invoke(CalculateDesignElevationSpotArgument args)
        {
            try
            {
                var Executor = new CalculateDesignElevationSpot();

                return(Executor.Execute(DIContext.ObtainRequired <ISiteModels>().GetSiteModel(args.ProjectID), args.ReferenceDesign, args.SpotX, args.SpotY));
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception calculating design spot height");
                return(new CalculateDesignElevationSpotResponse {
                    Elevation = Common.Consts.NullDouble, CalcResult = DesignProfilerRequestResult.UnknownError
                });
            }
        }
Ejemplo n.º 16
0
        public async Task MachineStatusConvertCoords_OneMachine()
        {
            var machines = new List <MachineStatus>()
            {
                new MachineStatus
                    (Consts.NULL_LEGACY_ASSETID, "", false, "", null, null,
                    lastKnownLatitude: null, lastKnownLongitude: null,
                    lastKnownX: 2313, lastKnownY: 1204)
            };

            var result = await DIContext.Obtain <ICoordinateServiceUtility>().PatchLLH(TestCommonConsts.DIMENSIONS_2012_DC_CSIB, machines);

            result.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            machines[0].lastKnownLongitude.Should().Be(-115.03727717865179);
            machines[0].lastKnownLatitude.Should().Be(36.217306995697705);
        }
Ejemplo n.º 17
0
        public void ReadWritePersistentStore()
        {
            var l  = new MachinesList();
            var m  = l.CreateNew("Machine1", "HardwareID1", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            var m2 = l.CreateNew("Machine2", "HardwareID2", MachineType.Dozer, DeviceTypeEnum.SNM940, true, Guid.Empty);

            // Save it then read it back
            l.SaveToPersistentStore(DIContext.Obtain <ISiteModels>().PrimaryMutableStorageProxy);

            // read it back
            var l2 = new MachinesList();

            l2.LoadFromPersistentStore(DIContext.Obtain <ISiteModels>().PrimaryMutableStorageProxy);

            l.Should().BeEquivalentTo(l2);
        }
Ejemplo n.º 18
0
        public async void CallsRebuildManager_Async()
        {
            var mockManager = new Mock <ISiteModelRebuilderManager>();

            mockManager.Setup(x => x.Rebuild(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <TransferProxyType>())).Returns(true);

            DIBuilder
            .Continue()
            .Add(x => x.AddSingleton(mockManager.Object))
            .Complete();

            var executor = new ProjectRebuildExecutor(DIContext.Obtain <IConfigurationStore>(), DIContext.Obtain <ILoggerFactory>(), new Mock <IServiceExceptionHandler>().Object);
            await executor.ProcessAsync(new ProjectRebuildRequest(Guid.NewGuid(), TransferProxyType.TAGFiles, false));

            mockManager.Verify(x => x.Rebuild(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <TransferProxyType>()), Times.Once);
        }
Ejemplo n.º 19
0
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = CastRequestObjectTo <CSFileValidationRequest>(item);

            var coordinateSystem = DIContext
                                   .Obtain <ICoreXWrapper>()
                                   .GetCSDFromDCFileContent(System.Text.Encoding.UTF8.GetString(request.CSFileContent, 0, request.CSFileContent.Length));

            if (coordinateSystem != null && coordinateSystem.ZoneInfo != null && coordinateSystem.DatumInfo != null)
            {
                return(ConvertResult(request.CSFileName, coordinateSystem));
            }

            throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.FailedToGetResults,
                                                                                              $"Failed to convert DC File {request.CSFileName} content to Coordinate System definition data."));
        }
Ejemplo n.º 20
0
        public JsonResult GetEventListAsText(string siteModelID,
                                             string machineID,
                                             int eventType,
                                             [FromQuery] DateTime startDate,
                                             [FromQuery] DateTime endDate,
                                             [FromQuery] int maxEventsToReturn)
        {
            ISiteModel siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(Guid.Parse(siteModelID));
            IMachine   machine   = siteModel?.Machines.Locate(Guid.Parse(machineID));

            if (siteModel == null || machine == null)
            {
                return(new JsonResult($"Site model {siteModelID} and/or machine {machineID} unknown"));
            }

            return(new JsonResult(siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].GetEventList((ProductionEventType)eventType).ToStrings(startDate.ToUniversalTime(), endDate.ToUniversalTime(), maxEventsToReturn)));
        }
Ejemplo n.º 21
0
 private static void DependencyInjection()
 {
     DIBuilder
     .New()
     .AddLogging()
     .Add(x => x.AddSingleton <ITRexGridFactory>(new TRexGridFactory()))
     .Add(x => x.AddSingleton <IStorageProxyFactory>(new StorageProxyFactory()))
     .Add(x => x.AddTransient <ISurveyedSurfaces>(factory => new SurveyedSurfaces()))
     .Build()
     .Add(x => x.AddSingleton <ISiteModels>(new SiteModels(() => DIContext.Obtain <IStorageProxyFactory>().ImmutableGridStorage())))
     .Add(x => x.AddSingleton <ISiteModelFactory>(new SiteModelFactory()))
     .Add(x => x.AddSingleton(new ImmutableClientServer("TRexIgniteClient-Framework")))
     .Add(x => x.AddSingleton(new MutableClientServer("TRexIgniteClient-Framework")))
     .Add(x => x.AddSingleton <IDesignManager>(factory => new DesignManager()))
     .Add(x => x.AddSingleton <ISurveyedSurfaceManager>(factory => new SurveyedSurfaceManager()))
     .Complete();
 }
Ejemplo n.º 22
0
        public bool Process(IMutableCacheEntry <INonSpatialAffinityKey, byte[]> entry, Guid arg)
        {
            ISurveyedSurfaces ss = DIContext.Obtain <ISurveyedSurfaces>();

            if (entry.Exists)
            {
                ss.FromBytes(entry.Value);
            }

            if (ss.RemoveSurveyedSurface(arg))
            {
                entry.Value = ss.ToBytes();
                return(true);
            }

            return(false);
        }
Ejemplo n.º 23
0
        public void RebuildIsReflectedInManagerState()
        {
            AddPrimaryApplicationGridRouting();

            var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();

            siteModel.SaveMetadataToPersistentStore(siteModel.PrimaryStorageProxy, true);

            var manager = DIContext.Obtain <ISiteModelRebuilderManager>();
            var result  = manager.Rebuild(siteModel.ID, false, TransferProxyType.TAGFiles);

            result.Should().BeTrue();

            var state = manager.GetRebuildersState();

            state.Count.Should().Be(1);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// List the surveyed surfaces for a site model
        /// </summary>
        public ISurveyedSurfaces List(Guid SiteModelID)
        {
            INonSpatialAffinityKey cacheKey = CacheKey(SiteModelID);

            Log.LogInformation($"Listing surveyed surfaces from {cacheKey}");

            try
            {
                ISurveyedSurfaces ss = DIContext.Obtain <ISurveyedSurfaces>();
                ss.FromBytes(mutableNonSpatialCache.Get(cacheKey));
                return(ss);
            }
            catch (KeyNotFoundException)
            {
                return(null);
            }
        }
Ejemplo n.º 25
0
        public void StartListening()
        {
            _log.LogInformation($"Start listening for TAG file processing events on {MessageTopicName}");

            // Create a messaging group the cluster can use to send messages back to and establish a local listener
            // All nodes (client and server) want to know about TAG file processing notifications
            var MsgGroup = DIContext.Obtain <ITRexGridFactory>()?.Grid(Storage.Models.StorageMutability.Mutable)?.GetCluster().GetMessaging();

            if (MsgGroup != null)
            {
                MsgGroup.LocalListen(this, MessageTopicName);
            }
            else
            {
                _log.LogError("Unable to get messaging projection to add project rebuilder TAG file processed listener to");
            }
        }
Ejemplo n.º 26
0
        public bool Invoke(Guid nodeId, IRebuildSiteModelTAGNotifierEvent message)
        {
            var responseCount = 0;

            try
            {
                responseCount = message.ResponseItems?.Length ?? 0;
                _log.LogInformation($"Received notification of TAG file processing for {message.ProjectUid}, #TAG files = {responseCount}");

                if (responseCount > 0)
                {
                    // Tell the rebuilder manager instance about the notification
                    var rebuilderManager = DIContext.Obtain <ISiteModelRebuilderManager>();
                    if (rebuilderManager != null)
                    {
                        Task.Run(() =>
                        {
                            try
                            {
                                rebuilderManager.TAGFileProcessed(message.ProjectUid, message.ResponseItems);
                            }
                            catch (Exception e)
                            {
                                _log.LogError(e, "Exception handling TAG file processed notification event");
                            }
                        });
                    }
                    else
                    {
                        _log.LogError("No ISiteModelRebuilderManager instance available from DIContext to send TAG file processing notification to");
                        return(true); // Stay subscribed
                    }
                }
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception handling TAG file processed notification event");
                return(true); // Stay subscribed
            }
            finally
            {
                _log.LogInformation($"Completed handling of notification of TAG file processing for {message?.ProjectUid}, #TAG files = {responseCount}");
            }

            return(true);
        }
Ejemplo n.º 27
0
        public ISiteModelAttributesChangedEventSenderResponse Invoke(ISiteModelAttributesChangedEvent arg)
        {
            var localNodeId = Guid.Empty;

            try
            {
                var siteModels = DIContext.Obtain <ISiteModels>();
                if (siteModels == null)
                {
                    _log.LogError("No ISiteModels instance available from DIContext to send attributes change message to");

                    return(new SiteModelAttributesChangedEventSenderResponse {
                        Success = false, NodeUid = localNodeId
                    });
                }

                localNodeId = DIContext.ObtainRequired <ITRexGridFactory>().Grid(siteModels.PrimaryMutability).GetCluster().GetLocalNode().Id;

                _log.LogInformation(
                    $"Received notification of site model attributes changed for {arg.SiteModelID}: ExistenceMapModified={arg.ExistenceMapModified}, DesignsModified={arg.DesignsModified}, SurveyedSurfacesModified {arg.SurveyedSurfacesModified} CsibModified={arg.CsibModified}, MachinesModified={arg.MachinesModified}, MachineTargetValuesModified={arg.MachineTargetValuesModified}, AlignmentsModified {arg.AlignmentsModified}, ExistenceMapChangeMask {arg.ExistenceMapChangeMask != null}");

                // Tell the SiteModels instance to reload the designated site model that has changed
                siteModels.SiteModelAttributesHaveChanged(arg);

                return(new SiteModelAttributesChangedEventSenderResponse
                {
                    Success = true,
                    NodeUid = localNodeId
                });
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception occurred processing site model attributes changed event");

                return(new SiteModelAttributesChangedEventSenderResponse
                {
                    Success = false,
                    NodeUid = localNodeId
                });
            }
            finally
            {
                _log.LogInformation(
                    $"Completed handling notification of site model attributes changed for '{arg.SiteModelID}': ExistenceMapModified={arg.ExistenceMapModified}, DesignsModified={arg.DesignsModified}, SurveyedSurfacesModified {arg.SurveyedSurfacesModified} CsibModified={arg.CsibModified}, MachinesModified={arg.MachinesModified}, MachineTargetValuesModified={arg.MachineTargetValuesModified}, AlignmentsModified {arg.AlignmentsModified}, ExistenceMapChangeMask {arg.ExistenceMapChangeMask != null}");
            }
        }
Ejemplo n.º 28
0
 public string SetGridStatus(string gridName, bool status)
 {
     try
     {
         IIgnite ignite = DIContext.Obtain <ITRexGridFactory>().Grid(gridName);
         ignite.GetCluster().SetActive(status);
     }
     catch (ArgumentException ex)
     {
         return(ex.Message);
     }
     catch (NullReferenceException ex)
     {
         return($"{ex.Message} \n this usually indicates are failure to get ignite");
     }
     return($"Set grid {gridName} to {status}, this may take time to happen, use status/gridName to check status");
 }
Ejemplo n.º 29
0
        public void Test_RequestorUtilities_CreateIntermediaries_MultipleFilters_WithOneOfTwoSurveyedSurfacesExcluded(int filterCount)
        {
            var ru = new RequestorUtilities();

            ISurveyedSurfaces surveyedSurfaces = DIContext.Obtain <ISurveyedSurfaces>();

            // Create two surveyed surfaces that bracket current time by one day either side and set the filter end time to be current time
            // which will cause only one surveyed surface to be filtered
            Guid ssGuid1 = Guid.NewGuid();
            var  ss1     = surveyedSurfaces.AddSurveyedSurfaceDetails(ssGuid1, DesignDescriptor.Null(), DateTime.UtcNow.AddDays(-1), BoundingWorldExtent3D.Null());

            Guid ssGuid2 = Guid.NewGuid();
            var  ss2     = surveyedSurfaces.AddSurveyedSurfaceDetails(ssGuid2, DesignDescriptor.Null(), DateTime.UtcNow.AddDays(+1), BoundingWorldExtent3D.Null());

            var mockGrid = new Mock <IServerSubGridTree>();

            mockGrid.Setup(x => x.CellSize).Returns(SubGridTreeConsts.DefaultCellSize);

            var mockSiteModel = new Mock <ISiteModel>();

            mockSiteModel.Setup(x => x.SurveyedSurfacesLoaded).Returns(true);
            mockSiteModel.Setup(x => x.SurveyedSurfaces).Returns(surveyedSurfaces);
            mockSiteModel.Setup(x => x.Grid).Returns(mockGrid.Object);

            ICombinedFilter[] filters = Enumerable.Range(1, filterCount).Select(x =>
            {
                var filter = new CombinedFilter();
                filter.AttributeFilter.SurveyedSurfaceExclusionList = new[] { ssGuid1 };
                return(filter);
            }).ToArray();
            IFilterSet filterSet = new FilterSet(filters);

            var intermediaries = ru.ConstructRequestorIntermediaries(mockSiteModel.Object, filterSet, true, GridDataType.Height);

            intermediaries.Length.Should().Be(filters.Length);

            for (int i = 0; i < intermediaries.Length; i++)
            {
                intermediaries[i].Filter.Should().Be(filters[i]);
                intermediaries[i].FilteredSurveyedSurfaces.Should().Equal(new List <ISurveyedSurface> {
                    ss2
                });
                intermediaries[i].CacheContexts[0].Should().NotBeNull();
                intermediaries[i].surfaceElevationPatchRequest.Should().Be(_fixture.SurfaceElevationPatchRequest);
            }
        }
Ejemplo n.º 30
0
        public void StartListening()
        {
            Log.LogInformation($"Start listening for site model notification events on {MessageTopicName}");

            // Create a messaging group the cluster can use to send messages back to and establish a local listener
            // All nodes (client and server) want to know about site model attribute changes
            var MsgGroup = DIContext.Obtain <ITRexGridFactory>()?.Grid(GridName)?.GetCluster().GetMessaging();

            if (MsgGroup != null)
            {
                MsgGroup.LocalListen(this, MessageTopicName);
            }
            else
            {
                Log.LogError("Unable to get messaging projection to add site model attribute changed event to");
            }
        }
Ejemplo n.º 31
0
 public DIContext Init()
 {
     return dbContext ?? (dbContext = new DIContext());
 }