public async Task Execute()
        {
            _aggregateLogger.LogInformation("External Api Data Sync Function Started");
            _aggregateLogger.LogInformation($"Process Environment = {EnvironmentVariableTarget.Process}");

            if (_allowDataSync)
            {
                try
                {
                    _aggregateLogger.LogInformation("Proceeding with External Api Data Sync...");

                    using (var destinationSqlConnection = new SqlConnection(_destinationConnectionString))
                    {
                        if (!destinationSqlConnection.State.HasFlag(ConnectionState.Open))
                        {
                            destinationSqlConnection.Open();
                        }

                        using (var transaction = destinationSqlConnection.BeginTransaction())
                        {
                            Step0_TearDown_Database(transaction);
                            Step1_Organisation_Data(transaction);
                            Step2_Contacts_Data(transaction);
                            Step3_Standard_Data(transaction);
                            Step4_OrganisationStandard_Data(transaction);
                            Step5_Obfuscate_Personal_Data(transaction);
                            Step6_Generate_Test_Data(transaction);

                            transaction.Commit();
                        }
                    }

                    _aggregateLogger.LogInformation("External Api Data Sync completed");
                }
                catch (TransactionAbortedException ex)
                {
                    _aggregateLogger.LogError(ex, "Transaction was aborted during External Api Data Sync");
                }
                catch (SqlException ex)
                {
                    _aggregateLogger.LogError(ex, "SqlException occurred during External Api Data Sync");
                }
                catch (Exception ex)
                {
                    _aggregateLogger.LogError(ex, "Unknown Error occurred during External Api Data Sync");
                }
            }
            else
            {
                _aggregateLogger.LogInformation("External Api Data Sync is disabled at this time");
            }

            await Task.CompletedTask;
        }
Esempio n. 2
0
        public async Task Execute()
        {
            try
            {
                _aggregateLogger.LogInfo("Privately Funded Certificate Approval Notification Started");
                _aggregateLogger.LogInfo($"Process Environment = {EnvironmentVariableTarget.Process}");

                await _assessorServiceApi.UpdatePrivatelyFundedCertificateRequestsToBeApproved();

                var certificatesToBeApproved = await _assessorServiceApi.GetCertificatesToBeApproved();

                await _notificationService.Send(certificatesToBeApproved);
            }
            catch (Exception e)
            {
                _aggregateLogger.LogError("Function Errored", e);
                throw;
            }
        }
Esempio n. 3
0
        public async Task Execute()
        {
            try
            {
                _aggregateLogger.LogInfo("Function Started");

                var webConfig = ConfigurationHelper.GetConfiguration();

                _aggregateLogger.LogInfo("Config Received");

                var token = _tokenService.GetToken();

                _aggregateLogger.LogInfo("Token Received");

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
                    client.DefaultRequestHeaders.Add("accept", "application/json");

                    var response = await client.PostAsync($"{webConfig.ClientApiAuthentication.ApiBaseAddress}/api/v1/register-import", new StringContent(""));

                    var content = response.Content.ReadAsStringAsync().Result;

                    if (response.IsSuccessStatusCode)
                    {
                        _aggregateLogger.LogInfo($"Status code returned: {response.StatusCode}. Content: {content}");
                    }
                    else
                    {
                        _aggregateLogger.LogInfo($"Status code returned: {response.StatusCode}. Content: {content}");
                    }
                }
            }
            catch (Exception e)
            {
                _aggregateLogger.LogError("Function Errored", e);
                throw;
            }
        }
Esempio n. 4
0
        public async Task Execute()
        {
            try
            {
                _aggregateLogger.LogInfo("Function Started");
                _aggregateLogger.LogInfo("Print Function Flow Started");

                _aggregateLogger.LogInfo("Accessing Environment variables");
                var customSetting =
                    Environment.GetEnvironmentVariable("CustomSetting", EnvironmentVariableTarget.Process);
                _aggregateLogger.LogInfo($"Process Environment = {EnvironmentVariableTarget.Process}");

                if (await AnythingToProcess())
                {
                    var batchNumber = await _certificatesRepository.GenerateBatchNumber();

                    var certificates = (await _certificatesRepository.GetCertificatesToBePrinted()).ToList();

                    await _coverLetterService.Create(batchNumber, certificates);

                    await _ifaCertificateService.Create(batchNumber, certificates);

                    await _notificationService.Send();

                    await _certificatesRepository.ChangeStatusToPrinted(batchNumber.ToString(), certificates);
                }
                else
                {
                    _aggregateLogger.LogInfo("Nothing to Process");
                }
            }
            catch (Exception e)
            {
                _aggregateLogger.LogError("Function Errored", e);
                throw;
            }
        }
Esempio n. 5
0
        private async Task UploadCertificateDetailsToPinter()
        {
            try
            {
                _aggregateLogger.LogInfo("Print Process Function Started");

                var scheduleRun = await _assessorServiceApi.GetSchedule(ScheduleType.PrintRun);

                if (scheduleRun == null)
                {
                    _aggregateLogger.LogInfo("Print Function not scheduled to run at this time.");
                    return;
                }

                var batchLogResponse = await _assessorServiceApi.GetCurrentBatchLog();

                var batchNumber  = batchLogResponse.BatchNumber + 1;
                var certificates = (await _assessorServiceApi.GetCertificatesToBePrinted()).ToList()
                                   .Sanitise(_aggregateLogger);

                if (certificates.Count == 0)
                {
                    _aggregateLogger.LogInfo("No certificates to process");
                }
                else
                {
                    var certificateFileName =
                        $"IFA-Certificate-{DateTime.UtcNow.UtcToTimeZoneTime():MMyy}-{batchNumber.ToString().PadLeft(3, '0')}.json";
                    var excelFileName = $"IFA-Certificate-{DateTime.UtcNow.UtcToTimeZoneTime()}-{batchNumber.ToString().PadLeft(3, '0')}.xlsx";

                    var batchLogRequest = new CreateBatchLogRequest
                    {
                        BatchNumber         = batchNumber,
                        FileUploadStartTime = DateTime.UtcNow,
                        Period               = DateTime.UtcNow.UtcToTimeZoneTime().ToString("MMyy"),
                        BatchCreated         = DateTime.UtcNow,
                        CertificatesFileName = certificateFileName
                    };

                    var configuration = _configurationWrapper.GetConfiguration();

                    if (configuration.Sftp.UseJson)
                    {
                        _printingJsonCreator.Create(batchNumber, certificates, certificateFileName);
                        await _notificationService.Send(batchNumber, certificates, certificateFileName);
                    }
                    else
                    {
                        _printingSpreadsheetCreator.Create(batchNumber, certificates);
                        await _notificationService.Send(batchNumber, certificates, excelFileName);
                    }

                    batchLogRequest.FileUploadEndTime    = DateTime.UtcNow;
                    batchLogRequest.NumberOfCertificates = certificates.Count;
                    batchLogRequest.NumberOfCoverLetters = 0;
                    batchLogRequest.ScheduledDate        = batchLogResponse.ScheduledDate;

                    await _fileTransferClient.LogUploadDirectory();

                    await _assessorServiceApi.CreateBatchLog(batchLogRequest);

                    await _assessorServiceApi.ChangeStatusToPrinted(batchNumber, certificates);
                }
                await _assessorServiceApi.CompleteSchedule(scheduleRun.Id);
            }
            catch (Exception e)
            {
                _aggregateLogger.LogError("Function Errored", e);
                throw;
            }
        }