Example #1
0
        public async Task <ReturnLongV5Result> UpsertImportedFileV5TBC(
            [FromRoute] long projectId,
            [FromBody] ImportedFileTbc importedFileTbc,
            [FromServices] ISchedulerProxy schedulerProxy)
        {
            // MobileLinework .kml/.kmz files are sent along with linework files
            //     we need to suppress any error and return as if all ok.
            //     however we won't have a LegacyFileId to return - hmmm hope Business centre ignores this
            if (importedFileTbc.ImportedFileTypeId == ImportedFileType.MobileLinework)
            {
                Logger.LogInformation(
                    $"{nameof(UpsertImportedFileV5TBC)}: Ignore MobileLinework from BusinessCentre. projectId {projectId} importedFile: {JsonConvert.SerializeObject(importedFileTbc)}");

                return(ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.OK, -1));
            }

            // this also validates that this customer has access to the projectUid
            var project = await ProjectRequestHelper.GetProjectForCustomer(new Guid(CustomerUid), new Guid(UserId), projectId, Logger, ServiceExceptionHandler, CwsProjectClient, customHeaders);

            var projectUid = project.ProjectId;

            importedFileTbc = FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(new Guid(projectUid), importedFileTbc);
            Logger.LogInformation(
                $"{nameof(UpsertImportedFileV5TBC)}: projectId {projectId} projectUid {projectUid} importedFile: {JsonConvert.SerializeObject(importedFileTbc)}");

            var fileEntry = await TccHelper.GetFileInfoFromTccRepository(importedFileTbc, Logger, ServiceExceptionHandler, FileRepo);

            await TccHelper.CopyFileWithinTccRepository(importedFileTbc,
                                                        CustomerUid, projectUid, FileSpaceId,
                                                        Logger, ServiceExceptionHandler, FileRepo).ConfigureAwait(false);

            ImportedFileDescriptorSingleResult importedFileResult;

            using (var ms = await TccHelper.GetFileStreamFromTcc(importedFileTbc, Logger, ServiceExceptionHandler, FileRepo))
            {
                importedFileResult = await UpsertFileInternal(importedFileTbc.Name, ms, new Guid(projectUid),
                                                              importedFileTbc.ImportedFileTypeId,
                                                              importedFileTbc.ImportedFileTypeId == ImportedFileType.Linework
                                                              ?importedFileTbc.LineworkFile.DxfUnitsTypeId
                                                              : DxfUnitsType.Meters,
                                                              fileEntry.createTime, fileEntry.modifyTime,
                                                              importedFileTbc.ImportedFileTypeId == ImportedFileType.SurveyedSurface
                                                              ?importedFileTbc.SurfaceFile.SurveyedUtc
                                                              : (DateTime?)null, schedulerProxy);
            }

            // Automapper maps src.ImportedFileId to LegacyFileId, so this IS the one sent to TRex and used to ref via TCC
            var response = importedFileResult != null
        ? ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.OK, importedFileResult.ImportedFileDescriptor.LegacyFileId)
        : ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.InternalServerError, -1);

            Logger.LogInformation(
                $"{nameof(UpsertImportedFileV5TBC)}: Completed successfully. Response: {response} importedFile: {JsonConvert.SerializeObject(importedFileResult)}");

            return(response);
        }