コード例 #1
0
 /// <summary>
 /// Create instance of ProjectFileDescriptor using ID
 /// </summary>
 public static ProjectFileDescriptor CreateProjectFileDescriptor
 (
     long?projectId,
     Guid?projectUId,
     FileDescriptor file,
     string coordSystemFileName,
     DxfUnitsType dxfUnitsType,
     long fileId,
     ImportedFileType fileType,
     Guid fileUid,
     string userEmailAddress,
     long?legacyFileId = null
 )
 {
     return(new ProjectFileDescriptor
     {
         ProjectId = projectId,
         ProjectUid = projectUId,
         File = file,
         CoordSystemFileName = coordSystemFileName,
         DXFUnitsType = dxfUnitsType,
         FileId = fileId,
         FileType = fileType,
         FileUid = fileUid,
         UserEmailAddress = userEmailAddress,
         LegacyFileId = legacyFileId
     });
 }
コード例 #2
0
        public async Task <ContractExecutionResult> GetDeleteFile(
            [FromQuery] Guid projectUid,
            [FromQuery] ImportedFileType fileType,
            [FromQuery] Guid fileUid,
            [FromQuery] string fileDescriptor,
            [FromQuery] long fileId,
            [FromQuery] long?legacyFileId
            )
        {
            log.LogDebug($"{nameof(GetDeleteFile)}: " + Request.QueryString);

            //Cannot delete a design or alignment file that is used in a filter
            //TODO: When scheduled reports are implemented, extend this check to them as well.
            if (fileType == ImportedFileType.DesignSurface || fileType == ImportedFileType.Alignment || fileType == ImportedFileType.ReferenceSurface)
            {
                var filters = await GetFilters(projectUid, Request.Headers.GetCustomHeaders());

                if (filters != null)
                {
                    var fileUidStr = fileUid.ToString();
                    if (filters.Any(f => f.DesignUid == fileUidStr || f.AlignmentUid == fileUidStr))
                    {
                        throw new ServiceException(HttpStatusCode.BadRequest,
                                                   new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                               "Cannot delete a design surface, reference surface or alignment file used in a filter"));
                    }
                }
            }
            return(new ContractExecutionResult(ContractExecutionStatesEnum.ExecutedSuccessfully, "Delete file notification successful"));
        }
コード例 #3
0
        /// <summary>
        /// Notify TRex of updated DESIGN file
        /// </summary>
        public static async Task <ContractExecutionResult> NotifyTRexUpdateFile(Guid projectUid,
                                                                                ImportedFileType importedFileType, string filename, Guid importedFileUid, DateTime?surveyedUtc,
                                                                                ILogger log, IHeaderDictionary headers, IServiceExceptionHandler serviceExceptionHandler,
                                                                                ITRexImportFileProxy tRexImportFileProxy)
        {
            var    result       = new ContractExecutionResult();
            string fullFileName = filename;

            if (importedFileType == ImportedFileType.SurveyedSurface && surveyedUtc != null)
            {
                fullFileName =
                    fullFileName.IncludeSurveyedUtcInName(surveyedUtc.Value);
            }
            var request = new DesignRequest(projectUid, importedFileType, fullFileName, importedFileUid, surveyedUtc);

            try
            {
                result = await tRexImportFileProxy
                         .UpdateFile(request, headers)
                         .ConfigureAwait(false);
            }
            catch (Exception e)
            {
                log.LogError(e, $"NotifyTRexAddFile UpdateFile in Trex gateway failed with exception. request:{JsonConvert.SerializeObject(request)} filename: {fullFileName}");

                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 57, "tRexImportFile.UpdateFile",
                                                              e.Message);
            }

            return(result);
        }
コード例 #4
0
 protected bool IsTRexDesignFileType(ImportedFileType importedFileType)
 {
     return(importedFileType == ImportedFileType.DesignSurface ||
            importedFileType == ImportedFileType.SurveyedSurface ||
            importedFileType == ImportedFileType.Alignment);
     //Don't save reference surface to s3 (The original design file will have been saved).
 }
