Esempio n. 1
0
        /// <summary>
        /// Remove a given surveyed surface from a site model
        /// </summary>
        /// <param name="SiteModelID"></param>
        /// <param name="SurveySurfaceID"></param>
        /// <returns></returns>
        public bool RemoveDirect(Guid SiteModelID, Guid SurveySurfaceID)
        {
            // TODO: This should be done under a lock on the cache key. For now, we will live with the race condition

            try
            {
                INonSpatialAffinityKey cacheKey = CacheKey(SiteModelID);

                // Get the surveyed surfaces, creating it if it does not exist
                ISurveyedSurfaces ssList = DIContext.Obtain <ISurveyedSurfaces>();
                ssList.FromBytes(mutableNonSpatialCache.Get(cacheKey));

                // Add the new surveyed surface, generating a random ID from a GUID
                bool result = ssList.RemoveSurveyedSurface(SurveySurfaceID);

                // Put the list back into the cache with the new entry
                if (result)
                {
                    mutableNonSpatialCache.Put(cacheKey, ssList.ToBytes());
                }

                return(result);
            }
            catch (KeyNotFoundException)
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Notify all interested nodes in the immutable grid a site model has changed attributes
        /// </summary>
        public void DesignStateChanged(DesignNotificationGridMutability targetGrids, Guid siteModelUid, Guid designUid, ImportedFileType fileType, bool designRemoved = false)
        {
            var gridFactory = DIContext.Obtain <ITRexGridFactory>();
            var evt         = new DesignChangedEvent {
                SiteModelUid = siteModelUid, DesignUid = designUid, FileType = fileType, DesignRemoved = designRemoved
            };

            //if ((targetGrids & DesignNotificationGridMutability.NotifyImmutable) != 0)
            //  gridFactory.Grid(StorageMutability.Immutable).GetMessaging().SendOrdered(evt, MESSAGE_TOPIC_NAME, _messageSendTimeout);

            //if ((targetGrids & DesignNotificationGridMutability.NotifyMutable) != 0)
            //  gridFactory.Grid(StorageMutability.Mutable).GetMessaging().SendOrdered(evt, MESSAGE_TOPIC_NAME, _messageSendTimeout);

            if ((targetGrids & DesignNotificationGridMutability.NotifyImmutable) != 0)
            {
                evt.SourceNodeUid = gridFactory.Grid(StorageMutability.Immutable).GetCluster().GetLocalNode().Id;
                SendInvokeStyleMessage("Immutable", evt);
            }

            if ((targetGrids & DesignNotificationGridMutability.NotifyMutable) != 0)
            {
                evt.SourceNodeUid = gridFactory.Grid(StorageMutability.Mutable).GetCluster().GetLocalNode().Id;
                SendInvokeStyleMessage("Mutable", evt);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Performs the donkey work of the boundary calculation
        /// </summary>
        private List <Fence> Calc(DesignBoundaryArgument arg, out DesignProfilerRequestResult calcResult)
        {
            calcResult = DesignProfilerRequestResult.UnknownError;

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

            if (siteModel == null)
            {
                calcResult = DesignProfilerRequestResult.NoSelectedSiteModel;
                Log.LogError($"Site model {arg.ProjectID} not found");
                return(null);
            }

            var design = Designs.Lock(arg.ReferenceDesign.DesignID, siteModel, siteModel.CellSize, out var lockResult);

            if (design == null)
            {
                Log.LogWarning($"Failed to read file for design {arg.ReferenceDesign.DesignID}");
                calcResult = DesignProfilerRequestResult.FailedToLoadDesignFile;
                return(null);
            }

            try
            {
                var result = design.GetBoundary();

                calcResult = result != null ? DesignProfilerRequestResult.OK : DesignProfilerRequestResult.FailedToCalculateBoundary;

                return(result);
            }
            finally
            {
                Designs.UnLock(arg.ReferenceDesign.DesignID, design);
            }
        }
Esempio n. 4
0
        public void MapFilterResultHasMachineFilterToCombinedFilter_WithMachines()
        {
            var contributingMachines = new List <MachineDetails>()
            {
                new MachineDetails(Consts.NULL_LEGACY_ASSETID, "Big yella 1", false, Guid.NewGuid()), new MachineDetails(Consts.NULL_LEGACY_ASSETID, "Big yella 2", true, Guid.NewGuid())
            };
            var filter       = new Filter(contributingMachines: contributingMachines);
            var filterResult = new FilterResult(filter: filter);

            filterResult.Validate();

            var combinedFilter = AutoMapperUtility.Automapper.Map <CombinedFilter>(filterResult);

            combinedFilter.AttributeFilter.HasMachineFilter.Should().BeTrue();
            combinedFilter.AttributeFilter.MachinesList.Length.Should().Be(2);
            combinedFilter.AttributeFilter.MachinesList[0].Should().Be((Guid)(contributingMachines[0].AssetUid ?? null));
            combinedFilter.AttributeFilter.MachinesList[1].Should().Be((Guid)(contributingMachines[1].AssetUid ?? null));

            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);

            siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            siteModel.Machines.CreateNew("Test Machine 2", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            siteModel.Machines.CreateNew("Test Machine 3", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, contributingMachines[0].AssetUid.Value);

            combinedFilter.AttributeFilter.SiteModel = siteModel;
            var internalMachineIdBitArray = combinedFilter.AttributeFilter.GetMachineIDsSet();

            internalMachineIdBitArray.Should().NotBeNull();
            internalMachineIdBitArray.Count.Should().Be(3);
            internalMachineIdBitArray[0].Should().BeFalse();
            internalMachineIdBitArray[1].Should().BeFalse();
            internalMachineIdBitArray[2].Should().BeTrue();
        }
Esempio n. 5
0
        /// <summary>
        /// Primary method called to begin analytics computation
        /// </summary>
        public bool ComputeAnalytics(BaseAnalyticsResponse response)
        {
            using var processor = DIContext.Obtain <IPipelineProcessorFactory>().NewInstanceNoBuild <SubGridsRequestArgument>(
                      RequestDescriptor,
                      SiteModel.ID,
                      RequestedGridDataType,
                      response,
                      Filters,
                      CutFillDesign,
                      DIContext.Obtain <Func <PipelineProcessorTaskStyle, ITRexTask> >()(PipelineProcessorTaskStyle.AggregatedPipelined),
                      DIContext.Obtain <Func <PipelineProcessorPipelineStyle, ISubGridPipelineBase> >()(PipelineProcessorPipelineStyle.DefaultAggregative),
                      DIContext.Obtain <IRequestAnalyser>(),
                      IncludeSurveyedSurfaces,
                      CutFillDesign?.DesignID != Guid.Empty,
                      BoundingIntegerExtent2D.Inverted(),
                      LiftParams
                      );

            // Assign the provided aggregator into the pipelined sub grid task
            ((IAggregatedPipelinedSubGridTask)processor.Task).Aggregator = Aggregator;

            if (!processor.Build())
            {
                Log.LogError($"Failed to build pipeline processor for request to model {SiteModel.ID}");
                return(false);
            }

            processor.Process();

            return(response.ResultStatus == RequestErrorStatus.OK);
        }
Esempio n. 6
0
        public void Persist_UnSuccessful_NoAWS()
        {
            var projectUid = Guid.NewGuid();

            var csvExportUserPreference = new CSVExportUserPreferences();
            var requestArgument         = new CSVExportRequestArgument
                                          (
                projectUid, new FilterSet(new CombinedFilter()), "the filename",
                CoordType.Northeast, OutputTypes.PassCountLastPass,
                csvExportUserPreference, new List <CSVExportMappedMachine>(), false, false
                                          )
            {
                TRexNodeID = Guid.NewGuid()
            };

            var originalConfiguration = DIContext.Obtain <IConfigurationStore>();
            var moqConfiguration      = DIContext.Obtain <Mock <IConfigurationStore> >();

            moqConfiguration.Setup(c => c.GetValueString("AWS_TEMPORARY_BUCKET_NAME")).Returns((string)null);
            moqConfiguration.Setup(c => c.GetValueString("AWS_TEMPORARY_BUCKET_NAME", It.IsAny <string>())).Returns((string)null);

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

            Action act = () => new CSVExportFileWriter(requestArgument);

            act.Should().Throw <ServiceException>();

            DIBuilder
            .Continue()
            .Add(x => x.AddSingleton <IConfigurationStore>(originalConfiguration))
            .Complete();
        }
Esempio n. 7
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()))
            .Add(x => x.AddSingleton <ISurveyedSurfaceFactory>(new SurveyedSurfaceFactory()))
            .Build()
            .Add(x => x.AddSingleton <ISiteModels>(new SiteModels(() => DIContext.Obtain <IStorageProxyFactory>().ImmutableGridStorage())))
            .Add(x => x.AddSingleton <ISiteModelFactory>(new SiteModelFactory()))
            .Add(x => x.AddSingleton <IProfilerBuilderFactory>(new ProfilerBuilderFactory()))
            .Add(x => x.AddTransient <IProfilerBuilder>(factory => new ProfilerBuilder()))
            .Add(x => x.AddSingleton <IExistenceMaps>(new ExistenceMaps()))
            .Add(x => x.AddSingleton <IPipelineProcessorFactory>(new PipelineProcessorFactory()))
            .Add(x => x.AddSingleton <Func <PipelineProcessorPipelineStyle, ISubGridPipelineBase> >(provider => SubGridPipelineFactoryMethod))
            .Add(x => x.AddTransient <IRequestAnalyser>(factory => new RequestAnalyser()))
            .Add(x => x.AddSingleton <Func <PipelineProcessorTaskStyle, ITask> >(provider => SubGridTaskFactoryMethod))
            .Add(x => x.AddSingleton <IProductionEventsFactory>(new ProductionEventsFactory()))
            .Add(x => x.AddSingleton <IClientLeafSubGridFactory>(ClientLeafSubGridFactoryFactory.CreateClientSubGridFactory()))
            .Add(x => x.AddSingleton(new SubGridProcessingServer()))
            .Add(x => x.AddSingleton <IDesignsService>(new DesignsService(StorageMutability.Immutable)))
            .Complete();
        }
