Pull Request 33523 suggestions
Pull Request 33520 suggestions Injected AppSettings instead of using GetEnvironmentVariable at Services level When debugging only app.Services.GetRequiredService<IPCRBService>(); Get ready to use VSCode IDE Align .editorconfig files
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
using System.Text;
|
||||
|
||||
using System.Text;
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -63,4 +63,4 @@ public class ApprovalService : IApprovalService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
using System.Text;
|
||||
|
||||
using System.Text;
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -106,4 +106,4 @@ public class CorrectiveActionService : ICorrectiveActionService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using Dapper;
|
||||
using System.Data;
|
||||
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -28,7 +28,7 @@ public class DalService : IDalService {
|
||||
|
||||
int remainingRetries = RETRIES;
|
||||
bool queryWasSuccessful = false;
|
||||
Exception exception = null;
|
||||
Exception? exception = null;
|
||||
IEnumerable<T> result = new List<T>();
|
||||
while (!queryWasSuccessful && remainingRetries > 0) {
|
||||
int backoffSeconds = (RETRIES - remainingRetries--) * BACKOFF_SECONDS_INTERVAL;
|
||||
@ -60,7 +60,7 @@ public class DalService : IDalService {
|
||||
|
||||
int remainingRetries = RETRIES;
|
||||
bool queryWasSuccessful = false;
|
||||
Exception exception = null;
|
||||
Exception? exception = null;
|
||||
int rowsAffected = 0;
|
||||
while (!queryWasSuccessful && remainingRetries > 0) {
|
||||
int backoffSeconds = (RETRIES - remainingRetries--) * BACKOFF_SECONDS_INTERVAL;
|
||||
@ -86,4 +86,4 @@ public class DalService : IDalService {
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.Data;
|
||||
|
||||
using System.Data;
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -10,17 +11,13 @@ public interface IDbConnectionService {
|
||||
}
|
||||
|
||||
public class DbConnectionService : IDbConnectionService {
|
||||
private readonly string _envName;
|
||||
private readonly string _dbConnectionString;
|
||||
|
||||
public DbConnectionService() {
|
||||
_envName = Environment.GetEnvironmentVariable("FabApprovalEnvironmentName") ??
|
||||
throw new ArgumentNullException("FabApprovalEnvironmentName environment variable not found");
|
||||
_dbConnectionString = Environment.GetEnvironmentVariable("FabApprovalDbConnectionString") ??
|
||||
throw new ArgumentNullException("FabApprovalDbConnectionString environment variable not found");
|
||||
public DbConnectionService(AppSettings appSettings) {
|
||||
_dbConnectionString = appSettings.DbConnectionString;
|
||||
}
|
||||
|
||||
public IDbConnection GetConnection() {
|
||||
return new SqlConnection(_dbConnectionString);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
using System.Text;
|
||||
|
||||
using System.Text;
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -185,4 +185,4 @@ public class ECNService : IECNService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
using System.Text;
|
||||
|
||||
using System.Text;
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -56,4 +56,4 @@ public class MRBService : IMRBService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using Infineon.Monitoring.MonA;
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using Infineon.Monitoring.MonA;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -13,13 +15,11 @@ public class MonInClient : IMonInClient {
|
||||
private readonly string _site;
|
||||
private readonly string _resource;
|
||||
|
||||
public MonInClient(ILogger<MonInClient> logger) {
|
||||
public MonInClient(ILogger<MonInClient> logger, AppSettings appSettings) {
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
_site = Environment.GetEnvironmentVariable("MonInSite") ??
|
||||
throw new ArgumentNullException("MonInSite environment variable not found");
|
||||
_resource = Environment.GetEnvironmentVariable("FabApprovalWorkerServiceMonInResource") ??
|
||||
throw new ArgumentNullException("FabApprovalWorkerServiceMonInResource environment variable not found");
|
||||
_site = appSettings.MonInSite;
|
||||
_resource = appSettings.WorkerServiceMonInResource;
|
||||
}
|
||||
|
||||
public void PostMetric(string metricName, double metricValue) {
|
||||
@ -55,4 +55,4 @@ public class MonInClient : IMonInClient {
|
||||
ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
using System.Text;
|
||||
|
||||
using System.Text;
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
@ -57,4 +57,4 @@ public class PCRBService : IPCRBService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
using FabApprovalWorkerService.Clients;
|
||||
using System.Net.Mail;
|
||||
|
||||
using FabApprovalWorkerService.Clients;
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface ISmtpService {
|
||||
@ -15,13 +16,19 @@ public class SmtpService : ISmtpService {
|
||||
private ISmtpClientWrapper _smtpClient;
|
||||
private bool _shouldSendEmail;
|
||||
|
||||
public SmtpService(ILogger<SmtpService> logger, ISmtpClientWrapper smtpClient) {
|
||||
public SmtpService(ILogger<SmtpService> logger,
|
||||
ISmtpClientWrapper smtpClient,
|
||||
AppSettings? appSettings = null) {
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
_smtpClient = smtpClient ??
|
||||
throw new ArgumentNullException("SmtpClient not injected");
|
||||
if (!Boolean.TryParse(Environment.GetEnvironmentVariable("FabApprovalShouldSendEmail"), out _shouldSendEmail))
|
||||
throw new ArgumentNullException("FabApprovalShouldSendEmail environment variable not found");
|
||||
if (appSettings is not null)
|
||||
_shouldSendEmail = appSettings.ShouldSendEmail;
|
||||
else {
|
||||
if (!bool.TryParse(Environment.GetEnvironmentVariable("FabApprovalShouldSendEmail"), out _shouldSendEmail))
|
||||
throw new ArgumentNullException("FabApprovalShouldSendEmail environment variable not found");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> SendEmail(IEnumerable<MailAddress> recipients,
|
||||
@ -32,7 +39,7 @@ public class SmtpService : ISmtpService {
|
||||
if (ccRecipients is null) throw new ArgumentNullException("ccRecipients cannot be null!");
|
||||
if (subject.IsNullOrEmpty()) throw new ArgumentNullException("subject cannot be null or empty!");
|
||||
if (body.IsNullOrEmpty()) throw new ArgumentNullException("body cannot be null or empty!");
|
||||
|
||||
|
||||
return await Task.Run(() => {
|
||||
int maxRetries = 3;
|
||||
int backoffSeconds = 30;
|
||||
@ -76,4 +83,4 @@ public class SmtpService : ISmtpService {
|
||||
return messageWasSent;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface ITrainingService {
|
||||
@ -30,20 +30,25 @@ public class TrainingService : ITrainingService {
|
||||
|
||||
private readonly string _userCertRecordsFilePath;
|
||||
|
||||
public TrainingService(ILogger<TrainingService> logger, IDalService dalService, IUserService userService) {
|
||||
public TrainingService(ILogger<TrainingService> logger,
|
||||
IDalService dalService,
|
||||
IUserService userService,
|
||||
AppSettings? appSettings = null) {
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ??
|
||||
throw new ArgumentNullException("IDalService not injected");
|
||||
_userService = userService ??
|
||||
throw new ArgumentNullException("IUserService not injected");
|
||||
_userCertRecordsFilePath = Environment.GetEnvironmentVariable("UserCertificationRecordsFilePath") ??
|
||||
throw new ArgumentNullException("UserCertificationRecordsFilePath environment variable not found");
|
||||
_userCertRecordsFilePath = appSettings is not null
|
||||
? appSettings.UserCertificationRecordsFilePath
|
||||
: Environment.GetEnvironmentVariable("UserCertificationRecordsFilePath") ??
|
||||
throw new ArgumentNullException("UserCertificationRecordsFilePath environment variable not found");
|
||||
}
|
||||
|
||||
public async Task DeleteDocAssignment(int trainingAssignmentId) {
|
||||
if (trainingAssignmentId <= 0) throw new ArgumentException($"Invalid training assignment id: {trainingAssignmentId}");
|
||||
|
||||
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to delete training doc assignments for training assignment {trainingAssignmentId}");
|
||||
|
||||
@ -84,7 +89,7 @@ public class TrainingService : ITrainingService {
|
||||
}
|
||||
|
||||
public async Task DeleteTrainingAssignmentById(int trainingAssignmentId) {
|
||||
if (trainingAssignmentId <= 0)
|
||||
if (trainingAssignmentId <= 0)
|
||||
throw new ArgumentException($"Invalid training assignment id: {trainingAssignmentId}");
|
||||
|
||||
try {
|
||||
@ -341,4 +346,4 @@ public class TrainingService : ITrainingService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using System.Text;
|
||||
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface IUserService {
|
||||
@ -417,4 +417,4 @@ public class UserService : IUserService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -39,4 +39,4 @@ public class WindowsService : BackgroundService {
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user