コード例 #5
0
        public FileDataSingleResult CreateMockImportedFile(
            FlowFile file,
            [FromQuery] Guid projectUid,
            [FromQuery] ImportedFileType importedFileType,
            [FromQuery] DxfUnitsType dxfUnitsType,
            [FromQuery] DateTime fileCreatedUtc,
            [FromQuery] DateTime fileUpdatedUtc,
            [FromQuery] DateTime?surveyedUtc = null)
        {
            Logger.LogInformation(
                $"CreateMockImportedFile. file: {file.flowFilename} path {file.path} projectUid {projectUid} ImportedFileType: {importedFileType} " +
                $"DxfUnitsType: {dxfUnitsType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}");

            if (projectUid.ToString() == ConstantsUtil.DIMENSIONS_PROJECT_UID)
            {
                var result = new FileDataSingleResult();
                result.ImportedFileDescriptor = ImportedFilesService.ImportedFiles[ConstantsUtil.DIMENSIONS_PROJECT_UID]
                                                .SingleOrDefault(f => f.Name.Equals(file.flowFilename, StringComparison.OrdinalIgnoreCase));

                return(result);
            }

            return(new FileDataSingleResult
            {
                Code = ContractExecutionStatesEnum.InternalProcessingError,
                Message = "Failed to create imported file"
            });
        }
コード例 #6
0
        /// <summary>
        /// Validate the Create request e.g that the file has been uploaded and parameters are as expected.
        /// </summary>
        public static void ValidateUpsertImportedFileRequest(FlowFile file, Guid projectUid,
                                                             ImportedFileType importedFileType, DxfUnitsType dxfUnitsType,
                                                             DateTime fileCreatedUtc, DateTime fileUpdatedUtc,
                                                             string importedBy, DateTime?surveyedUtc, Guid?parentUid, double?offset)
        {
            if (file == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(27),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(27)));
            }

            if (file.flowFilename.Length > MAX_FILE_NAME_LENGTH || string.IsNullOrEmpty(file.flowFilename) ||
                file.flowFilename.IndexOfAny(Path.GetInvalidPathChars()) > 0)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(28),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(28)));
            }

            if (string.IsNullOrEmpty(file.path) || file.path.IndexOfAny(Path.GetInvalidPathChars()) > 0)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(29),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(29)));
            }

            ValidateUpsertImportedFileRequest(projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, importedBy, surveyedUtc, file.flowFilename, parentUid, offset);
        }
コード例 #7
0
        private void DeleteLocalFiles(Guid siteModelUid, string filename, ImportedFileType importedFileTypeEnum)
        {
            var localPath            = FilePathHelper.GetTempFolderForProject(siteModelUid);
            var localPathAndFileName = Path.Combine(new[] { localPath, filename });

            if (System.IO.File.Exists(localPathAndFileName))
            {
                System.IO.File.Delete(localPathAndFileName);

                if (importedFileTypeEnum != ImportedFileType.Alignment)
                {
                    var indexFilename = SubGridIndexFileName(localPathAndFileName);
                    if (System.IO.File.Exists(indexFilename))
                    {
                        System.IO.File.Delete(indexFilename);
                    }
                    indexFilename = SpatialIndexFileName(localPathAndFileName);
                    if (System.IO.File.Exists(indexFilename))
                    {
                        System.IO.File.Delete(indexFilename);
                    }
                    indexFilename = BoundaryFileName(localPathAndFileName);
                    if (System.IO.File.Exists(indexFilename))
                    {
                        System.IO.File.Delete(indexFilename);
                    }
                }
            }
        }
コード例 #8
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
            });
        }
