Beispiel #1
0
        /// <summary>
        /// Pass Coordinate System to TRex and save a copy in DataOcean for DXF tile generation.
        /// </summary>
        private async Task SaveCoordinateSystem(Guid projectUid,
                                                string coordinateSystemFileName,
                                                byte[] coordinateSystemFileContent)
        {
            //Save to DataOcean for DXF tile generation
            var rootFolder = configStore.GetValueString("DATA_OCEAN_ROOT_FOLDER_ID");

            if (string.IsNullOrEmpty(rootFolder))
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 115);
            }

            using (var ms = new MemoryStream(coordinateSystemFileContent))
            {
                await DataOceanHelper.WriteFileToDataOcean(
                    ms, rootFolder, customerUid, projectUid.ToString(),
                    DataOceanFileUtil.DataOceanFileName(coordinateSystemFileName, false, projectUid, null),
                    log, serviceExceptionHandler, dataOceanClient, authn, projectUid, configStore);
            }

            //Save in TRex
            CoordinateSystemSettingsResult coordinateSystemSettingsResult = await productivity3dV1ProxyCoord
                                                                            .CoordinateSystemPost(projectUid,
                                                                                                  coordinateSystemFileContent, coordinateSystemFileName, customHeaders);

            var message = string.Format($"Sending coordinate system to TRex returned code: {0} Message {1}.",
                                        coordinateSystemSettingsResult?.Code ?? -1,
                                        coordinateSystemSettingsResult?.Message ?? "coordinateSystemSettingsResult == null");

            log.LogDebug(message);
            if (coordinateSystemSettingsResult == null ||
                coordinateSystemSettingsResult.Code != 0 /* TASNodeErrorStatus.asneOK */)
            {
                log.LogCritical($"Failed to save coordinate system file in TRex for project {projectUid}");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Deletes file via Trex
        /// </summary>
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var deleteImportedFile = CastRequestObjectTo <DeleteImportedFile>(item, errorCode: 68);

            await CheckIfUsedInFilter(deleteImportedFile);

            await CheckIfHasReferenceSurfacesAsync(deleteImportedFile);

            // DB change must be made before productivity3dV2ProxyNotification.DeleteFile is called as it calls back here to get list of Active files
            //Don't think the above comment applies any more !
            var deleteImportedFileEvent = await ImportedFileRequestDatabaseHelper.DeleteImportedFileInDb
                                              (deleteImportedFile.ProjectUid, deleteImportedFile.ImportedFileUid, serviceExceptionHandler, projectRepo);

            ImportedFileInternalResult importedFileInternalResult = null;

            if (deleteImportedFile.IsTRexDesignFileType)
            {
                //Now delete in TRex
                await ImportedFileRequestHelper.NotifyTRexDeleteFile(deleteImportedFile.ProjectUid,
                                                                     deleteImportedFile.ImportedFileType, deleteImportedFile.FileDescriptor.FileName,
                                                                     deleteImportedFile.ImportedFileUid,
                                                                     deleteImportedFile.SurveyedUtc,
                                                                     log, customHeaders, serviceExceptionHandler,
                                                                     tRexImportFileProxy);

                //and from s3 bucket
                ProjectRequestHelper.DeleteFileFromS3Repository(
                    deleteImportedFile.ProjectUid.ToString(), deleteImportedFile.FileDescriptor.FileName,
                    deleteImportedFile.ImportedFileType == ImportedFileType.SurveyedSurface, deleteImportedFile.SurveyedUtc,
                    log, serviceExceptionHandler, persistantTransferProxyFactory.NewProxy(TransferProxyType.DesignImport));
            }

            if (deleteImportedFile.ImportedFileType == ImportedFileType.Linework ||
                deleteImportedFile.ImportedFileType == ImportedFileType.GeoTiff)
            {
                var dataOceanFileName = DataOceanFileUtil.DataOceanFileName(deleteImportedFile.FileDescriptor.FileName,
                                                                            deleteImportedFile.ImportedFileType == ImportedFileType.SurveyedSurface || deleteImportedFile.ImportedFileType == ImportedFileType.GeoTiff,
                                                                            deleteImportedFile.ImportedFileUid, deleteImportedFile.SurveyedUtc);

                importedFileInternalResult = await DataOceanHelper.DeleteFileFromDataOcean(
                    dataOceanFileName, deleteImportedFile.DataOceanRootFolder, customerUid,
                    deleteImportedFile.ProjectUid, deleteImportedFile.ImportedFileUid, log, dataOceanClient, authn, configStore);

                var tasks = new List <Task>();
                //delete generated DXF tiles
                var dxfFileName   = DataOceanFileUtil.GeneratedFileName(dataOceanFileName, deleteImportedFile.ImportedFileType);
                var dataOceanPath = DataOceanFileUtil.DataOceanPath(deleteImportedFile.DataOceanRootFolder, customerUid, deleteImportedFile.ProjectUid.ToString());
                var fullFileName  = $"{dataOceanPath}{Path.DirectorySeparatorChar}{dxfFileName}";
                tasks.Add(pegasusClient.DeleteTiles(fullFileName, DataOceanHelper.CustomHeaders(authn)));

                await Task.WhenAll(tasks);
            }

            if (importedFileInternalResult != null)
            {
                await ImportedFileRequestDatabaseHelper.UndeleteImportedFile
                    (deleteImportedFile.ProjectUid, deleteImportedFile.ImportedFileUid, serviceExceptionHandler, projectRepo);

                serviceExceptionHandler.ThrowServiceException(importedFileInternalResult.StatusCode, importedFileInternalResult.ErrorNumber, importedFileInternalResult.ResultCode, importedFileInternalResult.ErrorMessage1);
            }

            return(new ContractExecutionResult());
        }
