public async Task <IActionResult> OnProjectAssociationChange([FromBody] List <string> trns) { Logger.LogInformation($"{nameof(OnProjectAssociationChange)} Associations Updated: {JsonConvert.SerializeObject(trns)}"); // We don't actually do anything with this data yet, other than clear cache // Since we call out to CWS for data var tasks = new Task[trns.Count]; for (var i = 0; i < trns.Count; i++) { var trn = trns[i]; var guid = TRNHelper.ExtractGuid(trn); if (!guid.HasValue) { continue; } Logger.LogInformation($"Clearing cache related to TRN: {guid.Value}"); tasks[i] = NotificationHubClient.Notify(new ProjectChangedNotification(guid.Value)); } await Task.WhenAll(tasks); return(Ok()); }
private Task NotifyChanges(string userUid, string projectUid) { // You'd like to think these are in the format of a guid, but a simple check will stop any cast exceptions var userTask = Guid.TryParse(userUid, out var u) ? NotificationHubClient.Notify(new UserChangedNotification(u)) : Task.CompletedTask; var projectTask = Guid.TryParse(projectUid, out var p) ? NotificationHubClient.Notify(new ProjectChangedNotification(p)) : Task.CompletedTask; return(Task.WhenAll(userTask, projectTask)); }
public async Task <ContractExecutionResult> DeleteImportedFileV6( [FromQuery] Guid projectUid, [FromQuery] Guid?importedFileUid, // for 3dpm imported files [FromServices] IPegasusClient pegasusClient, [FromServices] IWebClientWrapper webClient) { Logger.LogInformation($"{nameof(DeleteImportedFileV6)}: projectUid {projectUid} importedFileUid: {importedFileUid}"); await ValidateProjectId(projectUid.ToString()); var importedFiles = await ImportedFileRequestDatabaseHelper.GetImportedFiles(projectUid.ToString(), Logger, ProjectRepo).ConfigureAwait(false); ImportedFile existing = null; if (importedFiles.Count > 0) { existing = importedFiles.FirstOrDefault(f => f.ImportedFileUid == importedFileUid.ToString()); } if (existing == null) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 56); return(new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, "shouldn't get here")); // to keep compiler happy } var deleteImportedFile = new DeleteImportedFile( projectUid, existing.ImportedFileType, JsonConvert.DeserializeObject <FileDescriptor>(existing.FileDescriptor), Guid.Parse(existing.ImportedFileUid), existing.ImportedFileId, existing.LegacyImportedFileId, DataOceanRootFolderId, existing.SurveyedUtc); var result = await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <DeleteImportedFileExecutor>( LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, UserEmailAddress, customHeaders, persistantTransferProxyFactory : persistantTransferProxyFactory, filterServiceProxy : filterServiceProxy, tRexImportFileProxy : tRexImportFileProxy, projectRepo : ProjectRepo, dataOceanClient : DataOceanClient, authn : Authorization, pegasusClient : pegasusClient, cwsProjectClient : CwsProjectClient) .ProcessAsync(deleteImportedFile) ); await NotificationHubClient.Notify(new ProjectChangedNotification(projectUid)); Logger.LogInformation( $"{nameof(DeleteImportedFileV6)}: Completed successfully. projectUid {projectUid} importedFileUid: {importedFileUid}"); return(result); }
private async Task DoActivationAndNotification(string projectUid, Dictionary <Guid, bool> filesToUpdate) { var dbUpdateResult = await SetFileActivatedState(projectUid, filesToUpdate); await NotificationHubClient.Notify(new ProjectChangedNotification(Guid.Parse(projectUid))); }
/// <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); }