コード例 #9
0
        public async Task <ImportedFileDescriptorSingleResult> CreateImportedFileDirectV6(
            [FromServices] ISchedulerProxy schedulerProxy,
            Guid projectUid,
            string filename,
            ImportedFileType importedFileType,
            DxfUnitsType dxfUnitsType,
            DateTime fileCreatedUtc,
            DateTime fileUpdatedUtc,
            DateTime?surveyedUtc = null)
        {
            if (importedFileType == ImportedFileType.ReferenceSurface)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 122);
            }

            FileImportDataValidator.ValidateUpsertImportedFileRequest(projectUid, importedFileType, dxfUnitsType, fileCreatedUtc,
                                                                      fileUpdatedUtc, UserEmailAddress, surveyedUtc, filename, null, null);
            Logger.LogInformation(
                $"{nameof(CreateImportedFileDirectV6)}: ProjectUID: `{projectUid}`, Filename: `{filename}` ImportedFileType: `{importedFileType}`, DxfUnitsType: `{dxfUnitsType}`, SurveyedUTC: `{(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}`");

            //When debugging locally using Postman, remove this check so can do an update
            await ValidateFileDoesNotExist(projectUid.ToString(), filename, importedFileType, surveyedUtc, null, null);

            if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 58, $"Expected a multipart request, but got '{Request.ContentType}'");
            }

            var tempFilePath = await HttpContext.Request.StreamFile(Guid.NewGuid().ToString(), Logger);

            var result = await UpsertFile(tempFilePath, filename, projectUid.ToString(), importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, surveyedUtc, schedulerProxy);

            return(result);
        }
コード例 #10
0
        async Task ImportFileIntoLocalDB(string filePath, ImportedFileType fileType)
        {
            readerModelCommon = new FileReaderModels();

            ISQLConnectionSettings newConnection = new SQLConnectionSettings
            {
                Database = $"{Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath))}.db"
            };

            dBOperations = new SQLiteModelDBOperations(newConnection);
            dBOperations.EvntInfoMessage += new SqlAbstractConnector.Message <TextEventArgs>(AddLineAtTextBoxResultShow);

            SetAdminStatusLabelText($"Импорт файла '{filePath}' в базу данных...");
            AddLineAtTextBoxResultShow();

            readerModelCommon.EvntInfoMessage    += new FileReaderModels.Message <TextEventArgs>(AddLineAtTextBoxResultShow);
            readerModelCommon.EvntHeaderReady    += new FileReaderModels.CollectionFull <BoolEventArgs>(ModelCommon_EvntHeaderReady);
            readerModelCommon.EvntCollectionFull += new FileReaderModels.CollectionFull <BoolEventArgs>(ModelCommon_collectionFull);

            await readerModelCommon.SelectImportingMethod(filePath, fileType, MAX_ELEMENTS_COLLECTION);

            readerModelCommon.EvntCollectionFull -= ModelCommon_collectionFull;
            readerModelCommon.EvntHeaderReady    -= ModelCommon_EvntHeaderReady;
            readerModelCommon.EvntInfoMessage    -= AddLineAtTextBoxResultShow;

            SetAdminStatusLabelText($"Всего в БД '{newConnection.Database}' импортировано {readerModelCommon.importedRows} строк.");
            AddLineAtTextBoxResultShow("newConnection: " + newConnection.ToString());
            dBOperations.EvntInfoMessage -= AddLineAtTextBoxResultShow;

            readerModelCommon = null;
            AddLineAtTextBoxResultShow();

            currentSQLConnectionStore.Set(newConnection);
            currentSQLConnectionStore.Refresh();
        }
コード例 #11
0
        async Task GetFile(ImportedFileType typeFile)
        {
            MakeTextBoxResultShow();
            txtbResultShow.ReadOnly = true;
            EnabledInterface(false);

            string filePath = null;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                if (typeFile == ImportedFileType.Text)
                {
                    filePath = ofd.OpenFileDialogReturnPath(Properties.Resources.DialogTextFile, "Выберите для импорта текстовый файл с данными и резделителями:");
                }
                else if (typeFile == ImportedFileType.Excel)
                {
                    filePath = ofd.OpenFileDialogReturnPath(Properties.Resources.DialogExcelFile, "Выберите для импорта Excel файл с данными. Первая строчка должна содержать названия колонок:");
                }
            }

            if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath))
            {
                await ImportFileIntoLocalDB(filePath, typeFile);

                await Task.Run(() => ShowMessage("Готово!"));
            }
            else
            {
                AddLineAtTextBoxResultShow($"Файл '{filePath}' пустой или не выбран");
            }

            HideTextBoxResultShow();
            EnabledInterface(true);
        }
