Example #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public FileImportV5TBCController(IConfigurationStore config,
                                  ITransferProxyFactory transferProxyFactory,
                                  IFilterServiceProxy filterServiceProxy, ITRexImportFileProxy tRexImportFileProxy,
                                  IRequestFactory requestFactory)
     : base(config, transferProxyFactory, filterServiceProxy, tRexImportFileProxy, requestFactory)
 {
 }
Example #2
0
        public async Task <IActionResult> PostSnsTagFile(
            [FromServices] IWebRequest webRequest,
            [FromServices] ILoggerFactory loggerFactory,
            [FromServices] IConfigurationStore configStore,
            [FromServices] IDataCache dataCache,
            [FromServices] ITRexTagFileProxy trexTagFileProxy,
            [FromServices] ITransferProxyFactory transferProxyFactory)
        {
            // https://forums.aws.amazon.com/thread.jspa?threadID=69413
            // AWS SNS is in text/plain, not application/json - so need to parse manually
            var payloadMs = new MemoryStream();
            await Request.Body.CopyToAsync(payloadMs);

            var payload = JsonConvert.DeserializeObject <SnsPayload>(Encoding.UTF8.GetString(payloadMs.ToArray()));

            if (payload == null)
            {
                return(BadRequest());
            }

            var result = await RequestExecutorContainer.Build <TagFileSnsProcessExecutor>(loggerFactory,
                                                                                          configStore, dataCache, trexTagFileProxy, transferProxyFactory, webRequest)
                         .ProcessAsync(payload);

            if (result != null)
            {
                return(Ok());
            }
            // Note sure if we return bad request or not on failed processing - will updated if needed
            return(BadRequest());
        }
Example #3
0
 /// <summary>
 /// Constructor with dependency injection
 /// </summary>
 public ExportController(ILoggerFactory loggerFactory, IExportJob exportJob, ITransferProxyFactory transferProxyFactory, IJobRunner jobRunner)
 {
     log                       = loggerFactory.CreateLogger <ExportController>();
     this.exportJob            = exportJob;
     this.transferProxyFactory = transferProxyFactory;
     this.jobRunner            = jobRunner;
 }
Example #4
0
        /// <summary>
        /// Builds this instance for specified executor type.
        /// </summary>
        /// <typeparam name="TExecutor">The type of the executor.</typeparam>
        public static TExecutor Build <TExecutor>(
            ILoggerFactory logger, IConfigurationStore configStore, IServiceExceptionHandler serviceExceptionHandler,
            string customerUid = null, string userId = null, string userEmailAddress = null, IHeaderDictionary headers = null,
            IProductivity3dV1ProxyCoord productivity3dV1ProxyCoord = null, IProductivity3dV2ProxyCompaction productivity3dV2ProxyCompaction = null,
            ITransferProxyFactory persistantTransferProxyFactory   = null, IFilterServiceProxy filterServiceProxy = null, ITRexImportFileProxy tRexImportFileProxy = null,
            IProjectRepository projectRepo        = null, IHttpContextAccessor httpContextAccessor = null, IDataOceanClient dataOceanClient = null,
            ITPaaSApplicationAuthentication authn = null, ISchedulerProxy schedulerProxy           = null, IPegasusClient pegasusClient     = null,
            ICwsProjectClient cwsProjectClient    = null, ICwsDeviceClient cwsDeviceClient         = null,
            ICwsProfileSettingsClient cwsProfileSettingsClient = null,
            IWebRequest gracefulClient = null, INotificationHubClient notificationHubClient = null
            )
            where TExecutor : RequestExecutorContainer, new()
        {
            ILogger log = null;

            if (logger != null)
            {
                log = logger.CreateLogger <RequestExecutorContainer>();
            }

            var executor = new TExecutor();

            executor.Initialise(
                log, configStore, serviceExceptionHandler, customerUid, userId, userEmailAddress, headers,
                productivity3dV1ProxyCoord, productivity3dV2ProxyCompaction,
                persistantTransferProxyFactory, filterServiceProxy, tRexImportFileProxy, projectRepo,
                httpContextAccessor, dataOceanClient, authn, schedulerProxy, pegasusClient, cwsProjectClient, cwsDeviceClient,
                cwsProfileSettingsClient, gracefulClient, notificationHubClient
                );

            return(executor);
        }
