MRB webassembly
This commit is contained in:
16
MesaFabApproval.Shared/MesaFabApproval.Shared.csproj
Normal file
16
MesaFabApproval.Shared/MesaFabApproval.Shared.csproj
Normal file
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
20
MesaFabApproval.Shared/Models/Approval.cs
Normal file
20
MesaFabApproval.Shared/Models/Approval.cs
Normal file
@ -0,0 +1,20 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class Approval {
|
||||
public int ApprovalID { get; set; }
|
||||
public required int IssueID { get; set; }
|
||||
public required string RoleName { get; set; }
|
||||
public required string SubRole { get; set; }
|
||||
public required int UserID { get; set; }
|
||||
public User? User { get; set; }
|
||||
public required int SubRoleID { get; set; }
|
||||
public int ItemStatus { get; set; } = 0;
|
||||
public string StatusMessage = "Assigned";
|
||||
public DateTime NotifyDate { get; set; } = DateTime.MinValue;
|
||||
public required DateTime AssignedDate { get; set; }
|
||||
public DateTime CompletedDate { get; set; } = DateTime.MaxValue;
|
||||
public string Comments { get; set; } = "";
|
||||
public int Step { get; set; } = 1;
|
||||
public string SubRoleCategoryItem { get; set; } = "";
|
||||
public int TaskID { get; set; }
|
||||
}
|
7
MesaFabApproval.Shared/Models/AuthAttempt.cs
Normal file
7
MesaFabApproval.Shared/Models/AuthAttempt.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class AuthAttempt {
|
||||
public required string LoginID { get; set; }
|
||||
public string Password { get; set; } = "";
|
||||
public AuthTokens? AuthTokens { get; set; }
|
||||
}
|
6
MesaFabApproval.Shared/Models/AuthTokens.cs
Normal file
6
MesaFabApproval.Shared/Models/AuthTokens.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class AuthTokens {
|
||||
public required string JwtToken { get; set; }
|
||||
public required string RefreshToken { get; set; }
|
||||
}
|
7
MesaFabApproval.Shared/Models/LoginResult.cs
Normal file
7
MesaFabApproval.Shared/Models/LoginResult.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class LoginResult {
|
||||
public required bool IsAuthenticated { get; set; }
|
||||
public required User User { get; set; }
|
||||
public required AuthTokens AuthTokens { get; set; }
|
||||
}
|
42
MesaFabApproval.Shared/Models/MRB.cs
Normal file
42
MesaFabApproval.Shared/Models/MRB.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class MRB {
|
||||
public static string[] Stages { get; } = {
|
||||
"Draft",
|
||||
"QA Pre Approval",
|
||||
"Pending Approval",
|
||||
"Approved",
|
||||
"Complete"
|
||||
};
|
||||
|
||||
public int MRBNumber { get; set; }
|
||||
public int OriginatorID { get; set; }
|
||||
public string OriginatorName { get; set; } = "";
|
||||
public string Title { get; set; } = "";
|
||||
public DateTime SubmittedDate { get; set; } = DateTime.MinValue;
|
||||
public DateTime CloseDate { get; set; } = DateTime.MaxValue;
|
||||
public DateTime CancelDate { get; set; } = DateTime.MaxValue;
|
||||
public DateTime ApprovalDate { get; set; } = DateTime.MaxValue;
|
||||
public string IssueDescription { get; set; } = "";
|
||||
public int NumberOfLotsAffected { get; set; }
|
||||
public string Val { get; set; } = "";
|
||||
public bool CustomerImpacted { get; set; } = false;
|
||||
public string Department { get; set; } = "";
|
||||
public string Process { get; set; } = "";
|
||||
public int RMANo { get; set; }
|
||||
public int PCRBNo { get; set; }
|
||||
public bool SpecsImpacted { get; set; } = false;
|
||||
public bool TrainingRequired { get; set; } = false;
|
||||
public IEnumerable<MRBAttachment>? Attachments { get; set; }
|
||||
public IEnumerable<MRBAction>? Actions { get; set; }
|
||||
public IEnumerable<int>? ApproverUserIds { get; set; }
|
||||
public required int StageNo { get; set; }
|
||||
public required string Status { get; set; }
|
||||
|
||||
public sealed class StageApprovalData {
|
||||
public required string RoleName { get; set; }
|
||||
public required string SubRoleName { get; set; }
|
||||
}
|
||||
}
|
15
MesaFabApproval.Shared/Models/MRBAction.cs
Normal file
15
MesaFabApproval.Shared/Models/MRBAction.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class MRBAction {
|
||||
public int ActionID { get; set; }
|
||||
public required string Action { get; set; }
|
||||
public required string Customer { get; set; }
|
||||
public required int Quantity { get; set; }
|
||||
public required string PartNumber { get; set; }
|
||||
public required string LotNumber { get; set; }
|
||||
public required int MRBNumber { get; set; }
|
||||
public DateTime AssignedDate { get; set; } = DateTime.MinValue;
|
||||
public DateTime CompletedDate { get; set; } = DateTime.MaxValue;
|
||||
public int CompletedByUserID { get; set; } = 0;
|
||||
public User? CompletedByUser { get; set; }
|
||||
}
|
13
MesaFabApproval.Shared/Models/MRBAttachment.cs
Normal file
13
MesaFabApproval.Shared/Models/MRBAttachment.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class MRBAttachment {
|
||||
public int AttachmentID { get; set; }
|
||||
public required int MRBNumber { get; set; }
|
||||
public required string FileName { get; set; }
|
||||
public required int UserID { get; set; }
|
||||
public required DateTime UploadDate { get; set; }
|
||||
public string? Path { get; set; }
|
||||
public IBrowserFile? File { get; set; }
|
||||
}
|
6
MesaFabApproval.Shared/Models/MRBNotification.cs
Normal file
6
MesaFabApproval.Shared/Models/MRBNotification.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class MRBNotification {
|
||||
public required string Message { get; set; }
|
||||
public required MRB MRB { get; set; }
|
||||
}
|
8
MesaFabApproval.Shared/Models/MonInMetricRequest.cs
Normal file
8
MesaFabApproval.Shared/Models/MonInMetricRequest.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class MonInMetricRequest {
|
||||
public required string resource { get; set; }
|
||||
public required DateTime dateTime { get; set; }
|
||||
public required string metricName { get; set; }
|
||||
public required double metricValue { get; set; }
|
||||
}
|
8
MesaFabApproval.Shared/Models/RawMonInStatusRequest.cs
Normal file
8
MesaFabApproval.Shared/Models/RawMonInStatusRequest.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class RawMonInStatusRequest {
|
||||
public required string resource { get; set; }
|
||||
public required DateTime dateTime { get; set; }
|
||||
public required string statusName { get; set; }
|
||||
public required string statusValue { get; set; }
|
||||
}
|
11
MesaFabApproval.Shared/Models/Role.cs
Normal file
11
MesaFabApproval.Shared/Models/Role.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class Role {
|
||||
private string Value { get; set; }
|
||||
|
||||
private Role(string value) { this.Value = value; }
|
||||
|
||||
public static Role MRB_APPROVER { get { return new Role("MRB Approver"); } }
|
||||
|
||||
public override string ToString() => Value;
|
||||
}
|
10
MesaFabApproval.Shared/Models/StatusValue.cs
Normal file
10
MesaFabApproval.Shared/Models/StatusValue.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public enum StatusValue {
|
||||
Up,
|
||||
Ok,
|
||||
Warning,
|
||||
Critical,
|
||||
Down,
|
||||
Unknown
|
||||
}
|
13
MesaFabApproval.Shared/Models/SubRole.cs
Normal file
13
MesaFabApproval.Shared/Models/SubRole.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class SubRole {
|
||||
public int SubRoleID { get; set; }
|
||||
public required string SubRoleName { get; set; }
|
||||
public required int SubRoleCategoryID { get; set; }
|
||||
public required string SubRoleCategoryItem { get; set; }
|
||||
}
|
7
MesaFabApproval.Shared/Models/UploadResult.cs
Normal file
7
MesaFabApproval.Shared/Models/UploadResult.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class UploadResult {
|
||||
public required bool UploadSuccessful { get; set; }
|
||||
public string? FileName { get; set; }
|
||||
public string? Error { get; set; }
|
||||
}
|
20
MesaFabApproval.Shared/Models/User.cs
Normal file
20
MesaFabApproval.Shared/Models/User.cs
Normal file
@ -0,0 +1,20 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class User {
|
||||
public required int UserID { get; set; }
|
||||
public required string LoginID { get; set; }
|
||||
public required string FirstName { get; set; }
|
||||
public required string LastName { get; set; }
|
||||
public required string Email { get; set; }
|
||||
public bool IsAdmin { get; set; } = false;
|
||||
public bool IsManager { get; set; } = false;
|
||||
public bool IsActive { get; set; } = false;
|
||||
public bool OOO { get; set; } = false;
|
||||
public DateTime OOOStartDate { get; set; }
|
||||
public DateTime OOOExpirationDate { get; set; }
|
||||
public int DelegatedTo { get; set; }
|
||||
|
||||
public string GetFullName() {
|
||||
return $"{FirstName} {LastName}";
|
||||
}
|
||||
}
|
178
MesaFabApproval.Shared/Services/MonInWorkerClient.cs
Normal file
178
MesaFabApproval.Shared/Services/MonInWorkerClient.cs
Normal file
@ -0,0 +1,178 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
using MesaFabApproval.Shared.Models;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace MesaFabApproval.Shared.Services;
|
||||
|
||||
public interface IMonInWorkerClient {
|
||||
void PostAverage(string metricName, double metricValue);
|
||||
void PostCount(string metricName, double metricValue);
|
||||
void PostStatus(string statusName, StatusValue statusValue);
|
||||
}
|
||||
|
||||
public class MonInWorkerClient : IMonInWorkerClient {
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IConfiguration _config;
|
||||
private readonly ILogger<MonInWorkerClient> _logger;
|
||||
|
||||
private readonly string _baseUrl;
|
||||
private readonly int _retryLimit = -1;
|
||||
private readonly int _backoffInSeconds = -1;
|
||||
|
||||
private readonly string _resource;
|
||||
|
||||
public MonInWorkerClient(IHttpClientFactory httpClientFactory,
|
||||
IConfiguration config,
|
||||
ILogger<MonInWorkerClient> logger) {
|
||||
_httpClientFactory = httpClientFactory;
|
||||
if (_httpClientFactory is null) throw new ArgumentNullException("IHttpClientFactory not injected");
|
||||
|
||||
_config = config;
|
||||
if (_config is null) throw new ArgumentNullException("IConfiguration not injected");
|
||||
|
||||
_logger = logger;
|
||||
if (_logger is null) throw new ArgumentNullException("ILogger not injected");
|
||||
|
||||
_baseUrl = Environment.GetEnvironmentVariable("MonInWorkerUrl") ??
|
||||
throw new ArgumentNullException("MonInWorkerUrl environment variable not found");
|
||||
|
||||
string monInRetries = Environment.GetEnvironmentVariable("MonInRetries") ??
|
||||
throw new ArgumentNullException("MonInRetries environment variable not found");
|
||||
if (!Int32.TryParse(monInRetries, out _retryLimit))
|
||||
throw new ArgumentException("MonInReties environment variable not an integer");
|
||||
|
||||
string monInBackoffSeconds = Environment.GetEnvironmentVariable("MonInBackoffSeconds") ??
|
||||
throw new ArgumentNullException("MonInBackoffSeconds environment variable not found");
|
||||
if (!Int32.TryParse(monInBackoffSeconds, out _backoffInSeconds))
|
||||
throw new ArgumentException("MonInBackoffSeconds environment variable not an integer");
|
||||
|
||||
_resource = Environment.GetEnvironmentVariable("FabApprovalApiMonInResource") ??
|
||||
throw new ArgumentNullException("OIWizardMonInResource environment variable not found");
|
||||
}
|
||||
|
||||
public async void PostStatus(string statusName, StatusValue statusValue) {
|
||||
string url = _baseUrl + "status";
|
||||
|
||||
StringBuilder logBuilder = new();
|
||||
logBuilder.Append($"Attempting to send MonIn status request for resource {_resource} ");
|
||||
logBuilder.Append($"with name {statusName} and value {statusValue.ToString()} to url {url}");
|
||||
_logger.LogInformation(logBuilder.ToString());
|
||||
|
||||
try {
|
||||
bool success = false;
|
||||
int retries = _retryLimit;
|
||||
while (!success && retries > 0) {
|
||||
Task.Delay(TimeSpan.FromSeconds((_retryLimit - retries) * _backoffInSeconds)).Wait();
|
||||
|
||||
HttpClient httpClient = _httpClientFactory.CreateClient();
|
||||
|
||||
RawMonInStatusRequest statusRequest = new RawMonInStatusRequest() {
|
||||
resource = _resource,
|
||||
dateTime = DateTime.Now,
|
||||
statusName = statusName,
|
||||
statusValue = statusValue.ToString()
|
||||
};
|
||||
|
||||
StringContent statusRequestJson = new StringContent(JsonSerializer.Serialize(statusRequest),
|
||||
Encoding.UTF8,
|
||||
Application.Json);
|
||||
|
||||
using HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(url, statusRequestJson);
|
||||
|
||||
success = httpResponseMessage.IsSuccessStatusCode;
|
||||
retries--;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errLogBuilder = new();
|
||||
errLogBuilder.Append($"An exception occurred when attempting to send MonIn status request for resource {_resource} ");
|
||||
errLogBuilder.Append($"with name {statusName} and value {statusValue.ToString()} to url {url}. Exception: {ex.Message}");
|
||||
_logger.LogError(errLogBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async void PostCount(string metricName, double metricValue) {
|
||||
string url = _baseUrl + "count";
|
||||
|
||||
StringBuilder logMsgBuilder = new();
|
||||
logMsgBuilder.Append($"Attempting to send MonIn count request for resource {_resource} ");
|
||||
logMsgBuilder.Append($"with name {metricName} and value {metricValue} to url {url}");
|
||||
_logger.LogInformation(logMsgBuilder.ToString());
|
||||
|
||||
try {
|
||||
bool success = false;
|
||||
int retries = _retryLimit;
|
||||
while (!success && retries > 0) {
|
||||
Task.Delay(TimeSpan.FromSeconds((_retryLimit - retries) * _backoffInSeconds)).Wait();
|
||||
|
||||
HttpClient httpClient = _httpClientFactory.CreateClient();
|
||||
|
||||
MonInMetricRequest metricRequest = new MonInMetricRequest() {
|
||||
resource = _resource,
|
||||
dateTime = DateTime.Now,
|
||||
metricName = metricName,
|
||||
metricValue = metricValue
|
||||
};
|
||||
|
||||
StringContent metricRequestJson = new StringContent(JsonSerializer.Serialize(metricRequest),
|
||||
Encoding.UTF8,
|
||||
Application.Json);
|
||||
|
||||
using HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(url, metricRequestJson);
|
||||
|
||||
success = httpResponseMessage.IsSuccessStatusCode;
|
||||
retries--;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to send MonIn count request for resource {_resource} ");
|
||||
errMsgBuilder.Append($"with name {metricName} and value {metricValue} to url {url}. Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async void PostAverage(string metricName, double metricValue) {
|
||||
string url = _baseUrl + "average";
|
||||
|
||||
StringBuilder logMsgBuilder = new();
|
||||
logMsgBuilder.Append($"Attempting to send MonIn average request for resource {_resource} ");
|
||||
logMsgBuilder.Append($"with name {metricName} and value {metricValue} to url {url}");
|
||||
_logger.LogInformation(logMsgBuilder.ToString());
|
||||
|
||||
try {
|
||||
bool success = false;
|
||||
int retries = _retryLimit;
|
||||
while (!success && retries > 0) {
|
||||
Task.Delay(TimeSpan.FromSeconds((_retryLimit - retries) * _backoffInSeconds)).Wait();
|
||||
|
||||
HttpClient httpClient = _httpClientFactory.CreateClient();
|
||||
|
||||
MonInMetricRequest metricRequest = new MonInMetricRequest() {
|
||||
resource = _resource,
|
||||
dateTime = DateTime.Now,
|
||||
metricName = metricName,
|
||||
metricValue = metricValue
|
||||
};
|
||||
|
||||
StringContent metricRequestJson = new StringContent(JsonSerializer.Serialize(metricRequest),
|
||||
Encoding.UTF8,
|
||||
Application.Json);
|
||||
|
||||
using HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(url, metricRequestJson);
|
||||
|
||||
success = httpResponseMessage.IsSuccessStatusCode;
|
||||
retries--;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to send MonIn average request for resource {_resource} ");
|
||||
errMsgBuilder.Append($"with name {metricName} and value {metricValue} to url {url}. Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user