Esempio n. 8
0
        public async void TileExecutor_EmptySiteModel()
        {
            AddRoutings();

            var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();

            var request = new QMTileRequest
                          (
                siteModel.ID,
                new FilterResult(),
                1, 3, 3, 3, false
                          );

            request.Validate();

            var executor = RequestExecutorContainer
                           .Build <QuantizedMeshTileExecutor>(DIContext.Obtain <IConfigurationStore>(),
                                                              DIContext.Obtain <ILoggerFactory>(),
                                                              DIContext.Obtain <IServiceExceptionHandler>());

            var result = await executor.ProcessAsync(request) as QMTileResult;

            result.Should().NotBeNull();
            result.Code.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            result.TileData.Should().NotBeNull();
        }
Esempio n. 9
0
        private async void TestAFile(string fileName, DxfUnitsType units, int expectedBoundaryCount, int firstBoundaryVertexCount, string expectedName, DXFLineWorkBoundaryType expectedType, bool allowUnclosedBoundaries)
        {
            var request = new DXFBoundariesRequest("", ImportedFileType.SiteBoundary,
                                                   Convert.ToBase64String(File.ReadAllBytes(Path.Combine("TestData", fileName))),
                                                   units, 10, allowUnclosedBoundaries);
            var executor = new ExtractDXFBoundariesExecutor(DIContext.Obtain <IConfigurationStore>(), DIContext.Obtain <ILoggerFactory>(), DIContext.Obtain <IServiceExceptionHandler>());

            executor.Should().NotBeNull();

            var result = await executor.ProcessAsync(request);

            result.Should().NotBeNull();
            result.Code.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            result.Message.Should().Be("Success");

            if (result is DXFBoundaryResult boundary)
            {
                boundary.Boundaries.Count.Should().Be(expectedBoundaryCount);

                if (expectedBoundaryCount > 0)
                {
                    boundary.Boundaries[0].Fence.Count.Should().Be(firstBoundaryVertexCount);
                    boundary.Boundaries[0].Name.Should().Be(expectedName);
                    boundary.Boundaries[0].Type.Should().Be(expectedType);
                }
            }
            else
            {
                false.Should().BeTrue(); // fail the test
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Constructor for the renderer accepting all parameters necessary for its operation
        /// </summary>
        public RebuildSiteModelComputeFuncExecutor(RebuildSiteModelRequestArgument arg)
        {
            Response = new RebuildSiteModelRequestResponse(arg.ProjectID)
            {
                RebuildResult = RebuildSiteModelResult.OK
            };

            _rebuildSiteModelRequestArgument = arg;
            if (arg != null)
            {
                _siteModel = DIContext.Obtain <ISiteModels>().GetSiteModelRaw(arg.ProjectID);
            }

            if (_siteModel == null)
            {
                Response.RebuildResult = RebuildSiteModelResult.UnableToLocateSiteModel;
                return;
            }

            _siteModel.SetStorageRepresentationToSupply(StorageMutability.Mutable);

            // Rebuilding is only supported in the context of the mutable grid for coordination
            if (_siteModel.PrimaryStorageProxy.Mutability != StorageMutability.Mutable ||
                _siteModel.PrimaryStorageProxy.ImmutableProxy == null)
            {
                throw new TRexException("Rebulding is only supported in the context of the mutable grid for coordination");
            }
        }
Esempio n. 11
0
        public void GetAssetOnDesignLayerPeriods_TwoLayersOneDesign()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine Source", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            var design1   = siteModel.SiteModelMachineDesigns.CreateNew("DesignName1");

            var referenceDate      = DateTime.UtcNow;
            var startReportPeriod1 = referenceDate.AddMinutes(-60);
            var endReportPeriod1   = referenceDate.AddMinutes(-30);

            ushort layerId1 = 111;
            ushort layerId2 = 222;

            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].StartEndRecordedDataEvents.PutValueAtDate(startReportPeriod1, ProductionEventType.StartEvent);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].MachineDesignNameIDStateEvents.PutValueAtDate(startReportPeriod1, design1.Id);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].LayerIDStateEvents.PutValueAtDate(startReportPeriod1, layerId1);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].StartEndRecordedDataEvents.PutValueAtDate(endReportPeriod1, ProductionEventType.EndEvent);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].LayerIDStateEvents.PutValueAtDate(endReportPeriod1, layerId2);

            var assetOnDesignLayerPeriods = siteModel.GetAssetOnDesignLayerPeriods();

            assetOnDesignLayerPeriods.Count.Should().Be(1);
            assetOnDesignLayerPeriods[0].AssetId.Should().Be(Consts.NULL_LEGACY_ASSETID);
            assetOnDesignLayerPeriods[0].OnMachineDesignId.Should().Be(1);
            assetOnDesignLayerPeriods[0].OnMachineDesignName.Should().Be(design1.Name);
            assetOnDesignLayerPeriods[0].LayerId.Should().Be(layerId1);
            assetOnDesignLayerPeriods[0].StartDate.Should().Be(startReportPeriod1);
            assetOnDesignLayerPeriods[0].EndDate.Should().Be(endReportPeriod1);
            assetOnDesignLayerPeriods[0].AssetUid.Should().Be(machine.ID);
        }
