/// <summary> /// Remove the design list for a site model from the persistent store /// </summary> public bool Remove(Guid siteModelId, IStorageProxy storageProxy) { // First remove all the existence maps associated with the designs var designs = Load(siteModelId); designs.ForEach(x => { FileSystemErrorStatus result; var filename = BaseExistenceMapRequest.CacheKeyString(ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, x.ID); if ((result = storageProxy.RemoveStreamFromPersistentStore(siteModelId, FileSystemStreamType.DesignTopologyExistenceMap, filename)) != FileSystemErrorStatus.OK) { _log.LogWarning($"Unable to remove existence map for design {x.ID}, filename = {filename}, with result: {result}"); } }); // Then remove the designs list stream itself var result = storageProxy.RemoveStreamFromPersistentStore(siteModelId, FileSystemStreamType.Designs, DESIGNS_STREAM_NAME); if (result != FileSystemErrorStatus.OK) { _log.LogInformation($"Removing designs list from project {siteModelId} failed with error {result}"); } return(result == FileSystemErrorStatus.OK); }
/// <summary> /// Add a new design to a site model /// </summary> public IDesign Add(Guid siteModelId, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents, ISubGridTreeBitMask existenceMap) { if (extents == null) { throw new ArgumentNullException(nameof(extents)); } if (existenceMap == null) { throw new ArgumentNullException(nameof(existenceMap)); } // Add the design to the designs list var designs = Load(siteModelId); var result = designs.AddDesignDetails(designDescriptor.DesignID, designDescriptor, extents); // Store the existence map into the cache using var stream = existenceMap.ToStream(); var fileName = BaseExistenceMapRequest.CacheKeyString(ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, designDescriptor.DesignID); if (_writeStorageProxy.WriteStreamToPersistentStore(siteModelId, fileName, FileSystemStreamType.DesignTopologyExistenceMap, stream, existenceMap) != FileSystemErrorStatus.OK) { _log.LogError("Failed to write existence map to persistent store for key {fileName}"); return(null); } // Store performs Commit() operation Store(siteModelId, designs); return(result); }
private void Test_GetCombinedExistenceMap_ViaDescriptor(SubGridTreeSubGridExistenceBitMask setBitMask1, SubGridTreeSubGridExistenceBitMask setBitMask2) { var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel(); var DesignUid1 = Guid.NewGuid(); var DesignUid2 = Guid.NewGuid(); var em = new TRex.ExistenceMaps.ExistenceMaps(); siteModel.PrimaryStorageProxy.WriteStreamToPersistentStore (siteModel.ID, BaseExistenceMapRequest.CacheKeyString(Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, DesignUid1), FileSystemStreamType.DesignTopologyExistenceMap, setBitMask1.ToStream(), setBitMask1.ToStream()) .Should().Be(FileSystemErrorStatus.OK); siteModel.PrimaryStorageProxy.WriteStreamToPersistentStore (siteModel.ID, BaseExistenceMapRequest.CacheKeyString(Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, DesignUid2), FileSystemStreamType.DesignTopologyExistenceMap, setBitMask2.ToStream(), setBitMask2.ToStream()) .Should().Be(FileSystemErrorStatus.OK); var getBitMask = em.GetCombinedExistenceMap(siteModel.ID, new Tuple <long, Guid>[] { new Tuple <long, Guid> (Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, DesignUid1), new Tuple <long, Guid> (Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, DesignUid2) }); setBitMask1.SetOp_OR(setBitMask2); TestBitMasksAreTheSame(setBitMask1, getBitMask); }
public void GetExistenceMap() { var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel(); var DesignUid = Guid.NewGuid(); var filename = BaseExistenceMapRequest.CacheKeyString(TRex.ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, DesignUid); var setMap = new SubGridTreeSubGridExistenceBitMask(); siteModel.PrimaryStorageProxy.WriteStreamToPersistentStore (siteModel.ID, filename, FileSystemStreamType.DesignTopologyExistenceMap, setMap.ToStream(), null) .Should().Be(FileSystemErrorStatus.OK); var server = new ExistenceMapServer(); var getMap = server.GetExistenceMap(new NonSpatialAffinityKey(siteModel.ID, filename)); setMap.ToBytes().SequenceEqual(getMap.ToBytes()).Should().BeTrue(); }
public void GetSingleExistenceMapViaDescriptor_EmptyBitMask() { var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel(); var DesignUid = Guid.NewGuid(); var setBitMask = new SubGridTreeSubGridExistenceBitMask(); siteModel.PrimaryStorageProxy.WriteStreamToPersistentStore (siteModel.ID, BaseExistenceMapRequest.CacheKeyString(Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, DesignUid), FileSystemStreamType.DesignTopologyExistenceMap, (new SubGridTreeSubGridExistenceBitMask()).ToStream(), null) .Should().Be(FileSystemErrorStatus.OK); var em = new TRex.ExistenceMaps.ExistenceMaps(); var getBitMask = em.GetSingleExistenceMap(siteModel.ID, Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, DesignUid); TestBitMasksAreTheSame(setBitMask, getBitMask); }
/// <summary> /// Remove the surveyed surface list for a site model from the persistent store /// </summary> public bool Remove(Guid siteModelUid, IStorageProxy storageProxy) { // First remove all the existence maps associated with the surveyed surfaces foreach (var surveyedSurface in Load(siteModelUid)) { FileSystemErrorStatus fsResult; var filename = BaseExistenceMapRequest.CacheKeyString(ExistenceMaps.Interfaces.Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, surveyedSurface.ID); if ((fsResult = storageProxy.RemoveStreamFromPersistentStore(siteModelUid, FileSystemStreamType.DesignTopologyExistenceMap, filename)) != FileSystemErrorStatus.OK) { _log.LogWarning($"Unable to remove existence map for surveyed surface {surveyedSurface.ID}, filename = {filename}, in project {siteModelUid} with result: {fsResult}"); } } // Then remove the surveyed surface list stream itself var result = storageProxy.RemoveStreamFromPersistentStore(siteModelUid, FileSystemStreamType.Designs, SURVEYED_SURFACE_STREAM_NAME); if (result != FileSystemErrorStatus.OK) { _log.LogInformation($"Removing surveyed surfaces list from project {siteModelUid} failed with error {result}"); } return(result == FileSystemErrorStatus.OK); }
/// <summary> /// Add a new surveyed surface to a site model /// </summary> public ISurveyedSurface Add(Guid siteModelUid, DesignDescriptor designDescriptor, DateTime asAtDate, BoundingWorldExtent3D extents, ISubGridTreeBitMask existenceMap) { if (asAtDate.Kind != DateTimeKind.Utc) { throw new ArgumentException("AsAtDate must be a UTC date time"); } if (extents == null) { throw new ArgumentNullException(nameof(extents)); } if (existenceMap == null) { throw new ArgumentNullException(nameof(existenceMap)); } var ss = Load(siteModelUid); var newSurveyedSurface = ss.AddSurveyedSurfaceDetails(designDescriptor.DesignID, designDescriptor, asAtDate, extents); // Store the existence map into the cache using var stream = existenceMap.ToStream(); var fileName = BaseExistenceMapRequest.CacheKeyString(ExistenceMaps.Interfaces.Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, designDescriptor.DesignID); if (_writeStorageProxy.WriteStreamToPersistentStore(siteModelUid, fileName, FileSystemStreamType.DesignTopologyExistenceMap, stream, existenceMap) != FileSystemErrorStatus.OK) { _log.LogError("Failed to write existence map to persistent store for key {fileName}"); return(null); } // Store performs Commit() operation Store(siteModelUid, ss); return(newSurveyedSurface); }
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 request = new AddSurveyedSurfaceRequest(); var addResponse = await request.ExecuteAsync(new AddSurveyedSurfaceArgument { ProjectID = siteModel.ID, DesignDescriptor = new DesignDescriptor(designID, "folder", "filename"), AsAtDate = DateTime.UtcNow, Extents = new TRex.Geometry.BoundingWorldExtent3D(0, 0, 1, 1), ExistenceMap = existenceMap }); addResponse.Should().NotBeNull(); addResponse.RequestResult.Should().Be(DesignProfilerRequestResult.OK); // Re-request the sitemodel to reflect the change siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(siteModel.ID, false); siteModel.SurveyedSurfaces.Count.Should().Be(1); var removeRequest = new RemoveSurveyedSurfaceRequest(); var removeResponse = await removeRequest.ExecuteAsync(new RemoveSurveyedSurfaceArgument { 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.SurveyedSurfaces.Count.Should().Be(0); var readExistenceMap = DIContext.Obtain <IExistenceMapServer>().GetExistenceMap(new NonSpatialAffinityKey(siteModel.ID, BaseExistenceMapRequest.CacheKeyString(TRex.ExistenceMaps.Interfaces.Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, designID))); readExistenceMap.Should().BeNull(); }
public async void Add() { AddApplicationRouting(); var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel(); siteModel.SetStorageRepresentationToSupply(TRex.Storage.Models.StorageMutability.Mutable); siteModel.Designs.Count.Should().Be(0); siteModel.SetStorageRepresentationToSupply(TRex.Storage.Models.StorageMutability.Immutable); siteModel.Designs.Count.Should().Be(0); var designID = System.Guid.NewGuid(); var existenceMap = new TRex.SubGridTrees.SubGridTreeSubGridExistenceBitMask(); existenceMap[0, 0] = true; var request = new AddTTMDesignRequest(); var response = await request.ExecuteAsync(new AddTTMDesignArgument { ProjectID = siteModel.ID, DesignDescriptor = new DesignDescriptor(designID, "folder", "filename"), Extents = new TRex.Geometry.BoundingWorldExtent3D(0, 0, 1, 1), ExistenceMap = existenceMap }); response.Should().NotBeNull(); response.DesignUid.Should().Be(designID); response.RequestResult.Should().Be(DesignProfilerRequestResult.OK); // Re-request the sitemodel to reflect the change siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(siteModel.ID, false); siteModel.SetStorageRepresentationToSupply(TRex.Storage.Models.StorageMutability.Mutable); siteModel.Designs.Count.Should().Be(1); siteModel.Designs[0].DesignDescriptor.Should().BeEquivalentTo(new TRex.Designs.Models.DesignDescriptor(designID, "folder", "filename")); siteModel.SetStorageRepresentationToSupply(TRex.Storage.Models.StorageMutability.Immutable); siteModel.Designs.Count.Should().Be(1); siteModel.Designs[0].DesignDescriptor.Should().BeEquivalentTo(new TRex.Designs.Models.DesignDescriptor(designID, "folder", "filename")); var readExistenceMap = DIContext.Obtain <IExistenceMapServer>().GetExistenceMap(new NonSpatialAffinityKey(siteModel.ID, BaseExistenceMapRequest.CacheKeyString(TRex.ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, designID))); readExistenceMap.Should().NotBeNull(); existenceMap.CountBits().Should().Be(readExistenceMap.CountBits()); readExistenceMap[0, 0].Should().BeTrue(); }
/// <summary> /// Remove a given design from a site model /// </summary> public bool Remove(Guid siteModelId, Guid designId) { var designs = Load(siteModelId); var result = designs.RemoveDesign(designId); if (result) { var removeMapResult = _writeStorageProxy.RemoveStreamFromPersistentStore(siteModelId, FileSystemStreamType.DesignTopologyExistenceMap, BaseExistenceMapRequest.CacheKeyString(ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, designId)); if (removeMapResult != FileSystemErrorStatus.OK) { _log.LogInformation($"Removing existence map for design {designId} in project {siteModelId} failed with error {removeMapResult}"); } Store(siteModelId, designs); } return(result); }
/// <summary> /// Remove a given surveyed surface from a site model /// </summary> public bool Remove(Guid siteModelUid, Guid surveySurfaceUid) { var ss = Load(siteModelUid); var result = ss.RemoveSurveyedSurface(surveySurfaceUid); if (result) { var removeMapResult = _writeStorageProxy.RemoveStreamFromPersistentStore(siteModelUid, FileSystemStreamType.DesignTopologyExistenceMap, BaseExistenceMapRequest.CacheKeyString(ExistenceMaps.Interfaces.Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, surveySurfaceUid)); if (removeMapResult != FileSystemErrorStatus.OK) { _log.LogInformation($"Removing surveyed surface existence map for surveyed surface {surveySurfaceUid} project {siteModelUid} failed with error {removeMapResult}"); } Store(siteModelUid, ss); } return(result); }