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); }
/// <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); }