コード例 #12
0
        public static async Task <ImportedFile> GetImportedFileForProject
            (string projectUid, string fileName, ImportedFileType importedFileType, DateTime?surveyedUtc,
            ILogger log, IProjectRepository projectRepo, double?offset, Guid?parentUid)
        {
            var importedFiles = await ImportedFileRequestDatabaseHelper.GetImportedFiles(projectUid, log, projectRepo).ConfigureAwait(false);

            ImportedFile existing = null;

            if (importedFiles.Count > 0)
            {
                if (importedFileType == ImportedFileType.ReferenceSurface)
                {
                    existing = importedFiles.FirstOrDefault
                                   (f => f.ImportedFileType == ImportedFileType.ReferenceSurface &&
                                   f.ParentUid == parentUid.ToString() &&
                                   f.Offset.EqualsToNearestMillimeter(offset));
                }
                else
                {
                    existing = importedFiles.FirstOrDefault(
                        f => string.Equals(f.Name, fileName, StringComparison.OrdinalIgnoreCase) &&
                        f.ImportedFileType == importedFileType &&
                        (
                            importedFileType == ImportedFileType.SurveyedSurface &&
                            f.SurveyedUtc == surveyedUtc ||
                            importedFileType != ImportedFileType.SurveyedSurface
                        ));
                }
            }
            return(existing);
        }
コード例 #13
0
 public DesignRequest(Guid projectUid, ImportedFileType fileType, string fileName, Guid designUid, DateTime?surveyedUtc)
 {
     ProjectUid  = projectUid;
     FileType    = fileType;
     FileName    = fileName;
     DesignUid   = designUid;
     SurveyedUtc = surveyedUtc;
 }
コード例 #14
0
        public void IsDesignFileType_returns_correct_value_For_ImportedFileType(ImportedFileType importedFileType, bool expectedResult)
        {
            var obj = new DeleteImportedFile(Guid.NewGuid(), importedFileType, null,
                                             Guid.NewGuid(), 0, 0, null,
                                             importedFileType == ImportedFileType.SurveyedSurface || importedFileType == ImportedFileType.GeoTiff ? DateTime.UtcNow : (DateTime?)null);

            Assert.Equal(expectedResult, obj.IsDesignFileType);
        }
コード例 #15
0
 public ImportFileV5TBCValidationTests()
 {
     _projectUid         = Guid.NewGuid();
     _fileSpaceId        = "u3bdc38d-1afe-470e-8c1c-fc241d4c5e01";
     _path               = "/BC Data/Sites/Chch Test Site";
     _name               = "CTCTSITECAL.dc";
     _importedFileTypeId = ImportedFileType.DesignSurface;
     _createdUtc         = DateTime.UtcNow.AddDays(-0.5);
 }
