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.8" />
|
||||
<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>
|
22
MesaFabApproval.Shared/Models/Approval.cs
Normal file
22
MesaFabApproval.Shared/Models/Approval.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using MesaFabApproval.Shared.Utilities;
|
||||
|
||||
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; } = DateTimeUtilities.MIN_DT;
|
||||
public required DateTime AssignedDate { get; set; }
|
||||
public DateTime CompletedDate { get; set; } = DateTimeUtilities.MAX_DT;
|
||||
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; }
|
||||
}
|
46
MesaFabApproval.Shared/Models/MRB.cs
Normal file
46
MesaFabApproval.Shared/Models/MRB.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using MesaFabApproval.Shared.Utilities;
|
||||
|
||||
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; } = DateTimeUtilities.MIN_DT;
|
||||
public DateTime CloseDate { get; set; } = DateTimeUtilities.MAX_DT;
|
||||
public DateTime CancelDate { get; set; } = DateTimeUtilities.MAX_DT;
|
||||
public DateTime ApprovalDate { get; set; } = DateTimeUtilities.MAX_DT;
|
||||
public string IssueDescription { get; set; } = "";
|
||||
public int NumberOfLotsAffected { get; set; }
|
||||
public int Val { get; set; }
|
||||
public bool CustomerImpacted { get; set; } = false;
|
||||
public string CustomerImpactedName { get; set; } = "";
|
||||
public string Department { get; set; } = "";
|
||||
public string Process { get; set; } = "";
|
||||
public int RMANo { get; set; }
|
||||
public string PCRBNo { get; set; } = "";
|
||||
public bool SpecsImpacted { get; set; } = false;
|
||||
public int ProcessECNNumber { get; set; }
|
||||
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 string Tool { get; set; } = "";
|
||||
public string Category { get; set; } = string.Empty;
|
||||
|
||||
public sealed class StageApprovalData {
|
||||
public required string RoleName { get; set; }
|
||||
public required string SubRoleName { get; set; }
|
||||
}
|
||||
}
|
20
MesaFabApproval.Shared/Models/MRBAction.cs
Normal file
20
MesaFabApproval.Shared/Models/MRBAction.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using MesaFabApproval.Shared.Utilities;
|
||||
|
||||
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; } = DateTimeUtilities.MIN_DT;
|
||||
public DateTime CompletedDate { get; set; } = DateTimeUtilities.MAX_DT;
|
||||
public int CompletedByUserID { get; set; } = 0;
|
||||
public User? CompletedByUser { get; set; }
|
||||
public string ConvertFrom { get; set; } = "";
|
||||
public string ConvertTo { get; set; } = "";
|
||||
public string Justification { get; set; } = "";
|
||||
}
|
9
MesaFabApproval.Shared/Models/MRBActionAttachment.cs
Normal file
9
MesaFabApproval.Shared/Models/MRBActionAttachment.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class MRBActionAttachment {
|
||||
public required int AttachmentID { get; set; }
|
||||
public required int ActionID { get; set; }
|
||||
public required string FileName { get; set; }
|
||||
public required DateTime UploadDate { get; set; }
|
||||
public required string Path { 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; }
|
||||
}
|
27
MesaFabApproval.Shared/Models/PCRB.cs
Normal file
27
MesaFabApproval.Shared/Models/PCRB.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using MesaFabApproval.Shared.Utilities;
|
||||
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class PCRB {
|
||||
public static string[] Stages { get; } = {
|
||||
"Draft",
|
||||
"QA Pre Approval",
|
||||
"PCR1",
|
||||
"PCR2",
|
||||
"PCR3",
|
||||
"Complete"
|
||||
};
|
||||
|
||||
public int PlanNumber { get; set; }
|
||||
public int OwnerID { get; set; }
|
||||
public string OwnerName { get; set; } = "";
|
||||
public string Title { get; set; } = "";
|
||||
public string ChangeLevel { get; set; } = "Mesa";
|
||||
public bool IsITAR { get; set; } = false;
|
||||
public int CurrentStep { get; set; } = 0;
|
||||
public string ReasonForChange { get; set; } = "";
|
||||
public string ChangeDescription { get; set; } = "";
|
||||
public DateTime InsertTimeStamp { get; set; } = DateTimeUtilities.MIN_DT;
|
||||
public DateTime LastUpdateDate { get; set; } = DateTimeUtilities.MIN_DT;
|
||||
public DateTime ClosedDate { get; set; } = DateTimeUtilities.MAX_DT;
|
||||
}
|
56
MesaFabApproval.Shared/Models/Process.cs
Normal file
56
MesaFabApproval.Shared/Models/Process.cs
Normal file
@ -0,0 +1,56 @@
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class Process {
|
||||
public required string Name { get; set; } = "";
|
||||
|
||||
private static readonly Process Receiving = new Process { Name="Receiving" };
|
||||
private static readonly Process Kitting = new Process { Name = "Kitting" };
|
||||
private static readonly Process Cleans = new Process { Name = "Cleans" };
|
||||
private static readonly Process Reactor = new Process { Name = "Reactor" };
|
||||
private static readonly Process Metrology = new Process { Name = "Metrology" };
|
||||
private static readonly Process FQA = new Process { Name = "FQA" };
|
||||
private static readonly Process Packaging = new Process { Name = "Packaging" };
|
||||
private static readonly Process Shipping = new Process { Name = "Shipping" };
|
||||
private static readonly Process BuildingInfrastructure = new Process { Name = "Building Infrastructure" };
|
||||
private static readonly Process Conversion = new Process { Name = "Conversion" };
|
||||
private static readonly Process RMA = new Process { Name = "RMA" };
|
||||
private static readonly Process CustomerCompliant = new Process { Name = "Customer Compliant" };
|
||||
|
||||
public static IEnumerable<Process> ProductionProcesses = new HashSet<Process> {
|
||||
Cleans,
|
||||
Reactor,
|
||||
Metrology,
|
||||
FQA,
|
||||
Packaging
|
||||
};
|
||||
|
||||
public static IEnumerable<Process> EngineeringProcesses = new HashSet<Process> {
|
||||
Conversion,
|
||||
Cleans,
|
||||
Reactor,
|
||||
Metrology,
|
||||
FQA,
|
||||
Packaging
|
||||
};
|
||||
|
||||
public static IEnumerable<Process> MaterialsProcesses = new HashSet<Process> {
|
||||
Receiving,
|
||||
Kitting,
|
||||
Shipping
|
||||
};
|
||||
|
||||
public static IEnumerable<Process> FacilitiesProcesses = new HashSet<Process> {
|
||||
BuildingInfrastructure
|
||||
};
|
||||
|
||||
public static IEnumerable<Process> MaintenanceProcesses = new HashSet<Process> {
|
||||
Cleans,
|
||||
Reactor,
|
||||
Packaging
|
||||
};
|
||||
|
||||
public static IEnumerable<Process> QualityProcesses = new HashSet<Process> {
|
||||
RMA,
|
||||
CustomerCompliant
|
||||
};
|
||||
}
|
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; }
|
||||
}
|
111
MesaFabApproval.Shared/Models/Tool.cs
Normal file
111
MesaFabApproval.Shared/Models/Tool.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MesaFabApproval.Shared.Models;
|
||||
|
||||
public class Tool {
|
||||
[Key]
|
||||
public int ToolID { get; set; }
|
||||
|
||||
[Required]
|
||||
public required string Name { get; set; } = "";
|
||||
|
||||
public static IEnumerable<Tool> ReactorTools = new HashSet<Tool> {
|
||||
new Tool { Name = "Reactor 20"},
|
||||
new Tool { Name = "Reactor 21"},
|
||||
new Tool { Name = "Reactor 22"},
|
||||
new Tool { Name = "Reactor 23"},
|
||||
new Tool { Name = "Reactor 24"},
|
||||
new Tool { Name = "Reactor 25"},
|
||||
new Tool { Name = "Reactor 26"},
|
||||
new Tool { Name = "Reactor 27"},
|
||||
new Tool { Name = "Reactor 28"},
|
||||
new Tool { Name = "Reactor 29"},
|
||||
new Tool { Name = "Reactor 30"},
|
||||
new Tool { Name = "Reactor 31"},
|
||||
new Tool { Name = "Reactor 32"},
|
||||
new Tool { Name = "Reactor 33"},
|
||||
new Tool { Name = "Reactor 34"},
|
||||
new Tool { Name = "Reactor 35"},
|
||||
new Tool { Name = "Reactor 36"},
|
||||
new Tool { Name = "Reactor 37"},
|
||||
new Tool { Name = "Reactor 38"},
|
||||
new Tool { Name = "Reactor 39"},
|
||||
new Tool { Name = "Reactor 40"},
|
||||
new Tool { Name = "Reactor 41"},
|
||||
new Tool { Name = "Reactor 42"},
|
||||
new Tool { Name = "Reactor 43"},
|
||||
new Tool { Name = "Reactor 44"},
|
||||
new Tool { Name = "Reactor 45"},
|
||||
new Tool { Name = "Reactor 46"},
|
||||
new Tool { Name = "Reactor 47"},
|
||||
new Tool { Name = "Reactor 48"},
|
||||
new Tool { Name = "Reactor 49"},
|
||||
new Tool { Name = "Reactor 50"},
|
||||
new Tool { Name = "Reactor 51"},
|
||||
new Tool { Name = "Reactor 52"},
|
||||
new Tool { Name = "Reactor 53"},
|
||||
new Tool { Name = "Reactor 54"},
|
||||
new Tool { Name = "Reactor 55"},
|
||||
new Tool { Name = "Reactor 56"},
|
||||
new Tool { Name = "Reactor 57"},
|
||||
new Tool { Name = "Reactor 58"},
|
||||
new Tool { Name = "Reactor 59"},
|
||||
new Tool { Name = "Reactor 60"},
|
||||
new Tool { Name = "Reactor 61"},
|
||||
new Tool { Name = "Reactor 62"},
|
||||
new Tool { Name = "Reactor 63"},
|
||||
new Tool { Name = "Reactor 64"},
|
||||
new Tool { Name = "Reactor 65"},
|
||||
new Tool { Name = "Reactor 66"},
|
||||
new Tool { Name = "Reactor 67"},
|
||||
new Tool { Name = "Reactor 68"},
|
||||
new Tool { Name = "Reactor 70"},
|
||||
new Tool { Name = "Reactor 72"},
|
||||
new Tool { Name = "Reactor 73"},
|
||||
new Tool { Name = "Reactor 74"},
|
||||
new Tool { Name = "Reactor 75"},
|
||||
new Tool { Name = "Reactor 77"},
|
||||
new Tool { Name = "Reactor 79"}
|
||||
};
|
||||
|
||||
public static IEnumerable<Tool> MetrologyTools { get; private set; } = new HashSet<Tool> {
|
||||
new Tool { Name = "Biorad 2"},
|
||||
new Tool { Name = "Biorad 3"},
|
||||
new Tool { Name = "Biorad 4"},
|
||||
new Tool { Name = "Biorad 5"},
|
||||
new Tool { Name = "HgCV 1" },
|
||||
new Tool { Name = "HgCV 2" },
|
||||
new Tool { Name = "HgCV 3" },
|
||||
new Tool { Name = "CDE 4" },
|
||||
new Tool { Name = "CDE 5" },
|
||||
new Tool { Name = "CDE 6" },
|
||||
new Tool { Name = "Tencor 1" },
|
||||
new Tool { Name = "Tencor 2" },
|
||||
new Tool { Name = "Tencor 3" },
|
||||
new Tool { Name = "SP1" },
|
||||
new Tool { Name = "SRP" },
|
||||
new Tool { Name = "SPV" }
|
||||
};
|
||||
|
||||
public static IEnumerable<Tool> PackagingTools { get; private set; } = new HashSet<Tool> {
|
||||
new Tool { Name = "Bagger 1" },
|
||||
new Tool { Name = "Bagger 2" },
|
||||
new Tool { Name = "Bagger 3" },
|
||||
new Tool { Name = "Bagger 4" }
|
||||
};
|
||||
|
||||
public static IEnumerable<Tool> CleansTools { get; private set; } = new HashSet<Tool> {
|
||||
new Tool { Name = "Akrion 1" },
|
||||
new Tool { Name = "AHPS" }
|
||||
};
|
||||
|
||||
public static IEnumerable<Tool> FqaTools { get; private set; } = new HashSet<Tool> {
|
||||
new Tool { Name = "6\" Wafer Counter 1" },
|
||||
new Tool { Name = "6\" Wafer Counter 2" },
|
||||
new Tool { Name = "6\" Wafer Counter 3" },
|
||||
new Tool { Name = "6\" Wafer Counter 4" },
|
||||
new Tool { Name = "8\" Wafer Counter 1" },
|
||||
new Tool { Name = "8\" Wafer Counter 2" },
|
||||
new Tool { Name = "8\" Wafer Counter 3" }
|
||||
};
|
||||
}
|
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; }
|
||||
}
|
30
MesaFabApproval.Shared/Models/User.cs
Normal file
30
MesaFabApproval.Shared/Models/User.cs
Normal file
@ -0,0 +1,30 @@
|
||||
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}";
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
User? u = obj as User;
|
||||
|
||||
return u is not null && u.UserID == this.UserID;
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return this.UserID.GetHashCode();
|
||||
}
|
||||
}
|
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());
|
||||
}
|
||||
}
|
||||
}
|
14
MesaFabApproval.Shared/Utilities/DateTimeUtilities.cs
Normal file
14
MesaFabApproval.Shared/Utilities/DateTimeUtilities.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace MesaFabApproval.Shared.Utilities;
|
||||
|
||||
public class DateTimeUtilities {
|
||||
public static DateTime MIN_DT = new DateTime(1753, 1, 1, 0, 0, 0);
|
||||
public static DateTime MAX_DT = new DateTime(9999, 12, 31, 11, 59, 59);
|
||||
|
||||
public static string GetDateAsStringMinDefault(DateTime dt) {
|
||||
return dt > MIN_DT ? dt.ToString("yyyy-MM-dd HH:mm") : "";
|
||||
}
|
||||
|
||||
public static string GetDateAsStringMaxDefault(DateTime dt) {
|
||||
return dt < MAX_DT ? dt.ToString("yyyy-MM-dd HH:mm") : "";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user