Exemplo n.º 1
0
        public async Task Run([TimerTrigger("%SFTPScheduleTriggerTime%")] TimerInfo myTimer, ExecutionContext context)
        {
            try
            {
                _log.Info($"File transfer from SFTP to Blob started at {DateTime.Now}");

                await _processor.SaveCSVToBlobAsync(context);

                _log.Info($"File transfer from SFTP to Blob completed at {DateTime.Now}");
            }
            catch (Exception exception)
            {
                try
                {
                    await _dqtFileTransferService.AddDQTFileTransferDetails(DateTime.Now, DQTFileTransferStatus.Failure, exception.Message);
                }
                catch (Exception e)
                {
                    _log.Error(new Exception($"Failed to insert the last run error details", e));
                }

                _log.Error(new Exception($"File transfer from SFTP to blob failed at {DateTime.Now}", exception));

                throw exception;
            }
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "qualified-teachers/qualified-teaching-status")] HttpRequest req)
        {
            string requestReference = req.Headers["x-correlation-id"];

            if (string.IsNullOrWhiteSpace(requestReference))
            {
                requestReference = Guid.NewGuid().ToString();
            }

            _log.Info($"Received request. CorrelationId : {requestReference}");

            if (!_authorize.AuthorizeRequest(req))
            {
                _log.Warning($"Unauthorized request. CorrelationId : {requestReference}");
                return(new UnauthorizedResult());
            }

            try
            {
                var trn = req.Query["trn"];
                var ni  = req.Query["ni"];

                if (string.IsNullOrWhiteSpace(trn))
                {
                    var msg = $"TeacherReferenceNumber is mandatory.";
                    _log.Info($"{msg} CorrelationId : {requestReference}");
                    return(new BadRequestObjectResult(GetResultDto(null, msg)));
                }

                _log.Info($"Fetching records. CorrelationId : {requestReference}");

                var results = await _qtsService.GetQualifiedTeacherRecords(trn, ni);

                if (!results.Any())
                {
                    var msg = $"No records found.";
                    _log.Info($"{msg} CorrelationId : {requestReference}");
                    return(new NotFoundObjectResult(GetResultDto(null, msg)));
                }

                return(new OkObjectResult(GetResultDto(results.ToList())));
            }
            catch (JsonException jsonException)
            {
                var errorMsg = $"Error retrieving qualified teacher status data.";
                _log.Error(new JsonException($"{errorMsg} CorrelationId : {requestReference}", jsonException));
                return(new BadRequestObjectResult(GetResultDto(null, errorMsg)));
            }
            catch (Exception exception)
            {
                var errorMsg = $"Error retrieving qualified teacher status data. {exception.Message}";
                _log.Error(new Exception($"{errorMsg} CorrelationId : {requestReference}", exception));
                return(new ObjectResult(GetResultDto(null, errorMsg))
                {
                    StatusCode = 500
                });
            }
Exemplo n.º 3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "qualified-teachers/dqt-file-transfer-status")] HttpRequest req)
        {
            if (!_authorize.AuthorizeRequest(req))
            {
                _log.Warning($"Unauthorized request");

                return(new UnauthorizedResult());
            }

            try
            {
                var result = await _dqtFileTransferService.GetDQTFileTransferServiceStatus();

                if (result == null)
                {
                    return(new NotFoundObjectResult("No file transfer record(s) found"));
                }

                return(new OkObjectResult(GetResultDto(result)));
            }
            catch (Exception exception)
            {
                _log.Error(exception);

                return(new ObjectResult(GetResultDto(null, exception.Message))
                {
                    StatusCode = 500
                });
            }
Exemplo n.º 4
0
        public async Task Run([BlobTrigger("dqt-cont/{name}", Connection = "AzureWebJobsStorage")] Stream csvBlob, string name)
        {
            try
            {
                log.Info($"Started processing DQT data from Blob 'dqt-cont'. \n Name:{name} \n Size: {csvBlob.Length} Bytes");

                await csvProcessor.SaveCSVDataToDatabase(csvBlob, name);

                await dqtFileTransferService.AddDQTFileTransferDetails(DateTime.Now, DQTFileTransferStatus.Success, string.Empty);

                log.Info($"Finished processing DQT data from Blob 'dqt-cont'. \n Name:{name} \n Size: {csvBlob.Length} Bytes");
            }
            catch (Exception ex)
            {
                await dqtFileTransferService.AddDQTFileTransferDetails(DateTime.Now, DQTFileTransferStatus.Failure, ex.Message);

                var msg = $"Error processing DQT data from Blob 'dqt-cont'. \n Name:{name} \n Size: {csvBlob.Length} Bytes";
                log.Error(new Exception(msg, ex));

                throw ex;
            }
        }