コード例 #16
0
        public async Task <ScheduleJobResult> BackgroundUpload(
            FlowFile file,
            [FromQuery] Guid projectUid,
            [FromQuery] ImportedFileType importedFileType,
            [FromQuery] DxfUnitsType dxfUnitsType,
            [FromQuery] DateTime fileCreatedUtc,
            [FromQuery] DateTime fileUpdatedUtc,
            [FromQuery] DateTime?surveyedUtc,
            [FromServices] ISchedulerProxy scheduler,
            [FromServices] ITransferProxyFactory transferProxyFactory)
        {
            if (importedFileType == ImportedFileType.ReferenceSurface)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 122);
            }

            FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(
                file, projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, UserEmailAddress, surveyedUtc, null, null);
            Logger.LogInformation(
                $"{nameof(BackgroundUpload)}: file: {file.flowFilename} path {file.path} projectUid {projectUid} ImportedFileType: {importedFileType} " +
                $"DxfUnitsType: {dxfUnitsType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}");

            if (string.Equals(Request.Method, HttpMethod.Post.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                await ValidateFileDoesNotExist(projectUid.ToString(), file.flowFilename, importedFileType, surveyedUtc, null, null);
            }

            var s3Path        = $"project/importedfile/{Guid.NewGuid()}.dat";
            var fileStream    = System.IO.File.Open(file.path, FileMode.Open, FileAccess.Read);
            var transferProxy = transferProxyFactory.NewProxy(TransferProxyType.Temporary);

            transferProxy.Upload(fileStream, s3Path);

            var baseUrl = Request.Host.ToUriComponent();

            // The QueryString will have values in it, so it's safe to add extra queries with the & as opposed to ?, then &
            var callbackUrl = $"http://{baseUrl}/internal/v6/importedfile{Request.QueryString}";

            callbackUrl += $"&filename={WebUtility.UrlEncode(file.flowFilename)}&awsFilePath={WebUtility.UrlEncode(s3Path)}";

            Logger.LogInformation($"{nameof(BackgroundUpload)}: baseUrl {callbackUrl}");

            var executionTimeout = ConfigStore.GetValueInt("PEGASUS_EXECUTION_TIMEOUT_MINS", 5) * 60000;//minutes converted to millisecs
            var request          = new ScheduleJobRequest
            {
                Filename = file.flowFilename,
                Method   = "GET", // match the internal upload Method
                Url      = callbackUrl,
                Timeout  = executionTimeout
            };

            request.SetStringPayload(string.Empty);

            var headers = Request.Headers.GetCustomHeaders();

            return(await scheduler.ScheduleBackgroundJob(request, headers));
        }
コード例 #17
0
        public void DesignRequestValidation_Errors(string projectUid, ImportedFileType fileType, string fileName, string designUid, int expectedCode, string expectedMessage)
        {
            var designSurfaceRequest = new DesignRequest(Guid.Parse(projectUid), fileType, fileName, Guid.Parse(designUid), null);

            var ex = Assert.Throws <ServiceException>(() => designSurfaceRequest.Validate());

            Assert.Equal(expectedCode, ex.GetResult.Code);
            Assert.Equal(expectedMessage, ex.GetResult.Message);
        }
コード例 #18
0
        public void Should_validate_correctly_When_given_an_imported_filetype(ImportedFileType importedFileType,
                                                                              bool expectedResult)
        {
            var fileData = new FileData {
                ImportedFileType = importedFileType
            };

            Assert.AreEqual(expectedResult, fileData.IsProfileSupportedFileType());
        }
コード例 #19
0
 public DXFBoundariesRequest(string csibFileData, ImportedFileType fileType, string dxfFileData, DxfUnitsType fileUnits, uint maxBoundaries, bool convertLineStringCoordsToPolygon)
 {
     CSIBFileData  = csibFileData;
     FileType      = fileType;
     DXFFileData   = dxfFileData;
     FileUnits     = fileUnits;
     MaxBoundaries = maxBoundaries;
     ConvertLineStringCoordsToPolygon = convertLineStringCoordsToPolygon;
 }
コード例 #20
0
        /// <summary>
        /// Gets the imported files of the specified type in a project
        /// </summary>
        /// <param name="projectUid">The project UID</param>
        /// <param name="fileType">The type of files to retrieve</param>
        /// <returns>List of active imported files of specified type</returns>
        private async Task <List <FileData> > GetFilesOfType(Guid projectUid, ImportedFileType fileType)
        {
            var fileList = await FileImportProxy.GetFiles(projectUid.ToString(), GetUserId(), CustomHeaders);

            if (fileList == null || fileList.Count == 0)
            {
                return(new List <FileData>());
            }

            return(fileList.Where(f => f.ImportedFileType == fileType && f.IsActivated).ToList());
        }
