public void FileDeleteFromStorage_HappyPath() { var mockTransferProxy = new Mock <ITransferProxy>(); mockTransferProxy.Setup(t => t.RemoveFromBucket(It.IsAny <string>())).Returns(true); var mockTransferProxyFactory = new Mock <ITransferProxyFactory>(); mockTransferProxyFactory.Setup(x => x.NewProxy(It.IsAny <TransferProxyType>())).Returns(mockTransferProxy.Object); var mockConfig = new Mock <IConfigurationStore>(); mockConfig.Setup(x => x.GetValueString("AWS_DESIGNIMPORT_BUCKET_NAME")).Returns("vss-projects-stg"); DIBuilder .New() .AddLogging() .Add(x => x.AddSingleton(mockConfig.Object)) .Add(x => x.AddSingleton(mockTransferProxyFactory.Object)) .Complete(); var projectUid = Guid.Parse("A11F2458-6666-424F-A995-4426a00771AE"); var transferFileName = "TransferTestDesign.ttm"; var s3FileTransfer = new S3FileTransfer(TransferProxyType.DesignImport); var isDeletedFromS3Ok = s3FileTransfer.RemoveFileFromBucket(projectUid, transferFileName); Assert.True(isDeletedFromS3Ok); }
public override bool RemoveFromStorage(Guid siteModelUid, string fileName) { try { var s3FileTransfer = new S3FileTransfer(TransferProxyType.DesignImport); if (s3FileTransfer.RemoveFileFromBucket(siteModelUid, fileName)) { s3FileTransfer.RemoveFileFromBucket(siteModelUid, fileName + Consts.DESIGN_SUB_GRID_INDEX_FILE_EXTENSION); s3FileTransfer.RemoveFileFromBucket(siteModelUid, fileName + Consts.DESIGN_SPATIAL_INDEX_FILE_EXTENSION); s3FileTransfer.RemoveFileFromBucket(siteModelUid, fileName + Consts.DESIGN_BOUNDARY_FILE_EXTENSION); } } catch (Exception e) { Log.LogError(e, $"Exception RemoveFromStorage. file:{fileName}"); return(false); } return(true); }
public override bool RemoveFromStorage(Guid siteModelUid, string fileName) { var s3FileTransfer = new S3FileTransfer(TransferProxyType.DesignImport); return(s3FileTransfer.RemoveFileFromBucket(siteModelUid, fileName)); }
/// <summary> /// Delete a design or surveyed surface or alignment file from TRex /// </summary> protected async Task RemoveDesign(DesignRequest request, string executorName) { bool removedOk = false; if (request.FileType == ImportedFileType.DesignSurface) { // Remove the designSurface var tRexRequest = new RemoveTTMDesignRequest(); var removeResponse = await tRexRequest.ExecuteAsync(new RemoveTTMDesignArgument { ProjectID = request.ProjectUid, DesignID = request.DesignUid }); removedOk = removeResponse.RequestResult == DesignProfilerRequestResult.OK; } if (request.FileType == ImportedFileType.SurveyedSurface) { // Remove the new surveyedSurface var tRexRequest = new RemoveSurveyedSurfaceRequest(); var removeResponse = await tRexRequest.ExecuteAsync(new RemoveSurveyedSurfaceArgument { ProjectID = request.ProjectUid, DesignID = request.DesignUid }); removedOk = removeResponse.RequestResult == DesignProfilerRequestResult.OK; } if (request.FileType == ImportedFileType.Alignment) { // Remove the alignment var tRexRequest = new RemoveAlignmentRequest(); var removeResponse = await tRexRequest.ExecuteAsync(new RemoveAlignmentArgument { ProjectID = request.ProjectUid, AlignmentID = request.DesignUid }); removedOk = removeResponse.RequestResult == DesignProfilerRequestResult.OK; } if (!removedOk) { log.LogError($"#Out# {executorName}. Deletion failed, of design:{request.FileName}, Project:{request.ProjectUid}, DesignUid:{request.DesignUid}"); throw CreateServiceException <TExecutor> (HttpStatusCode.InternalServerError, ContractExecutionStatesEnum.InternalProcessingError, RequestErrorStatus.DesignImportUnableToDeleteDesign); } //Remove local copies of files var localPath = FilePathHelper.GetTempFolderForProject(request.ProjectUid); var localPathAndFileName = Path.Combine(new[] { localPath, request.FileName }); if (File.Exists(localPathAndFileName)) { try { File.Delete(localPathAndFileName); if (request.FileType != ImportedFileType.Alignment) { //Delete index files var indexFileName = SubGridIndexFileName(localPathAndFileName); if (File.Exists(indexFileName)) { File.Delete(indexFileName); } indexFileName = SpatialIndexFileName(localPathAndFileName); if (File.Exists(indexFileName)) { File.Delete(indexFileName); } indexFileName = BoundaryFileName(localPathAndFileName); if (File.Exists(indexFileName)) { File.Delete(indexFileName); } } } catch (Exception e) { log.LogError(e, $"Failed to delete files related to design/surveyed surface {request.DesignUid} in project {request.ProjectUid}"); } } if (request.FileType != ImportedFileType.Alignment) { //Remove the index files from s3 (project service removes the actual file from s3 as it put it there originally) var s3FileTransfer = new S3FileTransfer(TransferProxyType.DesignImport); s3FileTransfer.RemoveFileFromBucket(request.ProjectUid, SubGridIndexFileName(request.FileName)); s3FileTransfer.RemoveFileFromBucket(request.ProjectUid, SpatialIndexFileName(request.FileName)); s3FileTransfer.RemoveFileFromBucket(request.ProjectUid, BoundaryFileName(request.FileName)); } }