Example #5
0
        public async Task <ContractExecutionResult> PostTagFile([FromBody] CompactionTagFileRequest request,
                                                                [FromServices] ILoggerFactory loggerFactory,
                                                                [FromServices] IConfigurationStore configStore,
                                                                [FromServices] IDataCache dataCache,
                                                                [FromServices] ITRexTagFileProxy trexTagFileProxy,
                                                                [FromServices] ITransferProxyFactory transferProxyFactory,
                                                                [FromServices] IWebRequest webRequest)
        {
            var isDirect = Request.Path.Value.Contains("/direct");

            _logger.LogInformation($"{nameof(PostTagFile)} Attempting to process {(isDirect ? "Direct" : "Non-Direct")} tag file {request?.FileName}");
            var executor = RequestExecutorContainer
                           .Build <TagFileProcessExecutor>(loggerFactory, configStore, dataCache, trexTagFileProxy, transferProxyFactory, webRequest);

            executor.ArchiveOnInternalError = true;
            var result = await executor.ProcessAsync(request);

            _logger.LogInformation($"{nameof(PostTagFile)} Got result {JsonConvert.SerializeObject(result)} for Tag file: {request?.FileName}");


            // If we uploaded, return a successful result
            // (as the tag file may not have been processed for legitimate reasons)
            // We don't want the machine sending tag files over and over again in this instance
            return(new ContractExecutionResult());
        }
Example #6
0
 /// <summary>
 /// Constructor with dependency injection
 /// </summary>
 public ExportJob(IApiClient apiClient, ITransferProxyFactory transferProxyfactory, ILoggerFactory logger)
 {
     _log                  = logger.CreateLogger <ExportJob>();
     _apiClient            = apiClient;
     _transferProxyFactory = transferProxyfactory;
     _transferProxy        = _transferProxyFactory.NewProxy(TransferProxyType.Temporary);
 }
Example #7
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));
        }
Example #8
0
 /// <summary>
 ///
 /// Default constructor.
 /// </summary>
 public CompactionExportController(
     IConfigurationStore configStore, IFileImportProxy fileImportProxy, ICompactionSettingsManager settingsManager,
     IProductionDataRequestFactory requestFactory, IPreferenceProxy prefProxy,
     ITransferProxyFactory transferProxyFactory) :
     base(configStore, fileImportProxy, settingsManager)
 {
     this.prefProxy            = prefProxy;
     this.requestFactory       = requestFactory;
     this.transferProxyFactory = transferProxyFactory;
 }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileImportBaseController"/> class.
        /// </summary>
        public FileImportBaseController(IConfigurationStore config, ITransferProxyFactory transferProxyFactory,
                                        IFilterServiceProxy filterServiceProxy, ITRexImportFileProxy tRexImportFileProxy, IRequestFactory requestFactory)
        {
            this._requestFactory = requestFactory;

            this.persistantTransferProxyFactory = transferProxyFactory; //.NewProxy(TransferProxyType.DesignImport);
            this.filterServiceProxy             = filterServiceProxy;
            this.tRexImportFileProxy            = tRexImportFileProxy;

            ConfigStore           = config;
            FileSpaceId           = ConfigStore.GetValueString("TCCFILESPACEID");
            DataOceanRootFolderId = ConfigStore.GetValueString("DATA_OCEAN_ROOT_FOLDER_ID");
        }
Example #10
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);
        }