コード例 #21
0
        /// <summary>
        /// Creates an imported file in Db.
        /// </summary>
        /// <returns />
        public static async Task <CreateImportedFileEvent> CreateImportedFileinDb(Guid customerUid, Guid projectUid,
                                                                                  ImportedFileType importedFileType, DxfUnitsType dxfUnitsType, string filename, DateTime?surveyedUtc,
                                                                                  string fileDescriptor, DateTime fileCreatedUtc, DateTime fileUpdatedUtc, string importedBy,
                                                                                  ILogger log, IServiceExceptionHandler serviceExceptionHandler, IProjectRepository projectRepo,
                                                                                  Guid?parentUid, double?offset, Guid importedFileUid)
        {
            log.LogDebug($"Creating the ImportedFile {filename} for project {projectUid}.");
            var nowUtc = DateTime.UtcNow;
            var createImportedFileEvent = new CreateImportedFileEvent
            {
                CustomerUID      = customerUid,
                ProjectUID       = projectUid,
                ImportedFileUID  = importedFileUid,
                ImportedFileType = importedFileType,
                DxfUnitsType     = dxfUnitsType,
                Name             = filename,
                FileDescriptor   = fileDescriptor,
                FileCreatedUtc   = fileCreatedUtc,
                FileUpdatedUtc   = fileUpdatedUtc,
                ImportedBy       = importedBy,
                SurveyedUTC      = surveyedUtc,
                ActionUTC        = nowUtc,
                ParentUID        = parentUid,
                Offset           = offset ?? 0
            };

            var isCreated = await projectRepo.StoreEvent(createImportedFileEvent).ConfigureAwait(false);

            if (isCreated == 0)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 49);
            }

            log.LogDebug($"Created the ImportedFile in DB. ImportedFile {filename} for project {projectUid}.");

            // plug the legacyID back into the struct to be injected into kafka
            var existing = await projectRepo.GetImportedFile(createImportedFileEvent.ImportedFileUID.ToString())
                           .ConfigureAwait(false);

            if (existing != null && existing.ImportedFileId > 0)
            {
                createImportedFileEvent.ImportedFileID  = existing.ImportedFileId;
                createImportedFileEvent.ImportedFileUID = Guid.Parse(existing.ImportedFileUid); // for unit tests
            }
            else
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 50);
            }

            log.LogDebug(
                $"CreateImportedFileinDb: Legacy importedFileId {createImportedFileEvent.ImportedFileID} for ImportedFile {filename} for project {projectUid}.");
            return(createImportedFileEvent);
        }
コード例 #22
0
        /// <summary>
        /// The suffix to apply to a generated file name for an associated file
        /// </summary>
        /// <param name="fileType">The type of file for which the associated file will be generated</param>
        /// <returns>The suffix</returns>
        public static string GeneratedFileSuffix(ImportedFileType fileType)
        {
            switch (fileType)
            {
            case ImportedFileType.Linework: return(string.Empty);

            case ImportedFileType.Alignment: return(GENERATED_ALIGNMENT_CENTERLINE_FILE_SUFFIX);

            case ImportedFileType.DesignSurface: return(GENERATED_SURFACE_FILE_SUFFIX);
            }
            return(string.Empty);
        }
コード例 #23
0
        public async Task <AddFileResult> AddFile(Guid projectUid, ImportedFileType fileType, Guid fileUid, string fileDescriptor, long fileId, DxfUnitsType dxfUnitsType, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(AddFile)} projectUid: {projectUid} fileUid: {fileUid} fileDescriptor: {fileDescriptor} fileId: {fileId} dxfUnitsType: {dxfUnitsType}");
            var queryParams = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("projectUid", projectUid.ToString()), new KeyValuePair <string, string>("fileType", fileType.ToString()),
                new KeyValuePair <string, string>("fileUid", fileUid.ToString()), new KeyValuePair <string, string>("fileDescriptor", fileDescriptor),
                new KeyValuePair <string, string>("fileId", fileId.ToString()), new KeyValuePair <string, string>("dxfUnitsType", dxfUnitsType.ToString())
            };

            return(await NotifyFile <AddFileResult>("/notification/addfile", queryParams, customHeaders));
        }
