Updated azure-pipelines-server.yml
Changed to thunderclient to messa017 Nuget Bump Scan Helper
This commit is contained in:
90
Server/Repositories/ReactorsRepository.cs
Normal file
90
Server/Repositories/ReactorsRepository.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
namespace OI.Metrology.Server.Repository;
|
||||
|
||||
public class ReactorsRepository : IReactorsRepository
|
||||
{
|
||||
|
||||
Result<int[]> IReactorsRepository.EvenReactors()
|
||||
{
|
||||
Result<int[]> results;
|
||||
int[] collection = new int[] {
|
||||
20,
|
||||
22,
|
||||
24,
|
||||
26,
|
||||
28,
|
||||
30,
|
||||
32,
|
||||
34,
|
||||
36,
|
||||
38,
|
||||
40,
|
||||
42,
|
||||
44,
|
||||
46,
|
||||
48,
|
||||
50,
|
||||
52,
|
||||
54,
|
||||
56,
|
||||
58,
|
||||
60,
|
||||
62,
|
||||
64,
|
||||
66,
|
||||
68,
|
||||
70,
|
||||
72,
|
||||
74
|
||||
};
|
||||
results = new()
|
||||
{
|
||||
Results = collection,
|
||||
TotalRows = collection.Length,
|
||||
};
|
||||
return results;
|
||||
}
|
||||
|
||||
Result<int[]> IReactorsRepository.OddReactors()
|
||||
{
|
||||
Result<int[]> results;
|
||||
int[] collection = new int[] {
|
||||
21,
|
||||
23,
|
||||
25,
|
||||
27,
|
||||
29,
|
||||
31,
|
||||
33,
|
||||
35,
|
||||
37,
|
||||
39,
|
||||
41,
|
||||
43,
|
||||
45,
|
||||
47,
|
||||
49,
|
||||
51,
|
||||
53,
|
||||
55,
|
||||
57,
|
||||
59,
|
||||
61,
|
||||
63,
|
||||
65,
|
||||
73,
|
||||
75,
|
||||
77,
|
||||
79
|
||||
};
|
||||
results = new()
|
||||
{
|
||||
Results = collection,
|
||||
TotalRows = collection.Length,
|
||||
};
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
158
Server/Repositories/WorkMaterialRepository.cs
Normal file
158
Server/Repositories/WorkMaterialRepository.cs
Normal file
@ -0,0 +1,158 @@
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OI.Metrology.Server.Repository;
|
||||
|
||||
public class WorkMaterialRepository : IWorkMaterialRepository
|
||||
{
|
||||
|
||||
private readonly string _MockRoot;
|
||||
private readonly string _RepositoryName;
|
||||
private readonly IDbConnectionFactory _DBConnectionFactory;
|
||||
|
||||
public WorkMaterialRepository(string mockRoot, IDbConnectionFactory dbConnectionFactory)
|
||||
{
|
||||
_MockRoot = mockRoot;
|
||||
_DBConnectionFactory = dbConnectionFactory;
|
||||
_RepositoryName = nameof(WorkMaterialRepository)[..^10];
|
||||
}
|
||||
|
||||
string IWorkMaterialRepository.GetCommandText(int? workOrderNumber, int? workOrderStep, int? workOrderCassette)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
_ = result.Append("select ( ").
|
||||
Append(" select wm_b.slot_no, ").
|
||||
Append(" wm_b.rds_no, ").
|
||||
Append(" rr.reactor, ").
|
||||
Append(" wm_b.pocket_no, ").
|
||||
Append(" wm_b.zone, ").
|
||||
Append(" rr.ps_no, ").
|
||||
Append(" rr.recipe_name, ").
|
||||
Append(" rr.recipe_no, ").
|
||||
Append(" rr.spec_type ").
|
||||
Append(" from lsl2sql.dbo.wm_in_slot_no wm_b ").
|
||||
Append(" inner join lsl2sql.dbo.react_run rr ").
|
||||
Append(" on wm_b.wo_no = rr.wo_no ").
|
||||
Append(" and wm_b.rds_no = rr.rds_no ").
|
||||
Append(" where wm_b.wo_no = ").Append(workOrderNumber is null ? -1 : workOrderNumber.Value).Append(' ').
|
||||
Append(" and wm_b.proc_step_no = ").Append(workOrderStep is null ? -1 : workOrderStep.Value).Append(' ').
|
||||
Append(" and wm_b.in_cass_no = ").Append(workOrderCassette is null ? -1 : workOrderCassette.Value).Append(' ').
|
||||
Append(" and wm_b.rds_no = wm.rds_no ").
|
||||
Append(" order by wm_b.slot_no ").
|
||||
Append(" for json path ").
|
||||
Append(" ) [group] ").
|
||||
Append("from lsl2sql.dbo.wm_in_slot_no wm ").
|
||||
Append("where wm.wo_no = ").Append(workOrderNumber is null ? -1 : workOrderNumber.Value).Append(' ').
|
||||
Append(" and wm.proc_step_no = ").Append(workOrderStep is null ? -1 : workOrderStep.Value).Append(' ').
|
||||
Append(" and wm.in_cass_no = ").Append(workOrderCassette is null ? -1 : workOrderCassette.Value).Append(' ').
|
||||
Append("group by wm.rds_no ").
|
||||
Append("order by wm.rds_no ").
|
||||
Append("for json path ");
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private static StringBuilder GetForJsonPath(IDbConnectionFactory dbConnectionFactory, string commandText)
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
using DbConnection dbConnection = dbConnectionFactory.GetDbConnection(useOI2Sql: true);
|
||||
DbCommand dbCommand = dbConnection.CreateCommand();
|
||||
dbCommand.CommandText = commandText;
|
||||
DbDataReader dbDataReader = dbCommand.ExecuteReader(CommandBehavior.SequentialAccess);
|
||||
while (dbDataReader.Read())
|
||||
_ = stringBuilder.Append(dbDataReader.GetString(0));
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
private static (int?, int?, int?, bool) GetWorkOrder(string mid)
|
||||
{
|
||||
int? workOrderStep = null;
|
||||
int? workOrderNumber = null;
|
||||
MatchCollection[] collection;
|
||||
int? workOrderCassette = null;
|
||||
if (string.IsNullOrEmpty(mid))
|
||||
collection = Array.Empty<MatchCollection>();
|
||||
else
|
||||
{
|
||||
string pattern = @"^([oiOI])?([0-9]{6,7})\.([0-5]{1})\.([0-9]{1,2})$"; // o171308.1.51
|
||||
collection = (from l in mid.Split('-') select Regex.Matches(l, pattern)).ToArray();
|
||||
}
|
||||
foreach (MatchCollection matchCollection in collection)
|
||||
{
|
||||
if (matchCollection.Count == 0)
|
||||
continue;
|
||||
if (!matchCollection[0].Success || matchCollection[0].Groups.Count != 5)
|
||||
continue;
|
||||
if (!int.TryParse(matchCollection[0].Groups[3].Value, out int workOrderStepValue))
|
||||
continue;
|
||||
if (!int.TryParse(matchCollection[0].Groups[2].Value, out int workOrderNumberValue))
|
||||
continue;
|
||||
if (!int.TryParse(matchCollection[0].Groups[4].Value, out int workOrderCassetteValue))
|
||||
continue;
|
||||
workOrderStep = workOrderStepValue;
|
||||
workOrderNumber = workOrderNumberValue;
|
||||
workOrderCassette = workOrderCassetteValue;
|
||||
break;
|
||||
}
|
||||
return new(workOrderNumber, workOrderStep, workOrderCassette, workOrderStep is not null || workOrderNumber is not null || workOrderCassette is not null);
|
||||
}
|
||||
|
||||
Result<WorkMaterialV2[]> IWorkMaterialRepository.GetCassette(string mid)
|
||||
{
|
||||
Result<WorkMaterialV2[]>? result;
|
||||
if (!string.IsNullOrEmpty(_MockRoot))
|
||||
{
|
||||
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IWorkMaterialRepository.GetCassette)}.json"));
|
||||
result = JsonSerializer.Deserialize<Result<WorkMaterialV2[]>>(json);
|
||||
if (result is null)
|
||||
throw new NullReferenceException(nameof(result));
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkMaterialV2[] results;
|
||||
(int? workOrderNumber, int? workOrderStep, int? workOrderCassette, bool isWorkOrder) = GetWorkOrder(mid);
|
||||
if (!isWorkOrder)
|
||||
results = Array.Empty<WorkMaterialV2>();
|
||||
else
|
||||
{
|
||||
WorkMaterial[]? group;
|
||||
JsonProperty[] jsonProperties;
|
||||
List<WorkMaterial> collection = new();
|
||||
IWorkMaterialRepository workMaterialRepository = this;
|
||||
string commandText = workMaterialRepository.GetCommandText(workOrderNumber, workOrderStep, workOrderCassette);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_DBConnectionFactory, commandText);
|
||||
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(stringBuilder.ToString());
|
||||
if (jsonElements is null)
|
||||
throw new NullReferenceException(nameof(jsonElements));
|
||||
foreach (JsonElement jsonElement in jsonElements)
|
||||
{
|
||||
if (jsonElement.ValueKind != JsonValueKind.Object)
|
||||
continue;
|
||||
jsonProperties = jsonElement.EnumerateObject().ToArray();
|
||||
if (!jsonProperties.Any())
|
||||
continue;
|
||||
group = JsonSerializer.Deserialize<WorkMaterial[]>(jsonProperties.First().Value.ToString(), new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
if (group is null)
|
||||
continue;
|
||||
foreach (WorkMaterial workMaterial in group)
|
||||
collection.Add(workMaterial);
|
||||
}
|
||||
if (collection is null)
|
||||
throw new NullReferenceException(nameof(collection));
|
||||
results = WorkMaterial.Convert(collection);
|
||||
}
|
||||
result = new()
|
||||
{
|
||||
Results = results,
|
||||
TotalRows = results.Length,
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user