Beispiel #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public LineworkTileController(IProductivity3dV2ProxyCompactionTile productivity3DProxyCompactionTile, IPreferenceProxy prefProxy, IFileImportProxy fileImportProxy,
                               IMapTileGenerator tileGenerator, IMemoryCache cache, IConfigurationStore configStore,
                               IBoundingBoxHelper boundingBoxHelper, IDataOceanClient dataOceanClient, ITPaaSApplicationAuthentication authn)
     : base(productivity3DProxyCompactionTile, prefProxy, fileImportProxy, tileGenerator, cache, configStore, boundingBoxHelper, authn)
 {
     this.dataOceanClient = dataOceanClient;
 }
Beispiel #2
0
        /// <summary>
        /// Client for sending requests to the Pegasus API.
        /// </summary>
        public PegasusClient(IConfigurationStore configuration, ILoggerFactory logger, IWebRequest gracefulClient, IDataOceanClient dataOceanClient)
        {
            Log = logger.CreateLogger <PegasusClient>();
            this.gracefulClient  = gracefulClient;
            this.dataOceanClient = dataOceanClient;

            pegasusBaseUrl = configuration.GetValueString(PEGASUS_URL_KEY);
            if (string.IsNullOrEmpty(pegasusBaseUrl))
            {
                throw new ArgumentException($"Missing environment variable {PEGASUS_URL_KEY}");
            }
            Log.LogInformation($"{PEGASUS_URL_KEY}={pegasusBaseUrl}");
            executionWaitInterval = configuration.GetValueInt(PEGASUS_EXECUTION_WAIT_MILLSECS_KEY, 1000);
            executionTimeout      = configuration.GetValueDouble(PEGASUS_EXECUTION_TIMEOUT_MINS_KEY, 5);
            maxZoomLevel          = configuration.GetValueInt("TILE_RENDER_MAX_ZOOM_LEVEL", 21);
            dxfProcedureId        = configuration.GetValueGuid(PEGASUS_DXF_PROCEDURE_ID_KEY);
            if (dxfProcedureId == Guid.Empty)
            {
                throw new ArgumentException($"Missing environment variable {PEGASUS_DXF_PROCEDURE_ID_KEY}");
            }
            geoTiffProcedureId = configuration.GetValueGuid(PEGASUS_GEOTIFF_PROCEDURE_ID_KEY);
            if (geoTiffProcedureId == Guid.Empty)
            {
                throw new ArgumentException($"Missing environment variable {PEGASUS_GEOTIFF_PROCEDURE_ID_KEY}");
            }
        }
Beispiel #3
0
 public void Initialise(ILogger logger, IConfigurationStore configStore,
                        IHeaderDictionary customHeaders, IDataOceanClient dataOceanClient,
                        ITPaaSApplicationAuthentication authn, IProductivity3dV2ProxyCompactionTile productivity3DProxyCompactionTile, IBoundingBoxHelper bboxHelper)
 {
     log = logger;
     this.configStore     = configStore;
     this.customHeaders   = customHeaders;
     this.dataOceanClient = dataOceanClient;
     this.authn           = authn;
     this.productivity3DProxyCompactionTile = productivity3DProxyCompactionTile;
     this.bboxHelper = bboxHelper;
 }
Beispiel #4
0
        /// <summary>
        /// Writes the importedFile to DataOcean as a create or update,
        ///       if it already exists, old version will be deleted first.
        /// </summary>
        public static async Task WriteFileToDataOcean(
            Stream fileContents, string rootFolder, string customerUid, string projectUid, string dataOceanFileName,
            ILogger log, IServiceExceptionHandler serviceExceptionHandler, IDataOceanClient dataOceanClient,
            ITPaaSApplicationAuthentication authn, Guid fileUid, IConfigurationStore configStore)
        {
            var dataOceanEnabled = configStore.GetValueBool("ENABLE_DATA_OCEAN", false);

            if (dataOceanEnabled)
            {
                if (!dataOceanFileName.StartsWith(fileUid.ToString()))
                {
                    throw new ServiceException(HttpStatusCode.InternalServerError,
                                               new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError,
                                                                           $"Invalid DataOcean file name {dataOceanFileName}"));
                }

                var customHeaders = authn.CustomHeaders();
                var dataOceanPath = DataOceanFileUtil.DataOceanPath(rootFolder, customerUid, projectUid);

                var ccPutFileResult     = false;
                var folderAlreadyExists = false;

                try
                {
                    log.LogInformation($"{nameof(WriteFileToDataOcean)}: dataOceanPath: '{dataOceanPath}', dataOceanFileName: '{dataOceanFileName}'");

                    folderAlreadyExists = await dataOceanClient.FolderExists(dataOceanPath, customHeaders);

                    if (!folderAlreadyExists)
                    {
                        await dataOceanClient.MakeFolder(dataOceanPath, customHeaders);
                    }

                    ccPutFileResult = await dataOceanClient.PutFile(dataOceanPath, dataOceanFileName, fileContents, customHeaders);
                }
                catch (Exception e)
                {
                    serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 57, "dataOceanClient.PutFile",
                                                                  e.Message);
                }

                if (!ccPutFileResult)
                {
                    serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 116);
                }

                log.LogInformation($"{nameof(WriteFileToDataOcean)}: dataOceanFileName '{dataOceanFileName}' written to DataOcean, folderAlreadyExists: {folderAlreadyExists}");
            }
            else
            {
                log.LogInformation($"{nameof(WriteFileToDataOcean)}: File not saved. DataOcean disabled");
            }
        }