コード例 #24
0
        public async Task <BaseMasterDataResult> DeleteFile(Guid projectUid, ImportedFileType fileType, Guid fileUid, string fileDescriptor, long fileId, long?legacyFileId, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(DeleteFile)} projectUid: {projectUid} fileUid: {fileUid} fileDescriptor: {fileDescriptor} fileId: {fileId} legacyFileId: {legacyFileId}");
            var queryParams = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("projectUid", projectUid.ToString()), new KeyValuePair <string, string>("fileType", fileType.ToString()),
                new KeyValuePair <string, string>("fileUid", fileUid.ToString()), new KeyValuePair <string, string>("fileDescriptor", fileDescriptor),
                new KeyValuePair <string, string>("fileId", fileId.ToString())
            };

            return(await NotifyFile <BaseMasterDataResult>("/notification/deletefile", queryParams, customHeaders));
        }
コード例 #25
0
        /// <summary>
        /// Notify TRex of new DESIGN file
        /// </summary>
        /// <returns></returns>
        public static async Task <ContractExecutionResult> NotifyTRexAddFile(Guid projectUid,
                                                                             ImportedFileType importedFileType, string filename, Guid importedFileUid, DateTime?surveyedUtc,
                                                                             ILogger log, IHeaderDictionary headers, IServiceExceptionHandler serviceExceptionHandler,
                                                                             ITRexImportFileProxy tRexImportFileProxy, IProjectRepository projectRepo
                                                                             )
        {
            var result = new ContractExecutionResult();

            string fullFileName = filename;

            if (importedFileType == ImportedFileType.SurveyedSurface && surveyedUtc != null)
            {
                fullFileName =
                    fullFileName.IncludeSurveyedUtcInName(surveyedUtc.Value);
            }
            var request = new DesignRequest(projectUid, importedFileType, fullFileName, importedFileUid, surveyedUtc);

            try
            {
                result = await tRexImportFileProxy
                         .AddFile(request, headers)
                         .ConfigureAwait(false);
            }
            catch (Exception e)
            {
                log.LogError(e, $"NotifyTRexAddFile AddFile in Trex gateway failed with exception. request:{JsonConvert.SerializeObject(request)} filename: {fullFileName}");

                await ImportedFileRequestDatabaseHelper.DeleteImportedFileInDb
                    (projectUid, importedFileUid, serviceExceptionHandler, projectRepo, true)
                .ConfigureAwait(false);

                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 57, "tRexImportFile.AddFile",
                                                              e.Message);
            }

            log.LogDebug(
                $"NotifyTRexAddFile: projectUid: {projectUid}, filename: {filename} importedFileUid {importedFileUid}. TRex returned code: {result?.Code ?? -1}.");

            if (result != null && result.Code != 0)
            {
                log.LogError(
                    $"NotifyTRexAddFile AddFile in Trex failed. projectUid: {projectUid}, filename: {filename} importedFileUid {importedFileUid}. Reason: {result?.Code ?? -1} {result?.Message ?? "null"}.");

                await ImportedFileRequestDatabaseHelper.DeleteImportedFileInDb(projectUid, importedFileUid,
                                                                               serviceExceptionHandler, projectRepo, true)
                .ConfigureAwait(false);

                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 114,
                                                              result.Code.ToString(), result.Message);
            }

            return(result);
        }
コード例 #26
0
        /// <summary>
        /// Gets the generated DXF file name
        /// </summary>
        public static string GeneratedFileName(string fileName, ImportedFileType fileType)
        {
            if (fileType == ImportedFileType.Alignment)
            {
                return($"{Path.GetFileNameWithoutExtension(fileName)}{GENERATED_ALIGNMENT_CENTERLINE_FILE_SUFFIX}{DXF_FILE_EXTENSION}");
            }

            if (fileType == ImportedFileType.Linework || fileType == ImportedFileType.GeoTiff)
            {
                return(fileName);
            }
            throw new ArgumentException($"{fileName} is not a DXF, GeoTIFF or alignment file.");
        }