Beispiel #3
0
        /// <summary>
        /// Common file processing method used by all importedFile endpoints.
        /// </summary>
        protected async Task <ImportedFileDescriptorSingleResult> UpsertFileInternal(
            string filename,
            Stream fileStream,
            Guid projectUid,
            ImportedFileType importedFileType,
            DxfUnitsType dxfUnitsType,
            DateTime fileCreatedUtc,
            DateTime fileUpdatedUtc,
            DateTime?surveyedUtc,
            ISchedulerProxy schedulerProxy,
            Guid?parentUid = null,
            double?offset  = null)
        {
            ImportedFileDescriptorSingleResult importedFile = null;

            var existing = await ImportedFileRequestDatabaseHelper
                           .GetImportedFileForProject
                               (projectUid.ToString(), filename, importedFileType, surveyedUtc,
                               Logger, ProjectRepo, offset, parentUid)
                           .ConfigureAwait(false);

            var creating = existing == null;

            Logger.LogInformation(
                creating
          ? $"{nameof(UpsertFileInternal)}. file doesn't exist already in DB: {filename} projectUid {projectUid} ImportedFileType: {importedFileType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())} parentUid {parentUid} offset: {offset}"
          : $"{nameof(UpsertFileInternal)}. file exists already in DB. Will be updated: {JsonConvert.SerializeObject(existing)}");

            FileDescriptor fileDescriptor = null;

            var importedFileUid   = creating ? Guid.NewGuid() : Guid.Parse(existing.ImportedFileUid);
            var dataOceanFileName = DataOceanFileUtil.DataOceanFileName(filename,
                                                                        importedFileType == ImportedFileType.SurveyedSurface || importedFileType == ImportedFileType.GeoTiff,
                                                                        importedFileUid, surveyedUtc);

            if (importedFileType == ImportedFileType.ReferenceSurface)
            {
                //FileDescriptor not used for reference surface but validation requires values
                fileDescriptor = FileDescriptor.CreateFileDescriptor("Not applicable", "Not applicable", filename);
            }
            else
            {
                if (IsTRexDesignFileType(importedFileType))
                {
                    fileDescriptor = ProjectRequestHelper.WriteFileToS3Repository(
                        fileStream, projectUid.ToString(), filename,
                        importedFileType == ImportedFileType.SurveyedSurface, surveyedUtc,
                        Logger, ServiceExceptionHandler, persistantTransferProxyFactory.NewProxy(TransferProxyType.DesignImport));
                }

                //This is needed for ATs.
                fileDescriptor = FileDescriptor.CreateFileDescriptor(
                    FileSpaceId,
                    $"/{CustomerUid}/{projectUid}",
                    filename);

                if (importedFileType == ImportedFileType.Linework || importedFileType == ImportedFileType.GeoTiff)
                {
                    //save copy to DataOcean
                    await DataOceanHelper.WriteFileToDataOcean(
                        fileStream, DataOceanRootFolderId, CustomerUid, projectUid.ToString(), dataOceanFileName,
                        Logger, ServiceExceptionHandler, DataOceanClient, Authorization, importedFileUid, ConfigStore);
                }
            }

            if (creating)
            {
                var createImportedFile = new CreateImportedFile(
                    projectUid, filename, fileDescriptor, importedFileType, surveyedUtc, dxfUnitsType,
                    fileCreatedUtc, fileUpdatedUtc, DataOceanRootFolderId, parentUid, offset, importedFileUid, dataOceanFileName);

                importedFile = await WithServiceExceptionTryExecuteAsync(() =>
                                                                         RequestExecutorContainerFactory
                                                                         .Build <CreateImportedFileExecutor>(
                                                                             LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, UserEmailAddress, customHeaders,
                                                                             productivity3dV2ProxyCompaction : Productivity3dV2ProxyCompaction,
                                                                             persistantTransferProxyFactory : persistantTransferProxyFactory, tRexImportFileProxy : tRexImportFileProxy,
                                                                             projectRepo : ProjectRepo, dataOceanClient : DataOceanClient, authn : Authorization, schedulerProxy : schedulerProxy,
                                                                             cwsProjectClient : CwsProjectClient)
                                                                         .ProcessAsync(createImportedFile)
                                                                         ) as ImportedFileDescriptorSingleResult;

                Logger.LogInformation(
                    $"{nameof(UpsertFileInternal)}: Create completed successfully. Response: {JsonConvert.SerializeObject(importedFile)}");
            }
            else
            {
                // this also validates that this customer has access to the projectUid
                var project = await ProjectRequestHelper.GetProject(projectUid, new Guid(CustomerUid), new Guid(UserId), Logger, ServiceExceptionHandler, CwsProjectClient, customHeaders);

                var importedFileUpsertEvent = new UpdateImportedFile(
                    projectUid, project.ShortRaptorProjectId, importedFileType,
                    (importedFileType == ImportedFileType.SurveyedSurface || importedFileType == ImportedFileType.GeoTiff)
            ? surveyedUtc
            : null,
                    dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, fileDescriptor,
                    Guid.Parse(existing?.ImportedFileUid), existing.ImportedFileId,
                    DataOceanRootFolderId, offset, dataOceanFileName);

                importedFile = await WithServiceExceptionTryExecuteAsync(() =>
                                                                         RequestExecutorContainerFactory
                                                                         .Build <UpdateImportedFileExecutor>(
                                                                             LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, UserEmailAddress, customHeaders,
                                                                             productivity3dV2ProxyCompaction : Productivity3dV2ProxyCompaction,
                                                                             tRexImportFileProxy : tRexImportFileProxy,
                                                                             projectRepo : ProjectRepo, dataOceanClient : DataOceanClient, authn : Authorization, schedulerProxy : schedulerProxy,
                                                                             cwsProjectClient : CwsProjectClient)
                                                                         .ProcessAsync(importedFileUpsertEvent)
                                                                         ) as ImportedFileDescriptorSingleResult;

                Logger.LogInformation(
                    $"{nameof(UpsertFileInternal)}: Update completed successfully. Response: {JsonConvert.SerializeObject(importedFile)}");
            }

            await NotificationHubClient.Notify(new ProjectChangedNotification(projectUid));

            return(importedFile);
        }