Example #11
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public Compaction3DMapController(ILoggerFactory loggerFactory,
                                         IServiceExceptionHandler serviceExceptionHandler,
                                         IConfigurationStore configStore,
                                         IFileImportProxy fileImportProxy,
                                         IProjectSettingsProxy projectSettingsProxy,
                                         IFilterServiceProxy filterServiceProxy,
                                         ICompactionSettingsManager settingsManager,
                                         IProductionDataTileService tileService,
#if RAPTOR
                                         IASNodeClient raptorClient,
#endif
                                         IBoundingBoxHelper boundingBoxHelper,
                                         ITRexCompactionDataProxy trexCompactionDataProxy,
                                         ITransferProxyFactory transferProxyFactory) : base(configStore, fileImportProxy, settingsManager)
        {
            this.tileService             = tileService;
            this.boundingBoxHelper       = boundingBoxHelper;
            this.trexCompactionDataProxy = trexCompactionDataProxy;
            this.transferProxyFactory    = transferProxyFactory;
        }
Example #12
0
        public static TExecutor Build <TExecutor>(ILoggerFactory loggerFactory,
                                                  IConfigurationStore configStore,
                                                  IDataCache dataCache,
                                                  ITRexTagFileProxy trexTagFileProxy,
                                                  ITransferProxyFactory transferProxyFactory,
                                                  IWebRequest webRequest)
            where TExecutor : RequestExecutorContainer, new()
        {
            var executor = new TExecutor()
            {
                LoggerFactory        = loggerFactory,
                ConfigStore          = configStore,
                DataCache            = dataCache,
                TRexTagFileProxy     = trexTagFileProxy,
                TransferProxyFactory = transferProxyFactory,
                WebRequest           = webRequest
            };

            return(executor);
        }
Example #13
0
 public void Initialise(ILogger logger, IConfigurationStore configStore,
                        IServiceExceptionHandler serviceExceptionHandler,
                        string customerUid, string userId = null, string userEmailAddress = null,
                        IHeaderDictionary headers         = null,
                        IProductivity3dV1ProxyCoord productivity3dV1ProxyCoord           = null,
                        IProductivity3dV2ProxyCompaction productivity3dV2ProxyCompaction = null,
                        ITransferProxyFactory persistantTransferProxyFactory             = null, IFilterServiceProxy filterServiceProxy = null,
                        ITRexImportFileProxy tRexImportFileProxy           = null, IProjectRepository projectRepo = null,
                        IHttpContextAccessor httpContextAccessor           = null,
                        IDataOceanClient dataOceanClient                   = null, ITPaaSApplicationAuthentication authn = null,
                        ISchedulerProxy schedulerProxy                     = null, IPegasusClient pegasusClient          = null,
                        ICwsProjectClient cwsProjectClient                 = null, ICwsDeviceClient cwsDeviceClient      = null,
                        ICwsProfileSettingsClient cwsProfileSettingsClient = null,
                        IWebRequest gracefulClient = null, INotificationHubClient notificationHubClient = null)
 {
     log = logger;
     this.configStore             = configStore;
     this.serviceExceptionHandler = serviceExceptionHandler;
     this.customerUid             = customerUid;
     this.userId                          = userId;
     this.userEmailAddress                = userEmailAddress;
     this.customHeaders                   = headers;
     this.productivity3dV1ProxyCoord      = productivity3dV1ProxyCoord;
     this.productivity3dV2ProxyCompaction = productivity3dV2ProxyCompaction;
     this.persistantTransferProxyFactory  = persistantTransferProxyFactory;
     this.filterServiceProxy              = filterServiceProxy;
     this.tRexImportFileProxy             = tRexImportFileProxy;
     this.projectRepo                     = projectRepo;
     this.httpContextAccessor             = httpContextAccessor;
     this.dataOceanClient                 = dataOceanClient;
     this.authn                    = authn;
     this.schedulerProxy           = schedulerProxy;
     this.pegasusClient            = pegasusClient;
     this.cwsProjectClient         = cwsProjectClient;
     this.cwsDeviceClient          = cwsDeviceClient;
     this.cwsProfileSettingsClient = cwsProfileSettingsClient;
     this.gracefulClient           = gracefulClient;
     this.notificationHubClient    = notificationHubClient;
 }
Example #14
0
 public TagFileController(ITransferProxyFactory transferProxyFactory, ILogger <TagFileController> logger)
 {
     _transferProxyFactory = transferProxyFactory;
     _logger = logger;
 }