Esempio n. 12
0
        public void HeartBeat()
        {
            try
            {
                if (!DIContext.Obtain <IConfigurationStore>().GetValueBool("HEARTBEAT_LOGGING_ENABLED_GenericSlabAllocatedPool", false))
                {
                    return;
                }

                foreach (var cache in GenericSlabAllocatedArrayPoolRegister.ArrayPoolCaches)
                {
                    var stats = cache.Statistics();

                    if (stats != null)
                    {
                        _sb.Clear();
                        _sb.Append(cache.TypeName());
                        _sb.Append("-SlabAllocatedArrayPool: Index/ArraySize/Capacity/Available/Rented: ");

                        foreach (var stat in stats)
                        {
                            _sb.Append($"{stat.PoolIndex}/{stat.ArraySize}/{stat.Capacity}/{stat.Capacity - stat.RentedItems}/{stat.RentedItems} | ");
                        }

                        Log.LogInformation("Heartbeat: " + _sb);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogError(e, "Exception occurred during heart beat log epoch");
            }
        }
Esempio n. 13
0
        public bool Invoke(Guid nodeId, ISiteModelAttributesChangedEvent message)
        {
            try
            {
                Log.LogInformation(
                    $"Received notification of site model attributes changed for {message.SiteModelID}: ExistenceMapModified={message.ExistenceMapModified}, DesignsModified={message.DesignsModified}, SurveyedSurfacesModified {message.SurveyedSurfacesModified} CsibModified={message.CsibModified}, MachinesModified={message.MachinesModified}, MachineTargetValuesModified={message.MachineTargetValuesModified}, AlignmentsModified {message.AlignmentsModified}, ExistenceMapChangeMask {message.ExistenceMapChangeMask != null}");

                // Tell the SiteModels instance to reload the designated site model that has changed
                var siteModels = DIContext.Obtain <ISiteModels>();
                if (siteModels != null)
                {
                    siteModels.SiteModelAttributesHaveChanged(message);
                }
                else
                {
                    Log.LogError("No ISiteModels instance available from DIContext to send attributes change message to");
                    return(true); // Stay subscribed
                }
            }
            catch (Exception e)
            {
                Log.LogError(e, "Exception occurred processing site model attributes changed event");
                return(true); // stay subscribed
            }
            finally
            {
                Log.LogInformation(
                    $"Completed handling notification of site model attributes changed for '{message.SiteModelID}': ExistenceMapModified={message.ExistenceMapModified}, DesignsModified={message.DesignsModified}, SurveyedSurfacesModified {message.SurveyedSurfacesModified} CsibModified={message.CsibModified}, MachinesModified={message.MachinesModified}, MachineTargetValuesModified={message.MachineTargetValuesModified}, AlignmentsModified {message.AlignmentsModified}, ExistenceMapChangeMask {message.ExistenceMapChangeMask != null}");
            }

            return(true);
        }
Esempio n. 14
0
        /// <summary>
        /// Add a new surveyed surface to a site model via direct manipulation of the information in the grid
        /// </summary>
        /// <param name="SiteModelID"></param>
        /// <param name="designDescriptor"></param>
        /// <param name="asAtDate"></param>
        /// <param name="extents"></param>
        /// <param name="SuveyedSurfaceID"></param>
        public void AddDirect(Guid SiteModelID, DesignDescriptor designDescriptor, DateTime asAtDate, BoundingWorldExtent3D extents, out Guid SurveyedSurfaceID)
        {
            // This should be done under a lock on the cache key. For now, we will live with the race condition...

            INonSpatialAffinityKey cacheKey = CacheKey(SiteModelID);

            SurveyedSurfaceID = Guid.NewGuid();

            // Get the surveyed surfaces, creating it if it does not exist
            ISurveyedSurfaces ssList = DIContext.Obtain <ISurveyedSurfaces>();

            try
            {
                ssList.FromBytes(mutableNonSpatialCache.Get(cacheKey));
            }
            catch (KeyNotFoundException)
            {
                // Swallow exception, the list will be empty
            }

            // Add the new surveyed surface, generating a random ID from a GUID
            ssList.AddSurveyedSurfaceDetails(SurveyedSurfaceID, designDescriptor, asAtDate, extents);

            // Put the list back into the cache with the new entry
            mutableNonSpatialCache.Put(cacheKey, ssList.ToBytes());
        }
Esempio n. 15
0
        /// <summary>
        /// Given a design used as an elevation range filter aspect, retrieve the existence map for the design and
        /// includes it in the supplied overall existence map for the query
        /// </summary>
        public static bool ProcessDesignElevationsForFilter(ISiteModel siteModel, //Guid siteModelID,
                                                            ICombinedFilter filter,
                                                            ISubGridTreeBitMask overallExistenceMap)
        {
            if (filter == null)
            {
                return(true);
            }

            if (overallExistenceMap == null)
            {
                return(false);
            }

            if (filter.AttributeFilter.HasElevationRangeFilter && filter.AttributeFilter.ElevationRangeDesign.DesignID != Guid.Empty)
            {
                var designExistenceMap = DIContext.Obtain <IExistenceMaps>().GetSingleExistenceMap
                                             (siteModel.ID, Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, filter.AttributeFilter.ElevationRangeDesign.DesignID);

                if (designExistenceMap != null)
                {
                    // Not sure this is really needed...
                    designExistenceMap.CellSize = SubGridTreeConsts.SubGridTreeDimension * siteModel.CellSize;
                    overallExistenceMap.SetOp_OR(designExistenceMap);
                }
            }

            return(true);
        }
Esempio n. 16
0
        public async void Boundaries_OverLimit(string fileName, DxfUnitsType units, int firstBoundaryVertexCount)
        {
            const int LIMIT = 5;

            var request = new DXFBoundariesRequest("", ImportedFileType.SiteBoundary,
                                                   Convert.ToBase64String(File.ReadAllBytes(Path.Combine("TestData", fileName))), units, LIMIT, false);
            var executor = new ExtractDXFBoundariesExecutor(DIContext.Obtain <IConfigurationStore>(), DIContext.Obtain <ILoggerFactory>(), DIContext.Obtain <IServiceExceptionHandler>());

            executor.Should().NotBeNull();

            var result = await executor.ProcessAsync(request);

            result.Should().NotBeNull();
            result.Code.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            result.Message.Should().Be("Success");

            if (result is DXFBoundaryResult boundary)
            {
                boundary.Boundaries.Count.Should().Be(LIMIT);
                boundary.Boundaries[0].Fence.Count.Should().Be(firstBoundaryVertexCount);
            }
            else
            {
                false.Should().BeTrue(); // fail the test
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Performs execution business logic for this executor
        /// </summary>
        public DesignProfilerRequestResult Execute(Guid projectUid, Guid designUid)
        {
            try
            {
                var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(projectUid, false);

                if (siteModel == null)
                {
                    _log.LogError($"Site model {projectUid} not found");
                    return(DesignProfilerRequestResult.NoSelectedSiteModel);
                }

                var removed = DIContext.Obtain <IAlignmentManager>().Remove(projectUid, designUid);

                if (removed)
                {
                    // Broadcast to listeners that design has changed
                    var sender = DIContext.Obtain <IDesignChangedEventSender>();
                    sender.DesignStateChanged(DesignNotificationGridMutability.NotifyImmutable, projectUid, designUid, ImportedFileType.Alignment, designRemoved: true);
                }
                else
                {
                    _log.LogError($"Failed to remove design {designUid} from project {projectUid} as it may not exist in the project");
                    return(DesignProfilerRequestResult.DesignDoesNotExist);
                }

                return(DesignProfilerRequestResult.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Execute: Exception: ");
                return(DesignProfilerRequestResult.UnknownError);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Performs execution business logic for this executor
        /// </summary>
        public IDesign Execute(Guid projectUid, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents, ISubGridTreeBitMask existenceMap)
        {
            try
            {
                var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(projectUid, false);

                if (siteModel == null)
                {
                    _log.LogError($"Site model {projectUid} not found");
                    return(null);
                }

                var design = DIContext.Obtain <IDesignManager>().Add(projectUid, designDescriptor, extents, existenceMap);

                if (design == null)
                {
                    _log.LogError($"Failed to add design file {designDescriptor} to project {projectUid}");
                }

                return(design);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Execute: Exception: ");
                return(null);
            }
        }
Esempio n. 19
0
        public void GetAssetOnDesignPeriods_OneMachineTwoDesignsDuplicateEvents()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine Source", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            var design1   = siteModel.SiteModelMachineDesigns.CreateNew("DesignName1");
            var design2   = siteModel.SiteModelMachineDesigns.CreateNew("DesignName2");

            var referenceDate = DateTime.UtcNow;
            var eventDate1    = referenceDate.AddMinutes(-60);
            var eventDate2    = referenceDate.AddMinutes(-30);
            var eventDate3    = referenceDate.AddMinutes(-15);

            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].MachineDesignNameIDStateEvents.PutValueAtDate(eventDate1, design1.Id);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].MachineDesignNameIDStateEvents.PutValueAtDate(eventDate2, design2.Id);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].MachineDesignNameIDStateEvents.PutValueAtDate(eventDate3, design2.Id);
            siteModel.MachinesTargetValues[machine.InternalSiteModelMachineIndex].MachineDesignNameIDStateEvents.Count().Should().Be(3);

            var assetOnDesignPeriods = siteModel.GetAssetOnDesignPeriods();

            assetOnDesignPeriods.Count.Should().Be(2);
            assetOnDesignPeriods[0].OnMachineDesignId.Should().Be(1);
            assetOnDesignPeriods[0].OnMachineDesignName.Should().Be(design1.Name);
            assetOnDesignPeriods[0].MachineId.Should().Be(Consts.NULL_LEGACY_ASSETID);
            assetOnDesignPeriods[0].AssetUid.Should().Be(machine.ID);
            assetOnDesignPeriods[0].StartDate.Should().Be(eventDate1);
            assetOnDesignPeriods[0].EndDate.Should().Be(Consts.MAX_DATETIME_AS_UTC);

            assetOnDesignPeriods[1].OnMachineDesignId.Should().Be(2);
            assetOnDesignPeriods[1].OnMachineDesignName.Should().Be(design2.Name);
            assetOnDesignPeriods[1].MachineId.Should().Be(Consts.NULL_LEGACY_ASSETID);
            assetOnDesignPeriods[1].AssetUid.Should().Be(machine.ID);
            assetOnDesignPeriods[1].StartDate.Should().Be(eventDate2);
            assetOnDesignPeriods[1].EndDate.Should().Be(Consts.MAX_DATETIME_AS_UTC);
        }
Esempio n. 20
0
        public void Test_ElevationSubGridRequests_RequestElevationSubGrids_NoSurveyedSurfaces_NoFilter()
        {
            var siteModel = Utilities.ConstructModelForTestsWithTwoExcavatorMachineTAGFiles(out var processedTasks);

            // Construct the set of requestors to query elevation sub grids needed for the summary volume calculations.
            var utilities  = DIContext.Obtain <IRequestorUtilities>();
            var Requestors = utilities.ConstructRequestors(null, siteModel, new OverrideParameters(), new LiftParameters(),
                                                           utilities.ConstructRequestorIntermediaries(siteModel, new FilterSet(new CombinedFilter()), true, GridDataType.Height),
                                                           AreaControlSet.CreateAreaControlSet(), siteModel.ExistenceMap);

            Requestors.Should().NotBeNull();
            Requestors.Length.Should().Be(1);

            // Request all elevation sub grids from the model
            var requestedSubGrids = new List <IClientLeafSubGrid>();

            siteModel.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(x =>
            {
                var requestSubGridInternalResult = Requestors[0].RequestSubGridInternal(x, true, false);
                if (requestSubGridInternalResult.requestResult == ServerRequestResult.NoError)
                {
                    requestedSubGrids.Add(requestSubGridInternalResult.clientGrid);
                }
            });

            requestedSubGrids.Count.Should().Be(4);

            (requestedSubGrids[0] as IClientHeightLeafSubGrid).Cells[0, 0].Should().Be(Consts.NullHeight);

            requestedSubGrids.Cast <IClientHeightLeafSubGrid>().Sum(x => x.CountNonNullCells()).Should().Be(427);
        }
Esempio n. 21
0
        public void NewInstance()
        {
            var factory = new PipelineProcessorFactory();

            var processor = factory.NewInstance <SubGridsRequestArgument>(
                Guid.NewGuid(),
                Guid.NewGuid(),
                GridDataType.Height,
                new PatchRequestResponse(),
                new FilterSet(new CombinedFilter()),
                new DesignOffset(),
                DIContext.Obtain <Func <PipelineProcessorTaskStyle, ITRexTask> >()(PipelineProcessorTaskStyle.PatchExport),
                DIContext.Obtain <Func <PipelineProcessorPipelineStyle, ISubGridPipelineBase> >()(PipelineProcessorPipelineStyle.DefaultProgressive),
                DIContext.Obtain <IRequestAnalyser>(),
                false,
                false,
                BoundingIntegerExtent2D.Inverted(),
                new LiftParameters());

            processor.Should().BeNull("because there is no site model");

            // Configure the request analyser to return a single page of results.
//      processor.RequestAnalyser.SinglePageRequestNumber = 1;
//      processor.RequestAnalyser.SinglePageRequestSize = 10;
//      processor.RequestAnalyser.SubmitSinglePageOfRequests = true;

            // processor.Build().Should().BeFalse("because there is no sitemodel");
        }
Esempio n. 22
0
        /// <summary>
        /// Archives successfully processed tag files to S3
        /// </summary>
        /// <param name="tagDetail"></param>
        /// <returns></returns>
        public static async Task <bool> ArchiveTagfileS3(TagFileDetail tagDetail)
        {
            // CCSSCON-702 Archive any unknown asset (JohnDoe) to an empty guid machine folder.
            if (tagDetail.assetId == null)
            {
                tagDetail.assetId = Guid.Empty;
            }

            if (tagDetail.projectId == null || tagDetail.tagFileName == string.Empty || tagDetail.tagFileContent == null)
            {
                _log.LogError($"ArchiveTagfileS3. Bad request missing value {tagDetail.tagFileName}. Asset{tagDetail.assetId}, Project:{tagDetail.projectId}");
                return(false);
            }

            try
            {
                var s3FullPath = $"{tagDetail.projectId}{S3DirectorySeparator}{tagDetail.assetId}{S3DirectorySeparator}{tagDetail.tagFileName}";
                var proxy      = DIContext.Obtain <ITransferProxyFactory>().NewProxy(TransferProxyType.TAGFiles);
                using var stream = new MemoryStream(tagDetail.tagFileContent);
                if (!proxy.FileExists(s3FullPath).Result) // write once policy
                {
                    return(await proxy.UploadAndLock(stream, s3FullPath));
                }

                return(true); // already exists
            }

            catch (System.Exception ex)
            {
                _log.LogError(ex, $"Exception occured archiving tagfilesaving {tagDetail.tagFileName}. Asset{tagDetail.assetId}, error:{ex.Message}");
                return(false);
            }
        }
Esempio n. 23
0
        private DesignListResult GetDesignsForSiteModel(Guid projectUid, ImportedFileType fileType)
        {
            List <DesignFileDescriptor> designFileDescriptorList;

            if (fileType == ImportedFileType.DesignSurface)
            {
                var designList = DIContext.Obtain <IDesignManager>().List(projectUid);
                designFileDescriptorList = designList.Select(designSurface =>
                                                             AutoMapperUtility.Automapper.Map <DesignFileDescriptor>(designSurface))
                                           .ToList();
                return(new DesignListResult {
                    DesignFileDescriptors = designFileDescriptorList
                });
            }

            if (fileType == ImportedFileType.SurveyedSurface)
            {
                var designSurfaceList = DIContext.Obtain <ISurveyedSurfaceManager>().List(projectUid);
                designFileDescriptorList = designSurfaceList.Select(designSurface =>
                                                                    AutoMapperUtility.Automapper.Map <DesignFileDescriptor>(designSurface))
                                           .ToList();
                return(new DesignListResult {
                    DesignFileDescriptors = designFileDescriptorList
                });
            }

            var designAlignmentList = DIContext.Obtain <IAlignmentManager>().List(projectUid);

            designFileDescriptorList = designAlignmentList.Select(designAlignment =>
                                                                  AutoMapperUtility.Automapper.Map <DesignFileDescriptor>(designAlignment))
                                       .ToList();
            return(new DesignListResult {
                DesignFileDescriptors = designFileDescriptorList
            });
        }
Esempio n. 24
0
        public void SiteModelStatisticsExecutor_EmptySiteModel()
        {
            var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();

            var request = new ProjectStatisticsTRexRequest(siteModel.ID, null);

            request.Validate();

            var executor = RequestExecutorContainer
                           .Build <SiteModelStatisticsExecutor>(DIContext.Obtain <IConfigurationStore>(),
                                                                DIContext.Obtain <ILoggerFactory>(),
                                                                DIContext.Obtain <IServiceExceptionHandler>());
            var result = executor.Process(request) as ProjectStatisticsResult;

            result.Code.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            result.cellSize.Should().Be(SubGridTreeConsts.DefaultCellSize);
            result.startTime.Should().Be(Consts.MAX_DATETIME_AS_UTC);
            result.endTime.Should().Be(Consts.MIN_DATETIME_AS_UTC);
            result.extents.MinX.Should().Be(BoundingWorldExtent3D.Inverted().MinX);
            result.extents.MaxX.Should().Be(BoundingWorldExtent3D.Inverted().MaxX);
            result.extents.MinY.Should().Be(BoundingWorldExtent3D.Inverted().MinY);
            result.extents.MaxY.Should().Be(BoundingWorldExtent3D.Inverted().MaxY);
            result.extents.MinZ.Should().Be(BoundingWorldExtent3D.Inverted().MinZ);
            result.extents.MaxZ.Should().Be(BoundingWorldExtent3D.Inverted().MaxZ);
            result.indexOriginOffset.Should().Be((int)SubGridTreeConsts.DefaultIndexOriginOffset);

            var expectedJson = "{\"startTime\":\"9999-12-31T23:59:59.9999999\",\"endTime\":\"0001-01-01T00:00:00\",\"cellSize\":0.34,\"indexOriginOffset\":536870912,\"extents\":{\"maxX\":-1E+100,\"maxY\":-1E+100,\"maxZ\":-1E+100,\"minX\":1E+100,\"minY\":1E+100,\"minZ\":1E+100},\"Code\":0,\"Message\":\"success\"}";
            var json         = JsonConvert.SerializeObject(result);

            json.Should().Be(expectedJson);
        }
Esempio n. 25
0
        /// <summary>
        /// Process rebuild project request
        /// </summary>
        protected override ContractExecutionResult ProcessEx <T>(T item)
        {
            var request = CastRequestObjectTo <ProjectRebuildRequest>(item);

            try
            {
                log.LogInformation($"#In#: ProjectRebuildExecutor. Project:{request.ProjectUid}, Archive Tag Files: {request.ArchiveTagFiles}, Data Origin:{request.DataOrigin}");

                var rebuildResult = DIContext.Obtain <ISiteModelRebuilderManager>().Rebuild(request.ProjectUid, request.ArchiveTagFiles, request.DataOrigin);

                if (!rebuildResult)
                {
                    log.LogError($"#Out# ProjectRebuildExecutor. Rebuild request failed for Project:{request.ProjectUid}, Archive Tag Files: {request.ArchiveTagFiles}, Data Origin:{request.DataOrigin}");
                    throw CreateServiceException <ProjectRebuildExecutor>
                              (HttpStatusCode.InternalServerError, ContractExecutionStatesEnum.InternalProcessingError,
                              RequestErrorStatus.Unknown); // Todo: May want to enrich the return over a simple bool...
                }

                log.LogInformation($"#Out# ProjectRebuildExecutor. Rebuild request for Project:{request.ProjectUid}, Archive Tag Files: {request.ArchiveTagFiles}, Data Origin:{request.DataOrigin}");
            }
            catch (Exception e)
            {
                log.LogError(e, $"#Out# ProjectRebuildExecutor. Rebuild request failed for Project:{request.ProjectUid}, Archive Tag Files: {request.ArchiveTagFiles}, Data Origin:{request.DataOrigin}");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, (int)RequestErrorStatus.Unknown, e.Message); // Todo: Enrich return enum from rebuild request
                throw CreateServiceException <ProjectRebuildExecutor>
                          (HttpStatusCode.InternalServerError, ContractExecutionStatesEnum.InternalProcessingError,
                          RequestErrorStatus.Unknown, e.Message);
            }

            return(new ContractExecutionResult());
        }
Esempio n. 26
0
        private void SetupDIDeviceGateay(bool enableDeviceGateway = true)
        {
            var moqCustomHeaders = new HeaderDictionary()
            {
            };

            var moqTPaaSApplicationAuthentication = new Mock <ITPaaSApplicationAuthentication>();
            var moqCwsDeviceGateway = new Mock <ICwsDeviceGatewayClient>();

            moqTPaaSApplicationAuthentication.Setup(mk => mk.CustomHeaders()).Returns(moqCustomHeaders);
            moqCwsDeviceGateway.Setup(mk => mk.CreateDeviceLKS(It.IsAny <string>(), It.IsAny <DeviceLKSModel>(), It.IsAny <HeaderDictionary>()));

            //Moq doesn't support extension methods in IConfiguration/Root.
            var moqConfiguration = DIContext.Obtain <Mock <IConfigurationStore> >();

            moqConfiguration.Setup(x => x.GetValueBool("ENABLE_DEVICE_GATEWAY", It.IsAny <bool>())).Returns(enableDeviceGateway);
            moqConfiguration.Setup(x => x.GetValueBool("ENABLE_DEVICE_GATEWAY")).Returns(enableDeviceGateway);

            DIBuilder
            .Continue()
            .Add(x => x.AddSingleton <ITPaaSApplicationAuthentication>(moqTPaaSApplicationAuthentication.Object))
            .Add(x => x.AddSingleton <ICwsDeviceGatewayClient>(moqCwsDeviceGateway.Object))
            .Add(x => x.AddSingleton <IConfigurationStore>(moqConfiguration.Object))
            .Build();
        }
Esempio n. 27
0
        private IProductionEvents Deserialize(MemoryStream stream)
        {
            IProductionEvents events = null;

            using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                if (stream.Length < 16)
                {
                    return(events);
                }

                stream.Position = 1; // Skip the version to get the event list type

                var eventType = reader.ReadInt32();
                if (!Enum.IsDefined(typeof(ProductionEventType), eventType))
                {
                    return(events);
                }

                events = DIContext.Obtain <IProductionEventsFactory>().NewEventList(-1, Guid.Empty, (ProductionEventType)eventType);

                stream.Position = 0;
                events.ReadEvents(reader);
            }

            return(events);
        }
Esempio n. 28
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()))
            .Add(x => x.AddSingleton <ISurveyedSurfaceFactory>(new SurveyedSurfaceFactory()))
            .Build()

            // The renderer factory that allows tile rendering services access Bitmap etc platform dependent constructs
            .Add(x => x.AddSingleton <IRenderingFactory>(new RenderingFactory()))

            .Add(x => x.AddSingleton <ISiteModels>(new SiteModels(() => DIContext.Obtain <IStorageProxyFactory>().ImmutableGridStorage())))
            .Add(x => x.AddSingleton <ISiteModelFactory>(new SiteModelFactory()))
            .Add(x => x.AddSingleton <ICoordinateConversion>(new CoordinateConversion()))
            .Add(x => x.AddSingleton <IExistenceMaps>(new VSS.TRex.ExistenceMaps.ExistenceMaps()))
            .Add(x => x.AddSingleton <IPipelineProcessorFactory>(new PipelineProcessorFactory()))
            .Add(x => x.AddSingleton <Func <PipelineProcessorPipelineStyle, ISubGridPipelineBase> >(provider => SubGridPipelineFactoryMethod))
            .Add(x => x.AddTransient <IRequestAnalyser>(factory => new RequestAnalyser()))
            .Add(x => x.AddSingleton <Func <PipelineProcessorTaskStyle, ITask> >(provider => SubGridTaskFactoryMethod))
            .Add(x => x.AddSingleton <IClientLeafSubGridFactory>(ClientLeafSubGridFactoryFactory.CreateClientSubGridFactory()))

            .Add(x => x.AddSingleton(new ApplicationServiceServer(new[] {
                ApplicationServiceServer.DEFAULT_ROLE,
                ServerRoles.ASNODE_PROFILER,
                ServerRoles.PATCH_REQUEST_ROLE,
                ServerRoles.TILE_RENDERING_NODE,
                ServerRoles.ANALYTICS_NODE
            })))

            .Complete();
        }