Beispiel #5
0
        public DxfTileService(IConfigurationStore configuration, IDataOceanClient dataOceanClient, ILoggerFactory logger, ITPaaSApplicationAuthentication authn)
        {
            config = configuration;
            this.dataOceanClient = dataOceanClient;
            log        = logger.CreateLogger <DxfTileService>();
            this.authn = authn;

            const string DATA_OCEAN_ROOT_FOLDER_ID_KEY = "DATA_OCEAN_ROOT_FOLDER_ID";

            dataOceanRootFolder = configuration.GetValueString(DATA_OCEAN_ROOT_FOLDER_ID_KEY);
            if (string.IsNullOrEmpty(dataOceanRootFolder))
            {
                throw new ArgumentException($"Missing environment variable {DATA_OCEAN_ROOT_FOLDER_ID_KEY}");
            }
        }
Beispiel #6
0
        /// <summary>
        /// Deletes the importedFile from DataOcean
        /// </summary>
        public static async Task <ImportedFileInternalResult> DeleteFileFromDataOcean(
            string fileName, string rootFolder, string customerUid, Guid projectUid, Guid importedFileUid,
            ILogger log, IDataOceanClient dataOceanClient, ITPaaSApplicationAuthentication authn, IConfigurationStore configStore)
        {
            var dataOceanEnabled = configStore.GetValueBool("ENABLE_DATA_OCEAN", false);

            if (dataOceanEnabled)
            {
                var dataOceanPath = DataOceanFileUtil.DataOceanPath(rootFolder, customerUid, projectUid.ToString());
                var fullFileName  = $"{dataOceanPath}{Path.DirectorySeparatorChar}{fileName}";
                log.LogInformation($"{nameof(DeleteFileFromDataOcean)}: fullFileName {JsonConvert.SerializeObject(fullFileName)}");

                var  customHeaders = authn.CustomHeaders();
                bool ccDeleteFileResult;

                try
                {
                    ccDeleteFileResult = await dataOceanClient.DeleteFile(fullFileName, customHeaders);
                }
                catch (Exception e)
                {
                    log.LogError(e, $"{nameof(DeleteFileFromDataOcean)}: failed for {fileName} (importedFileUid:{importedFileUid}) with exception {e.Message}");
                    return(ImportedFileInternalResult.CreateImportedFileInternalResult(HttpStatusCode.InternalServerError, 57, "dataOceanClient.DeleteFile", e.Message));
                }

                if (!ccDeleteFileResult)
                {
                    log.LogWarning(
                        $"{nameof(DeleteFileFromDataOcean)}: failed to delete {fileName} (importedFileUid:{importedFileUid}).");
                    //Not an error if it doesn't delete the file?
                    //return ImportedFileInternalResult.CreateImportedFileInternalResult(HttpStatusCode.InternalServerError, 117);
                }
            }
            else
            {
                log.LogInformation($"{nameof(DeleteFileFromDataOcean)}: File not deleted. DataOcean disabled");
            }

            return(null);
        }
Beispiel #7
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;
 }
Beispiel #8
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);
        }
Beispiel #9
0
        /// <summary>
        /// Builds this instance for specified executor type.
        /// </summary>
        /// <typeparam name="TExecutor">The type of the executor.</typeparam>
        /// <typeparam name="TLog">The type of the logger.</typeparam>
        public static TExecutor Build <TExecutor, TLog>(ILogger <TLog> logger, IConfigurationStore configStore = null,
                                                        IHeaderDictionary customHeaders       = null, IDataOceanClient dataOceanClient = null,
                                                        ITPaaSApplicationAuthentication authn = null, IProductivity3dV2ProxyCompactionTile productivity3DProxyCompactionTile = null, IBoundingBoxHelper bboxHelper = null)
            where TExecutor : RequestExecutorContainer, new()
        {
            ILogger log      = logger;
            var     executor = new TExecutor();

            executor.Initialise(
                log,
                configStore,
                customHeaders,
                dataOceanClient,
                authn,
                productivity3DProxyCompactionTile,
                bboxHelper);

            return(executor);
        }