コード例 #27
0
        public async Task <ImportedFileDescriptorSingleResult> InternalImportedFileV6(

            [FromQuery] string filename,
            [FromQuery] string awsFilePath,
            [FromQuery] Guid projectUid,
            [FromQuery] ImportedFileType importedFileType,
            [FromQuery] DxfUnitsType dxfUnitsType,
            [FromQuery] DateTime fileCreatedUtc,
            [FromQuery] DateTime fileUpdatedUtc,
            [FromQuery] DateTime?surveyedUtc,
            [FromServices] ITransferProxyFactory transferProxyFactory,
            [FromServices] ISchedulerProxy schedulerProxy)
        {
            if (importedFileType == ImportedFileType.ReferenceSurface)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 122);
            }

            ImportedFileDescriptorSingleResult importedFileResult = null;
            var transferProxy = transferProxyFactory.NewProxy(TransferProxyType.Temporary);

            Logger.LogInformation(
                $"{nameof(InternalImportedFileV6)}:. filename: {filename} awspath {awsFilePath} projectUid {projectUid} ImportedFileType: {importedFileType} " +
                $"DxfUnitsType: {dxfUnitsType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}");

            // Retrieve the stored file from AWS
            var fileResult = await transferProxy.Download(awsFilePath);

            if (fileResult == null)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 55);
            }

            using (var ms = new MemoryStream())
            {
                // Depending on the size of the file in S3, the stream returned may or may not support seeking
                // Which we need to TCC to know the length of the file (can't find the length, if you can't seek).
                // To solve this, we have to download the entire stream here and copy to memory.
                // Allowing TCC to upload the file.
                // Not the best solution for extra large files, but TCC doesn't support uploading without file size AFAIK
                fileResult.FileStream.CopyTo(ms);

                importedFileResult = await UpsertFileInternal(filename, ms, projectUid, importedFileType, dxfUnitsType,
                                                              fileCreatedUtc, fileUpdatedUtc, surveyedUtc, schedulerProxy);
            }

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

            return(importedFileResult);
        }
コード例 #28
0
        public BaseMasterDataResult DummyDeleteFileGet(
            [FromQuery] Guid projectUid,
            [FromQuery] ImportedFileType fileType,
            [FromQuery] Guid fileUid,
            [FromQuery] string fileDescriptor,
            [FromQuery] long fileId)
        {
            var res     = new BaseMasterDataResult();
            var message =
                $"DummyDeleteFileGet: res {res}. projectUid {projectUid} fileType {fileType} fileUid {fileUid} fileDescriptor {fileDescriptor} fileId {fileId}";

            Console.WriteLine(message);
            return(res);
        }
コード例 #29
0
 public DeleteImportedFile(
     Guid projectUid, ImportedFileType importedFileTypeId,
     FileDescriptor fileDescriptor, Guid importedFileUid, long importedFileId,
     long?legacyImportedFileId, string dataOceanRootFolder, DateTime?surveyedUtc)
 {
     ProjectUid           = projectUid;
     ImportedFileType     = importedFileTypeId;
     FileDescriptor       = fileDescriptor;
     ImportedFileUid      = importedFileUid;
     ImportedFileId       = importedFileId;
     LegacyImportedFileId = legacyImportedFileId;
     DataOceanRootFolder  = dataOceanRootFolder;
     SurveyedUtc          = surveyedUtc;
 }
コード例 #30
0
 public TCCFile(ImportedFileType fileType, string fileName, string path)
 {
     FileType = fileType;
     FileName = fileName;
     FilePath = path;
     if (fileType != GetFileType(fileName))
     {
         throw new ArgumentException("File extension does not match file type",
                                     $"Filename: {fileName} Filetype: {fileType}");
     }
     if (fileType == ImportedFileType.SurveyedSurface)
     {
         SurveyedSurfaceTimestamp = SurveyedSurfaceUtc(fileName);
     }
 }