Beispiel #1
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"
            });
        }
Beispiel #2
0
        /// <summary>
        /// Downloads the file from TCC and if successful uploads it through the Project service.
        /// </summary>
        private async Task <(bool success, FileDataSingleResult file)> MigrateFile(ImportedFileDescriptor file, Project project)
        {
            if (_ignoredFiles != null && _ignoredFiles.Contains(file.ImportedFileUid))
            {
                Log.LogWarning($"{Method.Info()} Migrating file '{file.Name}', Uid: {file.ImportedFileUid} aborted, found in exclusion list.");

                return(success : false, file : null);
            }

            Log.LogInformation($"{Method.In()} Migrating file '{file.Name}', Uid: {file.ImportedFileUid}");

            string tempFileName;

            using (var fileContents = await FileRepo.GetFile(_fileSpaceId, $"{file.Path}/{file.Name}"))
            {
                _database.Update(file.LegacyFileId, (MigrationFile x) => x.MigrationState = MigrationState.InProgress, Table.Files);

                if (fileContents == null)
                {
                    var message = $"Failed to fetch file '{file.Name}' ({file.LegacyFileId}), not found";
                    _database.Update(file.LegacyFileId, (MigrationFile x) => x.MigrationState = MigrationState.FileNotFound, Table.Files);
                    _database.Insert(new MigrationMessage(file.ProjectUid, message));

                    Log.LogWarning($"{Method.Out()} {message}");

                    return(success : true, file : null);
                }

                var tempPath = Path.Combine(_tempFolder, file.CustomerUid, file.ProjectUid, file.ImportedFileUid);
                Directory.CreateDirectory(tempPath);

                tempFileName = Path.Combine(tempPath, file.Name);

                Log.LogInformation($"{Method.Info()} Creating temporary file '{tempFileName}' for file {file.ImportedFileUid}");

                if (_downloadProjectFiles)
                {
                    using (var tempFile = new FileStream(tempFileName, FileMode.Create))
                    {
                        fileContents.CopyTo(tempFile);

                        _database.Update(
                            file.LegacyFileId, (MigrationFile x) =>
                        {
                            // ReSharper disable once AccessToDisposedClosure
                            x.Length = tempFile.Length;
                        },
                            tableName: Table.Files);
                    }
                }
            }

            var result = new FileDataSingleResult();

            if (_downloadProjectFiles && _uploadProjectFiles)
            {
                Log.LogInformation($"{Method.Info()} Uploading file {file.ImportedFileUid}");

                result = ImportFile.SendRequestToFileImportV4(
                    _uploadFileApiUrl,
                    file,
                    tempFileName,
                    new ImportOptions(HttpMethod.Put));

                _database.Update(file.LegacyFileId, (MigrationFile x) => x.MigrationState              = MigrationState.Completed, Table.Files);
                _database.Update(project.LegacyProjectID, (MigrationProject x) => x.UploadedFileCount += 1, Table.Projects);
            }
            else
            {
                var skippedMessage = $"Skipped because DOWNLOAD_PROJECT_FILES={_downloadProjectFiles} && UPLOAD_PROJECT_FILES={_uploadProjectFiles}";

                _database.Update(file.LegacyFileId, (MigrationFile x) =>
                {
                    x.MigrationState        = MigrationState.Skipped;
                    x.MigrationStateMessage = skippedMessage;
                }, Table.Files);

                Log.LogDebug($"{Method.Info("DEBUG")} {skippedMessage}");
            }

            Log.LogInformation($"{Method.Out()} File {file.ImportedFileUid} update result {result.Code} {result.Message}");

            return(success : true, file : result);
        }