Esempio n. 29
0
        /// <summary>
        /// Performs execution business logic for this executor
        /// </summary>
        public IAlignment Execute(Guid projectUid, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents)
        {
            try
            {
                var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(projectUid, false);

                if (siteModel == null)
                {
                    _log.LogError($"Site model {projectUid} not found");
                    return(null);
                }

                var alignment = DIContext.Obtain <IAlignmentManager>().Add(projectUid, designDescriptor, extents);

                if (alignment == null)
                {
                    _log.LogError($"Failed to add design file {designDescriptor} to project {projectUid}");
                }

                return(alignment);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Execute: Exception: ");
                return(null);
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Performs execution business logic for this executor
        /// </summary>
        public ISurveyedSurface Execute(Guid projectUid, DesignDescriptor designDescriptor, DateTime asAtDate, BoundingWorldExtent3D extents, ISubGridTreeBitMask existenceMap)
        {
            try
            {
                var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(projectUid, false);

                if (siteModel == null)
                {
                    _log.LogError($"Site model {projectUid} not found");
                    return(null);
                }

                var surveyedSurface = DIContext.Obtain <ISurveyedSurfaceManager>().Add(projectUid, designDescriptor, asAtDate, extents, existenceMap);

                if (surveyedSurface == null)
                {
                    _log.LogError($"Failed to add surveyed surface file {designDescriptor}, asAtDate {asAtDate} to project {projectUid}");
                }

                return(surveyedSurface);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Execute: Exception: ");
                return(null);
            }
        }