Merge branch 'Release/CodeAssisted_02'
This commit is contained in:
@@ -1,94 +1,24 @@
|
||||
# CI to Local Workflow Guide
|
||||
# MAPO-CORE Agent Instructions
|
||||
|
||||
This document describes how the GitLab CI pipeline in this repository translates to local commands that can be run on your machine. It also contains helper scripts and environment variables used by the CI.
|
||||
## Core Context
|
||||
- **Primary Goal**: Optimization and refactoring of the `MP-SPEC.sln` solution, focusing on migrating legacy Redis/DB caching to `FusionCache` (Memory + Redis + DB) in `MP.SPEC\Data\MpDataService.cs`.
|
||||
- **Language**: C# (primary), PowerShell (scripts).
|
||||
- **Documentation/Comments**: MUST be in **Italiano**.
|
||||
- **Code Style**: Maintain existing region organization (`#region Public Methods`, etc.).
|
||||
- **Reference Docs**: See `Refactor_Plan.md` for the current migration status and detailed strategy.
|
||||
|
||||
## Environment Variables
|
||||
All variables listed below are interpolated in the CI templates. When running locally you can set them in a PowerShell profile or via `dotnet` arguments.
|
||||
## Development Workflow
|
||||
- **Build & Verification**:
|
||||
- Use `./build_all_par.ps1 --agent` to build all solutions silently.
|
||||
- Always verify that changes do not leave partial traces of old classes that break compilation.
|
||||
- **Refactoring Strategy (`MpDataService.cs`)**:
|
||||
- Use `GetOrFetchAsync<T>(string operationName, string cacheKey, Func<Task<T>> fetchFunc, TimeSpan expiration, params string[] tags)` as the standard for all data access.
|
||||
- Target methods currently using manual `redisDb.StringGetAsync` / `StringSetAsync` patterns.
|
||||
- **Testing**:
|
||||
- Check the codebase for existing testing patterns before proposing new ones.
|
||||
|
||||
| Variable | Description | Typical value |
|
||||
|----------|--------------|---------------|
|
||||
| `SOL_NAME` | Solution name to restore | **MP-STATS.sln** |
|
||||
| `PROJ_PATH` | Directory containing the main project | **MP.Stats** |
|
||||
| `APP_NAME` | Main project file name (without `.csproj`) | **MP.Stats** |
|
||||
| `NUGET_PATH` | NuGet credential file | **`C:\\Users\\samuele.steamw\AppData\Roaming\NuGet\Credentials.config`** |
|
||||
| `NEXUS_PATH` | Nexus host URL | **https://nexus.steamware.net** |
|
||||
| `DEST` | Artifacts output folder | **bin\publish** |
|
||||
| `VERS_MAIN`, `VERS_MAIN_APP`, `VERSSUB` | Version strings used in packaging | **1.0.0** /
|
||||
| `NEXUS_PASSWD` | Nexus password (secure via CI secret) | *Secret* |
|
||||
## Architecture Notes
|
||||
- **Multi-Layer Caching**: The system is transitioning from a dual-layer (Redis + DB) to a triple-layer approach via `IFusionCache`.
|
||||
- **Service Responsibility**: `MpDataService` is the central hub for data access, interacting with `MpSpecController` (EFCore) and `MpMongoController` (MongoDB).
|
||||
- **Key Management**: Cache keys are heavily managed via `Utils.redis...` constants. Use these to prevent key mismatches.
|
||||
|
||||
## Build Pipeline (`buildjob`) – Local Equivalent
|
||||
|
||||
The CI first restores NuGet packages and then builds the solution for the selected `APP_NAME`.
|
||||
|
||||
```powershell
|
||||
# 1. Restore
|
||||
#$env:SOL_NAME.sln is resolved by the .nuget-fix script
|
||||
# In PowerShell: dotnet restore "MP-STATS.sln"
|
||||
|
||||
# 2. Build
|
||||
# $env:APP_NAME/$env:APP_NAME.csproj points to the project file
|
||||
# In PowerShell: dotnet build "MP.Stats/MP.Stats.csproj"
|
||||
```
|
||||
|
||||
### Helper: `.nuget-fix`
|
||||
The `.nuget-fix` PowerShell script removes any stale NuGet sources that conflict with the Nexus proxy and re‑adds the latest proxy source with credentials. Ensure this script runs *before* `dotnet restore`.
|
||||
|
||||
## Deploy Pipeline (`deployjob`) – Local Equivalent
|
||||
|
||||
Deployment in CI rebuilds the project, publishes it, hashes the output, and uploads it to Nexus. The same steps can be executed locally.
|
||||
|
||||
```powershell
|
||||
# 1. Rebuild (same as Build)
|
||||
# dotnet build "MP.Stats/MP.Stats.csproj"
|
||||
|
||||
# 2. Publish to a local folder
|
||||
# The `dotnet publish` command mimics the CI publish step. The `-c Release` ensures a Release build.
|
||||
# In PowerShell:
|
||||
# dotnet publish "MP.Stats/MP.Stats.csproj" -c Release -o publish
|
||||
|
||||
# 3. Create hashes (MD5 & SHA1)
|
||||
# The .hashBuild template generates .md5 and .sha1 files alongside the ZIP. A simple replacement can be
|
||||
# 1. Zip the folder: `Compress-Archive -Path publish -DestinationPath $(APP_NAME).zip`
|
||||
# 2. Generate hashes:
|
||||
# (Get-FileHash -Algorithm MD5 "$(APP_NAME).zip").Hash | Out-File "$(APP_NAME).md5"
|
||||
# (Get-FileHash -Algorithm SHA1 "$(APP_NAME).zip").Hash | Out-File "$(APP_NAME).sha1"
|
||||
|
||||
# 4. Upload to Nexus (requires `curl`)
|
||||
# Example curl command (CI uses `nexus-curl` script):
|
||||
# $curl -u $(NUGET_USER):$(NEXUS_PASSWD) "$(NEXUS_PATH)/repository/$(APP_NAME)" -T "$(APP_NAME).zip"
|
||||
```
|
||||
|
||||
## Installer & Release
|
||||
The **installer** template copies the published artifacts to a staging folder and optionally creates installers. The **release** template bumps version numbers, updates the `nuspec`, generates a changelog, and pushes the packages to Nexus.
|
||||
|
||||
Generally these steps are CI‑only, but you can repeat the same `dotnet pack` / `nuget push` commands locally if needed.
|
||||
|
||||
## Common Issues & Fixes
|
||||
|
||||
* _NuGet authentication errors_: Run `.nuget-fix` to reset the sources.
|
||||
* _Missing SDK_: Verify `dotnet --list-sdks` includes at least one SDK.
|
||||
* _Hashes not matching_: Ensure the ZIP file is identical to the one CI produced (same path, no hidden files).
|
||||
|
||||
## Quick Start
|
||||
```powershell
|
||||
# Restore
|
||||
.\.nuget-fix
|
||||
|
||||
# Build
|
||||
|
||||
dotnet restore "MP-STATS.sln"
|
||||
dotnet build "MP.Stats/MP.Stats.csproj"
|
||||
|
||||
# Publish & run
|
||||
|
||||
dotnet publish "MP.Stats/MP.Stats.csproj" -c Release -o publish
|
||||
dotnet run --project "MP.Stats/MP.Stats.csproj"
|
||||
|
||||
# For hot‑reload during development
|
||||
|
||||
dotnet watch run --project "MP.Stats/MP.Stats.csproj"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Feel free to adjust paths or environment variable names if your local setup differs.
|
||||
|
||||
BIN
Binary file not shown.
@@ -24,7 +24,7 @@
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.36" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.36" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.36" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="10.0.7" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.25" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.1" />
|
||||
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.17" />
|
||||
<PackageVersion Include="MongoDB.Driver" Version="2.19.0" />
|
||||
|
||||
+16
-11
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Egw.Core
|
||||
{
|
||||
@@ -19,14 +14,24 @@ namespace Egw.Core
|
||||
/// <returns></returns>
|
||||
public static async Task SaveToCsv<T>(List<T> reportData, string path, char separator)
|
||||
{
|
||||
// 1. Recuperiamo le proprietà del tipo T una sola volta (Risolve i problemi di performance)
|
||||
PropertyInfo[] properties = typeof(T).GetProperties();
|
||||
|
||||
var lines = new List<string>();
|
||||
IEnumerable<PropertyDescriptor> props = TypeDescriptor.GetProperties(typeof(T)).OfType<PropertyDescriptor>();
|
||||
var header = string.Join(";", props.ToList().Select(x => x.Name));
|
||||
|
||||
// 2. Creiamo l'header usando il separatore corretto (Risolve il bug del ";" fisso)
|
||||
var header = string.Join(separator, properties.Select(p => p.Name));
|
||||
lines.Add(header);
|
||||
var valueLines = reportData.Select(row => string.Join(separator, header.Split(separator).Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
||||
//var valueLines = reportData.Select(row => string.Join(";", header.Split(';').Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
||||
|
||||
// 3. Estraiamo i valori gestendo i possibili null (Risolve il tuo warning)
|
||||
var valueLines = reportData
|
||||
.Where(row => row != null)
|
||||
.Select(row => string.Join(separator, properties.Select(p => p.GetValue(row)?.ToString() ?? string.Empty)));
|
||||
|
||||
lines.AddRange(valueLines);
|
||||
await Task.Run(() => File.WriteAllLines(path, lines.ToArray()));
|
||||
|
||||
// 4. Utilizziamo il metodo di scrittura asincrono nativo di .NET
|
||||
await File.WriteAllLinesAsync(path, lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.32126.317
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Data", "MP.Data\MP.Data.csproj", "{10BA8450-301D-49C7-8E1E-21B7469C225C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP-TAB", "MP-TAB\MP-TAB\MP-TAB.csproj", "{9141D627-EE10-4BF6-9A2C-AAC6845E185F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP-TAB.Client", "MP-TAB\MP-TAB.Client\MP-TAB.Client.csproj", "{28559808-58F2-424B-B65C-062AA59839EC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9141D627-EE10-4BF6-9A2C-AAC6845E185F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9141D627-EE10-4BF6-9A2C-AAC6845E185F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9141D627-EE10-4BF6-9A2C-AAC6845E185F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9141D627-EE10-4BF6-9A2C-AAC6845E185F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{28559808-58F2-424B-B65C-062AA59839EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{28559808-58F2-424B-B65C-062AA59839EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{28559808-58F2-424B-B65C-062AA59839EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{28559808-58F2-424B-B65C-062AA59839EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {632D11D1-088B-4795-97E5-048534002558}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -105,7 +105,7 @@ namespace MP_TAB3.Components
|
||||
if (!ListArtDisabled)
|
||||
{
|
||||
Log.Debug("START GetArticoli");
|
||||
var rawData = await MDataService.ArticoliGetSearch(10000, "*", searchVal);
|
||||
var rawData = await MDataService.ArticoliGetSearch(10000,"*", "*", searchVal);
|
||||
// trasformo!
|
||||
if (rawData != null)
|
||||
{
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace MP_TAB3.Components
|
||||
if (!ListArtDisabled)
|
||||
{
|
||||
Log.Debug("START GetArticoli");
|
||||
var rawData = await MDataService.ArticoliGetSearch(10000, "*", searchVal);
|
||||
var rawData = await MDataService.ArticoliGetSearch(10000,"*", "*", searchVal);
|
||||
// trasformo!
|
||||
if (rawData != null)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>8.16.2604.2718</Version>
|
||||
<Version>8.16.2606.408</Version>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP_TAB3</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
+41
-12
@@ -2,16 +2,18 @@
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
#endif
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using MP.Data;
|
||||
using MP.Data.Services;
|
||||
using NLog;
|
||||
using NLog.Web;
|
||||
using StackExchange.Redis;
|
||||
using static Org.BouncyCastle.Math.EC.ECCurve;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
using ZiggyCreatures.Caching.Fusion.Backplane.StackExchangeRedis;
|
||||
using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -27,15 +29,45 @@ var cString = configuration.GetConnectionString("Redis");
|
||||
string connStringRedis = cString ?? "localhost:6379, DefaultDatabase=5, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false";
|
||||
//string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
||||
// avvio oggetto shared x redis...
|
||||
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
IConnectionMultiplexer redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
|
||||
// Add services x accesso dati
|
||||
builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
||||
|
||||
// ✅ FusionCache
|
||||
builder.Services.AddFusionCache()
|
||||
.WithDistributedCache(sp => sp.GetRequiredService<IDistributedCache>())
|
||||
.WithSerializer(new FusionCacheNewtonsoftJsonSerializer())
|
||||
.WithBackplane(new RedisBackplane(new RedisBackplaneOptions
|
||||
{
|
||||
ConnectionMultiplexerFactory = () => Task.FromResult(redisMultiplexer)
|
||||
}));
|
||||
|
||||
// Metodi principali x accesso dati
|
||||
var connStr = builder.Configuration.GetConnectionString("MP.Data")
|
||||
?? throw new InvalidOperationException("ConnString 'MP.Data' mancante.");
|
||||
// aggiungo il costruttore x i vari DbContextFactory
|
||||
builder.Services.AddDbContextFactory<MoonProContext>(options =>
|
||||
options.UseSqlServer(connStr)
|
||||
.EnableSensitiveDataLogging(false) // true solo in Sviluppo
|
||||
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));
|
||||
|
||||
var connStrFL = builder.Configuration.GetConnectionString("MP.Flux")
|
||||
?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante.");
|
||||
builder.Services.AddDbContextFactory<MoonPro_FluxContext>(options =>
|
||||
options.UseSqlServer(connStrFL)
|
||||
.EnableSensitiveDataLogging(false) // true solo in Sviluppo
|
||||
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddServerSideBlazor();
|
||||
|
||||
|
||||
// Init centralizzato Repository/Servizi da MP.Data Services
|
||||
builder.Services.AddTabDataLayer();
|
||||
|
||||
#if false
|
||||
builder.Services.AddSingleton<TabDataFeeder>();
|
||||
builder.Services.AddSingleton<StatusData>();
|
||||
builder.Services.AddSingleton<ListSelectDataSrv>();
|
||||
@@ -43,13 +75,10 @@ builder.Services.AddSingleton<OrderDataSrv>();
|
||||
builder.Services.AddSingleton<SharedMemService>();
|
||||
builder.Services.AddSingleton<TabDataService>();
|
||||
builder.Services.AddScoped<MessageService>();
|
||||
#if false
|
||||
builder.Services.AddBlazoredLocalStorage();
|
||||
builder.Services.AddBlazoredSessionStorage();
|
||||
#endif
|
||||
// aggiunta helper local/session storage service
|
||||
builder.Services.AddScoped<ISessionStorageService, SessionStorageService>();
|
||||
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||
#endif
|
||||
|
||||
// gestione email
|
||||
builder.Services.Configure<MailKitMailSettings>(builder.Configuration.GetSection(nameof(MailKitMailSettings)));
|
||||
@@ -62,7 +91,7 @@ logger.Info("Aggiunti services");
|
||||
var app = builder.Build();
|
||||
|
||||
// aggiunt base URL x routing corretto
|
||||
var pathBase= configuration.GetValue<string>("SpecialConf:AppUrl") ?? (configuration.GetValue<string>("OptConf:AppUrl") ?? "");
|
||||
var pathBase = configuration.GetValue<string>("SpecialConf:AppUrl") ?? (configuration.GetValue<string>("OptConf:AppUrl") ?? "");
|
||||
app.UsePathBase(pathBase);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -78,7 +107,7 @@ app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
// gestione static files: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-8.0
|
||||
string BasePathDisegni = configuration.GetValue<string>("ServerConf:BasePathDisegni") ?? configuration.GetValue<string>("OptConf:BasePathDisegni")?? "";
|
||||
string BasePathDisegni = configuration.GetValue<string>("ServerConf:BasePathDisegni") ?? configuration.GetValue<string>("OptConf:BasePathDisegni") ?? "";
|
||||
if (!string.IsNullOrEmpty(BasePathDisegni))
|
||||
{
|
||||
// verifico esista folder disegni
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MAPOSPEC </i>
|
||||
<h4>Versione: 8.16.2604.2718</h4>
|
||||
<h4>Versione: 8.16.2606.408</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2604.2718
|
||||
8.16.2606.408
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2604.2718</version>
|
||||
<version>8.16.2606.408</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/MP-TAB3.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -8,16 +8,10 @@
|
||||
"AllowedHosts": "*",
|
||||
"CodApp": "MP.TAB",
|
||||
"ConnectionStrings": {
|
||||
//"Redis": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=6,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
|
||||
//"MP.All": "Server=SQL2022PROD;Database=Donati_LAV_MoonPro_prod; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
//"MP.Mon": "Server=SQL2022PROD;Database=Donati_LAV_MoonPro_prod; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
//"MP.IS": "Server=SQL2022PROD;Database=MoonPro_IS_EdilChim; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.INVE;",
|
||||
//"MP.Tab": "Server=SQL2022PROD;Database=Donati_LAV_MoonPro_prod; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
//"MP.Mag": "Server=SQL2022PROD;Database=MoonPro_MAG; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;"
|
||||
|
||||
"Redis": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
|
||||
"MP.All": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
"MP.Data": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
"MP.Flux": "Server=SQL2016DEV;Database=MoonPro_FluxData; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
"MP.Mon": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
"MP.IS": "Server=SQL2016DEV;Database=MoonPro_IS_EdilChim; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.INVE;",
|
||||
"MP.Tab": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;",
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.32126.317
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Data", "MP.Data\MP.Data.csproj", "{10BA8450-301D-49C7-8E1E-21B7469C225C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Mon", "MP.Mon\MP.Mon.csproj", "{7780FA7A-3597-4098-81C1-DC9AD6AE7A98}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Server", "MP.WASM.Mon\Server\MP.WASM.Mon.Server.csproj", "{4A98B7F4-4EC6-4284-9D6C-63203DB981B1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Client", "MP.WASM.Mon\Client\MP.WASM.Mon.Client.csproj", "{9BF7BDE7-016A-458C-8791-494FD4204301}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{10BA8450-301D-49C7-8E1E-21B7469C225C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9BF7BDE7-016A-458C-8791-494FD4204301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9BF7BDE7-016A-458C-8791-494FD4204301}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9BF7BDE7-016A-458C-8791-494FD4204301}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9BF7BDE7-016A-458C-8791-494FD4204301}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {632D11D1-088B-4795-97E5-048534002558}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -12,16 +12,23 @@ namespace MP.AppAuth.Controllers
|
||||
{
|
||||
public class AppAuthController
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public AppAuthController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
Log.Info("Avviata classe AppAuthController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -189,8 +196,6 @@ namespace MP.AppAuth.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Record x gestione Update
|
||||
/// </summary>
|
||||
@@ -225,12 +230,5 @@ namespace MP.AppAuth.Controllers
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,16 @@ namespace MP.AppAuth.Controllers
|
||||
{
|
||||
public class AppUserController : IDisposable
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private bool _disposed = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public AppUserController(IConfiguration configuration)
|
||||
@@ -19,7 +29,7 @@ namespace MP.AppAuth.Controllers
|
||||
Log.Info("Avviata classe AppUserController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -42,18 +52,28 @@ namespace MP.AppAuth.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
#region Protected Methods
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Fields
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,15 @@ namespace MP.AppAuth.Controllers
|
||||
{
|
||||
public class MPController : IDisposable
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
public static MPController dbController;
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
private bool _disposed = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
@@ -32,7 +28,7 @@ namespace MP.AppAuth.Controllers
|
||||
Log.Info("Avviata classe MpController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -271,15 +267,6 @@ namespace MP.AppAuth.Controllers
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (dbController != null)
|
||||
{
|
||||
// Clear database controller
|
||||
dbController.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Record x ListValues
|
||||
/// </summary>
|
||||
@@ -380,5 +367,27 @@ namespace MP.AppAuth.Controllers
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.AppAuth
|
||||
{
|
||||
public static class DataServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per IOC
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddAuthLandDataLayer(this IServiceCollection services)
|
||||
{
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,12 @@ namespace MP.AppAuth
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. DbContextOptions must be supplied.")]
|
||||
public MoonProContext()
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. DbContextOptions must be supplied.")]
|
||||
public MoonProContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
@@ -20,10 +20,6 @@ namespace MP.AppAuth.Services
|
||||
// diritti (cablato)
|
||||
public const string RoleSuperAdmin = "MoonPro_SuperAdmin";
|
||||
|
||||
public static AppAuthController dbController;
|
||||
public static MPController MpDbController;
|
||||
public static AppUserController userController;
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Private Fields
|
||||
@@ -37,15 +33,15 @@ namespace MP.AppAuth.Services
|
||||
|
||||
private const string rKeyPermUser = $"{redisBaseAddr}:PERM_USER";
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
private static ILogger<AppAuthService> _logger;
|
||||
private readonly ILogger<AppAuthService> _logger;
|
||||
|
||||
private static JsonSerializerSettings? JSSettings;
|
||||
private readonly JsonSerializerSettings? JSSettings;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private static string Modulo = "";
|
||||
private string Modulo = "";
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga IN SECONDI
|
||||
@@ -60,23 +56,27 @@ namespace MP.AppAuth.Services
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
private IConnectionMultiplexer redisConn;
|
||||
private readonly IConnectionMultiplexer redisConn;
|
||||
|
||||
//ISubscriber sub = redis.GetSubscriber();
|
||||
/// <summary>
|
||||
/// Oggetto DB redis da impiegare x chiamate R/W
|
||||
/// </summary>
|
||||
private StackExchange.Redis.IDatabase redisDb = null!;
|
||||
private readonly StackExchange.Redis.IDatabase redisDb;
|
||||
|
||||
private Random rnd = new Random();
|
||||
private readonly Random rnd = new Random();
|
||||
|
||||
private Dictionary<string, string> Vocabolario = new Dictionary<string, string>();
|
||||
|
||||
private readonly AppAuthController _appAuthController;
|
||||
private readonly MPController _mpController;
|
||||
private readonly AppUserController _appUserController;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public AppAuthService(IConfiguration configuration, ILogger<AppAuthService> logger, IConnectionMultiplexer redisConnMult)
|
||||
public AppAuthService(IConfiguration configuration, ILogger<AppAuthService> logger, IConnectionMultiplexer redisConnMult, AppAuthController appAuthController, MPController mpController, AppUserController appUserController)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
@@ -103,9 +103,9 @@ namespace MP.AppAuth.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new AppAuthController(configuration);
|
||||
MpDbController = new MPController(configuration);
|
||||
userController = new AppUserController(configuration);
|
||||
_appAuthController = appAuthController;
|
||||
_mpController = mpController;
|
||||
_appUserController = appUserController;
|
||||
_logger.LogInformation("DbController OK");
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace MP.AppAuth.Services
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private string CodApp { get; set; } = "";
|
||||
private string CodApp { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
||||
@@ -153,7 +153,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaCausaliScarto> dbResult = new List<AnagraficaCausaliScarto>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.AnagCauSca();
|
||||
dbResult = _mpController.AnagCauSca();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagCauSca: {ts.TotalMilliseconds} ms");
|
||||
@@ -169,7 +169,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagClassiTempo> dbResult = new List<AnagClassiTempo>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.AnagClassiTempo();
|
||||
dbResult = _mpController.AnagClassiTempo();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagClassiTempo: {ts.TotalMilliseconds} ms");
|
||||
@@ -185,7 +185,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaEventi> dbResult = new List<AnagraficaEventi>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.AnagEventi();
|
||||
dbResult = _mpController.AnagEventi();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagEventi: {ts.TotalMilliseconds} ms");
|
||||
@@ -201,7 +201,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaGruppi> dbResult = new List<AnagraficaGruppi>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = dbController.AnagGruppiGetAll();
|
||||
dbResult = _appAuthController.AnagGruppiGetAll();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagGruppiAll: {ts.TotalMilliseconds} ms");
|
||||
@@ -213,7 +213,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaGruppi> dbResult = new List<AnagraficaGruppi>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = dbController.AnagGruppiFilt(codTipo);
|
||||
dbResult = _appAuthController.AnagGruppiFilt(codTipo);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagGruppiFilt: {ts.TotalMilliseconds} ms");
|
||||
@@ -229,7 +229,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaIngressi> dbResult = new List<AnagraficaIngressi>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.AnagIngressi();
|
||||
dbResult = _mpController.AnagIngressi();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagIngressi: {ts.TotalMilliseconds} ms");
|
||||
@@ -241,7 +241,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.AnagKeyValuesUpsert(currRec);
|
||||
answ = _mpController.AnagKeyValuesUpsert(currRec);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"AnagKeyValAdd | Aggiunto rec | NomeVar: {currRec.NomeVar} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -253,7 +253,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.AnagKeyValuesDelete(NomeVar);
|
||||
answ = _mpController.AnagKeyValuesDelete(NomeVar);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"AnagKeyValDelete | Effettuata cancellazione | NomeVar: {NomeVar} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -265,7 +265,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagKeyValueModel> dbResult = new List<AnagKeyValueModel>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.AnagKeyValuesGetAll();
|
||||
dbResult = _mpController.AnagKeyValuesGetAll();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagKeyValList: {ts.TotalMilliseconds} ms");
|
||||
@@ -277,7 +277,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.AnagKeyValuesUpsert(currRec);
|
||||
answ = _mpController.AnagKeyValuesUpsert(currRec);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"AnagKeyValUpd | Effettuata modifica | NomeVar: {currRec.NomeVar} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -293,7 +293,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaMicroStati> dbResult = new List<AnagraficaMicroStati>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.AnagMicroStati();
|
||||
dbResult = _mpController.AnagMicroStati();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagMicroStati: {ts.TotalMilliseconds} ms");
|
||||
@@ -305,7 +305,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaOperatori> dbResult = new List<AnagraficaOperatori>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
var rawData = dbController
|
||||
var rawData = _appAuthController
|
||||
.AnagOpByGruppoGetFilt(codGruppo, searchVal);
|
||||
dbResult = rawData
|
||||
.GroupBy(user => user.MatrOpr)
|
||||
@@ -322,7 +322,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaOperatori> dbResult = new List<AnagraficaOperatori>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = dbController.AnagOpGetAll(searchVal);
|
||||
dbResult = _appAuthController.AnagOpGetAll(searchVal);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagOperList: {ts.TotalMilliseconds} ms");
|
||||
@@ -338,7 +338,7 @@ namespace MP.AppAuth.Services
|
||||
List<AnagraficaStati> dbResult = new List<AnagraficaStati>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.AnagStati();
|
||||
dbResult = _mpController.AnagStati();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per AnagStati: {ts.TotalMilliseconds} ms");
|
||||
@@ -350,7 +350,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.ConfigUpsert(currRec);
|
||||
answ = _mpController.ConfigUpsert(currRec);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"ConfigAdd | Aggiunto rec | Chiave: {currRec.Chiave} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -362,7 +362,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.ConfigDelete(Chiave);
|
||||
answ = _mpController.ConfigDelete(Chiave);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"ConfigDelete | Effettuata cancellazione | Chiave: {Chiave} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -374,7 +374,7 @@ namespace MP.AppAuth.Services
|
||||
List<ConfigModel> dbResult = new List<ConfigModel>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.ConfigGetAll();
|
||||
dbResult = _mpController.ConfigGetAll();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per ConfigList: {ts.TotalMilliseconds} ms");
|
||||
@@ -386,7 +386,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.ConfigUpsert(currRec);
|
||||
answ = _mpController.ConfigUpsert(currRec);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"ConfigUpd | Effettuata modifica | Chiave: {currRec.Chiave} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -415,7 +415,7 @@ namespace MP.AppAuth.Services
|
||||
else
|
||||
{
|
||||
// recupero diritti utente
|
||||
dbResult = userController.DirittiUtente(UserName, Modulo);
|
||||
dbResult = _appUserController.DirittiUtente(UserName, Modulo);
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -430,11 +430,8 @@ namespace MP.AppAuth.Services
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database controller
|
||||
if (MpDbController != null)
|
||||
{
|
||||
MpDbController.Dispose();
|
||||
}
|
||||
// Clear database controllers
|
||||
_mpController?.Dispose();
|
||||
}
|
||||
|
||||
public async Task FlushRedisCache()
|
||||
@@ -455,7 +452,7 @@ namespace MP.AppAuth.Services
|
||||
List<ListValues> dbResult = new List<ListValues>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.ListValues();
|
||||
dbResult = _mpController.ListValues();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per ListValues: {ts.TotalMilliseconds} ms");
|
||||
@@ -484,7 +481,7 @@ namespace MP.AppAuth.Services
|
||||
else
|
||||
{
|
||||
// recupero diritti utente
|
||||
dbResult = MpDbController.MacchineGetAll();
|
||||
dbResult = _mpController.MacchineGetAll();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -526,7 +523,7 @@ namespace MP.AppAuth.Services
|
||||
else
|
||||
{
|
||||
// recupero diritti utente
|
||||
var userRightList = userController.DirittiUtente(UserName, Modulo);
|
||||
var userRightList = _appUserController.DirittiUtente(UserName, Modulo);
|
||||
// proietto come funzioni...
|
||||
var ListFunc = userRightList.Select(x => x.Funzione).ToList();
|
||||
// trasformo i permessi utente
|
||||
@@ -534,7 +531,7 @@ namespace MP.AppAuth.Services
|
||||
{
|
||||
ListFunc = new List<string>();
|
||||
}
|
||||
dbResult = dbController.PermessiGetByFunc(ListFunc);
|
||||
dbResult = _appAuthController.PermessiGetByFunc(ListFunc);
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -565,7 +562,7 @@ namespace MP.AppAuth.Services
|
||||
List<UpdMan> dbResult = new List<UpdMan>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = dbController.UpdManGetAll();
|
||||
dbResult = _appAuthController.UpdManGetAll();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per UpdManList: {ts.TotalMilliseconds} ms");
|
||||
@@ -577,7 +574,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.VocabolarioUpsert(currRec);
|
||||
answ = _mpController.VocabolarioUpsert(currRec);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"VocabolarioAdd | Aggiunto rec | lingua: {currRec.Lingua} | lemma: {currRec.Lemma} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -589,7 +586,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.VocabolarioDelete(currRec);
|
||||
answ = _mpController.VocabolarioDelete(currRec);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"VocabolarioDelete | Effettuata cancellazione | lingua: {currRec.Lingua} | lemma: {currRec.Lemma} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -601,7 +598,7 @@ namespace MP.AppAuth.Services
|
||||
List<VocabolarioModel> dbResult = new List<VocabolarioModel>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = MpDbController.VocabolarioGetAll();
|
||||
dbResult = _mpController.VocabolarioGetAll();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per VocabolarioList: {ts.TotalMilliseconds} ms");
|
||||
@@ -613,7 +610,7 @@ namespace MP.AppAuth.Services
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
answ = MpDbController.VocabolarioUpsert(currRec);
|
||||
answ = _mpController.VocabolarioUpsert(currRec);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"VocabolarioUpd | Effettuata modifica | lingua: {currRec.Lingua} | lemma: {currRec.Lemma} | durata: {ts.TotalMilliseconds} ms");
|
||||
@@ -641,7 +638,7 @@ namespace MP.AppAuth.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
Vocabolario = dbController
|
||||
Vocabolario = _appAuthController
|
||||
.VocabolarioGetAll()
|
||||
.ToDictionary(x => $"{x.Lingua}#{x.Lemma}", x => x.Traduzione);
|
||||
rawData = JsonConvert.SerializeObject(Vocabolario);
|
||||
@@ -665,10 +662,10 @@ namespace MP.AppAuth.Services
|
||||
{
|
||||
bool answ = false;
|
||||
var masterEndpoint = redisConn.GetEndPoints()
|
||||
.Where(ep => redisConn.GetServer(ep).IsConnected && !redisConn.GetServer(ep).IsReplica)
|
||||
.FirstOrDefault();
|
||||
.Where(ep => redisConn.GetServer(ep).IsConnected && !redisConn.GetServer(ep).IsReplica)
|
||||
.FirstOrDefault();
|
||||
|
||||
// sepattern è "*" elimino intero DB...
|
||||
// se pattern è "*" elimino intero DB...
|
||||
if (masterEndpoint != null && (pat2Flush.Equals(new RedisValue("*")) || pat2Flush == RedisValue.Null))
|
||||
{
|
||||
redisConn.GetServer(masterEndpoint).FlushDatabase(database: redisDb.Database);
|
||||
@@ -699,4 +696,4 @@ namespace MP.AppAuth.Services
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MP.Core.DTO
|
||||
{
|
||||
public class CountResultDto
|
||||
{
|
||||
public int NumCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace MP.Core.DTO
|
||||
namespace MP.Core.DTO
|
||||
{
|
||||
public class FluxLogDTO
|
||||
{
|
||||
public string IdxMacchina { get; set; }
|
||||
public string IdxMacchina { get; set; } = string.Empty;
|
||||
|
||||
public DateTime dtEvento { get; set; }
|
||||
|
||||
public string CodFlux { get; set; }
|
||||
public string CodFlux { get; set; } = string.Empty;
|
||||
|
||||
public string Valore { get; set; }
|
||||
public string Valore { get; set; } = string.Empty;
|
||||
|
||||
public string ValoreEdit { get; set; }
|
||||
public string ValoreEdit { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -9,20 +9,20 @@ namespace MP.Core.DTO
|
||||
{
|
||||
public int RowNum { get; set; }
|
||||
public DateTime? LastUpdate { get; set; }
|
||||
public string IdxMacchina { get; set; }
|
||||
public string CodMacchina { get; set; }
|
||||
public string Nome { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string IdxMacchina { get; set; } = string.Empty;
|
||||
public string CodMacchina { get; set; } = string.Empty;
|
||||
public string Nome { get; set; } = string.Empty;
|
||||
public string Url { get; set; } = string.Empty;
|
||||
public int? IdxOdl { get; set; } = 0;
|
||||
public int? IdxPOdl { get; set; } = 0;
|
||||
public string CodArticolo { get; set; }
|
||||
public string Disegno { get; set; }
|
||||
public string CodArticolo { get; set; } = string.Empty;
|
||||
public string Disegno { get; set; } = string.Empty;
|
||||
public int NumPezzi { get; set; } = 0;
|
||||
public decimal TCAssegnato { get; set; } = 0;
|
||||
public DateTime? DataInizioOdl { get; set; }
|
||||
public string Semaforo { get; set; }
|
||||
public string Semaforo { get; set; } = string.Empty;
|
||||
public int? IdxStato { get; set; }
|
||||
public string DescrizioneStato { get; set; }
|
||||
public string DescrizioneStato { get; set; } = string.Empty;
|
||||
public double? Durata { get; set; }
|
||||
public int PezziProd { get; set; } = 0;
|
||||
public int PezziConf { get; set; } = 0;
|
||||
@@ -65,7 +65,7 @@ namespace MP.Core.DTO
|
||||
get
|
||||
{
|
||||
int answ = 0;
|
||||
if(NumPezzi < PezziProd)
|
||||
if (NumPezzi < PezziProd)
|
||||
{
|
||||
answ = Math.Abs(NumPezzi - PezziProd);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace MP.Core.DTO
|
||||
namespace MP.Core.DTO
|
||||
{
|
||||
public class ParetoFluxLogDTO
|
||||
{
|
||||
public string IdxMacchina { get; set; }
|
||||
public string CodFlux { get; set; }
|
||||
public string IdxMacchina { get; set; } = string.Empty;
|
||||
public string CodFlux { get; set; } = string.Empty;
|
||||
public int Qty { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public List<ULogDataDto> fluxData { get; set; }
|
||||
public List<ULogDataDto> fluxData { get; set; } = new();
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
+20
-23
@@ -12,34 +12,29 @@ namespace MP.Core
|
||||
|
||||
public const string redisAnagGruppi = redisBaseAddr + "Cache:AnagGruppi";
|
||||
public const string redisAnagStati = redisBaseAddr + "Cache:AnagStati";
|
||||
public const string redisAnagGruppiOpr = redisBaseAddr + "Cache:GrpByOpr";
|
||||
|
||||
public const string redisArtByDossier = redisBaseAddr + "Cache:ArtByDossier";
|
||||
|
||||
public const string redisArtList = redisBaseAddr + "Cache:ArtList";
|
||||
|
||||
public const string redisBaseAddr = "MP:";
|
||||
|
||||
public const string redisConfFlux = redisBaseAddr + "Cache:ConfFlux";
|
||||
public const string redisConfAll = redisBaseAddr + "Cache:ConfigAll";
|
||||
public const string redisConfKey = redisBaseAddr + "Cache:Config";
|
||||
|
||||
public const string redisDecNumArtKey = redisBaseAddr + "Cache:DecNumArt";
|
||||
|
||||
public const string redisDossByMac = redisBaseAddr + "Cache:DossByMac";
|
||||
public const string redisDossByMacLast = redisBaseAddr + "Cache:DossByMacLast";
|
||||
|
||||
public const string redisEventList = redisBaseAddr + "Cache:EventList";
|
||||
|
||||
public const string redisFluxByMac = redisBaseAddr + "Cache:FluxByMac";
|
||||
public const string redisFluxByMacFirst = redisBaseAddr + "Cache:FluxByMacFirst";
|
||||
public const string redisFluxLogFilt = redisBaseAddr + "Cache:FluxLogFilt";
|
||||
|
||||
public const string redisGiacenzaList = redisBaseAddr + "Cache:GiacenzaList";
|
||||
|
||||
public const string redisKit = redisBaseAddr + "Cache:Kit";
|
||||
public const string redisKitInst = redisBaseAddr + "Cache:Kit:Inst";
|
||||
public const string redisKitScore = redisBaseAddr + "Cache:Kit:Score";
|
||||
public const string redisKitTempl = redisBaseAddr + "Cache:Kit:Templ";
|
||||
public const string redisKitWip = redisBaseAddr + "Cache:Kit:Wip";
|
||||
public const string redisIobConf = redisBaseAddr + "Cache:IobConf";
|
||||
public const string redisLinkMenu = redisBaseAddr + "Cache:LinkMenu";
|
||||
public const string redisMacByFlux = redisBaseAddr + "Cache:MacByFlux";
|
||||
|
||||
public const string redisMacList = redisBaseAddr + "Cache:MacList";
|
||||
@@ -49,11 +44,13 @@ namespace MP.Core
|
||||
public const string redisMacRecipePath = redisBaseAddr + "Cache:RecipePath";
|
||||
|
||||
public const string redisOdlByBatch = redisXdlData + "OdlByBatch";
|
||||
public const string redisOdlByKey = redisXdlData + "OdlByKey";
|
||||
|
||||
public const string redisOdlCurrByMac = redisXdlData + "OdlByMac";
|
||||
public const string redisOdlLastByMac = redisXdlData + "LastOdlByMac";
|
||||
|
||||
public const string redisOdlList = redisXdlData + "OdlList";
|
||||
public const string redisOdlStats = redisXdlData + "OdlStats";
|
||||
|
||||
public const string redisOprList = redisBaseAddr + "Cache:OprList";
|
||||
|
||||
@@ -88,12 +85,12 @@ namespace MP.Core
|
||||
|
||||
public static string redKeyArtUsed
|
||||
{
|
||||
get => RedHash($"SPEC:Cache:CheckArtUsed");
|
||||
get => RedHash($"SPEC:Cache:CheckArtUsed").ToString();
|
||||
}
|
||||
|
||||
public static string redKeyTabCheckArt
|
||||
{
|
||||
get => RedHash($"CACHE:TabCheckArt");
|
||||
get => RedHash($"CACHE:TabCheckArt").ToString();
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
@@ -180,7 +177,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyCurrObjItems(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyCurrObjItems(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:CurrentParameters:{idxMacchina}";
|
||||
@@ -192,7 +189,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyDatiMacc(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyDatiMacc(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:DtMac:{idxMacchina}";
|
||||
@@ -212,7 +209,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyIobConfYaml(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyIobConfYaml(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:IOB:{idxMacchina}:ConfYaml";
|
||||
@@ -224,7 +221,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyIobMemMap(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyIobMemMap(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:MemMap:{idxMacchina}";
|
||||
@@ -237,7 +234,7 @@ namespace MP.Core
|
||||
/// <param name="flog"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyLastFLog(string idxMacchina, string flog, string baseAddr = null)
|
||||
public static RedisKey RedKeyLastFLog(string idxMacchina, string flog, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:FLOG:{idxMacchina}:{flog}";
|
||||
@@ -249,7 +246,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr"></param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyMach2Iob(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyMach2Iob(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:hM2IOB:{idxMacchina}";
|
||||
@@ -261,7 +258,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr"></param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyMachIobConf(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyMachIobConf(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:IOB:{idxMacchina}:MachIobConf";
|
||||
@@ -273,7 +270,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyMsmi(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyMsmi(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
|
||||
@@ -285,7 +282,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyOptPar(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyOptPar(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:OptPar:{idxMacchina}";
|
||||
@@ -297,7 +294,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyPzCount(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyPzCount(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:PzCount:{idxMacchina}";
|
||||
@@ -309,7 +306,7 @@ namespace MP.Core
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeySavedTask2ExeMacc(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeySavedTask2ExeMacc(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:SavedTask:{idxMacchina}";
|
||||
@@ -321,7 +318,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyTask2ExeMacc(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyTask2ExeMacc(string idxMacchina, string? baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:ExeTask:{idxMacchina}";
|
||||
|
||||
@@ -15,15 +15,30 @@ namespace MP.Data.Controllers
|
||||
{
|
||||
public class MpIocController
|
||||
{
|
||||
protected readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
#region Public Constructors
|
||||
|
||||
public MpIocController(IConfiguration configuration)
|
||||
public MpIocController(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_configuration = configuration;
|
||||
string connStr = _configuration.GetConnectionString("MP.Data");
|
||||
#if false
|
||||
_configuration = configuration;
|
||||
#endif
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
#if false
|
||||
string connStr = configuration.GetConnectionString("MP.Data");
|
||||
options = new DbContextOptionsBuilder<MoonProContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
string connStrFlux = configuration.GetConnectionString("MP.Flux");
|
||||
optionsFlux = new DbContextOptionsBuilder<MoonPro_FluxContext>()
|
||||
.UseSqlServer(connStrFlux)
|
||||
.Options;
|
||||
#endif
|
||||
Log.Info("Avviata classe MpIocController");
|
||||
}
|
||||
|
||||
@@ -43,7 +58,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AlarmLogInsertAsync(DateTime dtRif, string machineId, string memAddress, int memIndex, int statusVal, string valDecoded)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var DtRif = new SqlParameter("@DtRif", dtRif);
|
||||
var MachineId = new SqlParameter("@MachineId", machineId);
|
||||
@@ -63,7 +78,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagStatiModel>> AnagStatiGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetAnagStati
|
||||
@@ -81,7 +96,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetLastByMaccAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var dbResult = await dbCtx
|
||||
@@ -107,7 +122,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AutoStartOdlAsync(int idxOdl, int MatrOpr, string idxMacchina, decimal tCRich, int pzPallet, string note, bool startNewOdl, int qtyRich, string keyRich)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxOdl = new SqlParameter("@idxOdl ", idxOdl);
|
||||
var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
|
||||
@@ -138,7 +153,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CheckCambiaStatoBatchAsync(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet)
|
||||
{
|
||||
await using var dbCtx = new MoonProContext(options);
|
||||
await using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
//await using var tx = await dbCtx.Database.BeginTransactionAsync();
|
||||
|
||||
try
|
||||
@@ -224,7 +239,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfermaProdMacchinaAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra ", DateTime.Now);
|
||||
@@ -267,7 +282,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfermaProdMacchinaFullAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzLasciati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra ", DateTime.Now);
|
||||
@@ -306,7 +321,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfFluxModel>> ConfFluxFiltAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = _ctxFactoryFL.CreateDbContext();
|
||||
|
||||
var query = dbCtx.DbSetConfFlux
|
||||
.AsNoTracking()
|
||||
@@ -326,7 +341,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetConfig
|
||||
@@ -343,17 +358,17 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfigUpdateAsync(ConfigModel updRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
bool fatto = false;
|
||||
var dbResult = dbCtx
|
||||
.DbSetConfig
|
||||
.Where(x => x.Chiave == updRec.Chiave)
|
||||
.FirstOrDefault();
|
||||
var dbResult = await dbCtx
|
||||
.DbSetConfig
|
||||
.Where(x => x.Chiave == updRec.Chiave)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbResult != null)
|
||||
{
|
||||
dbResult.Valore = updRec.Valore;
|
||||
fatto = dbCtx.SaveChanges() > 0;
|
||||
fatto = await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
return fatto;
|
||||
@@ -365,7 +380,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<DatiMacchineModel>> DatiMacchineGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetDatiMacchine
|
||||
@@ -388,7 +403,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DDB_InsStatoBatchAsync(string idxMacchina, DateTime inizioStato, int idxStato, string codArt, string value, int matrOpr, string pallet)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var InizioStato = new SqlParameter("@InizioStato", inizioStato);
|
||||
@@ -411,7 +426,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<DecNumArticoliModel>> DecNumArtGetFiltAsync(string codArt = "")
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var query = dbCtx.DbSetDecNumArt
|
||||
.AsNoTracking()
|
||||
@@ -432,17 +447,13 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<DossierModel>> DossGetLastByMaccAsync(string idxMacc)
|
||||
{
|
||||
List<DossierModel> dbResult = new();
|
||||
using (var dbCtx = new MoonPro_FluxContext(_configuration))
|
||||
{
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
dbResult = await dbCtx
|
||||
.DbSetDossiers
|
||||
.FromSqlRaw("exec dbo.stp_DOSS_getLastByMacch @idxMacchina", IdxMacchina)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.FromSqlRaw("exec dbo.stp_DOSS_getLastByMacch @idxMacchina", IdxMacchina)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -452,7 +463,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EvListInsertAsync(EventListModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbCtx.DbSetEvList.Add(newRec);
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
@@ -467,7 +478,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> EvListMicroStatoInsertAsync(MicroStatoMacchinaModel newRecMsm, EventListModel newRecEv)
|
||||
{
|
||||
// eseguo in transazione...
|
||||
await using var dbCtx = new MoonProContext(options);
|
||||
await using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
await using var tx = await dbCtx.Database.BeginTransactionAsync();
|
||||
|
||||
try
|
||||
@@ -518,18 +529,15 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<FluxLogModel>> FluxLogFirstByMaccAsync(string idxMacc, int numMax)
|
||||
{
|
||||
List<FluxLogModel> dbResult = new();
|
||||
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var NumMax = new SqlParameter("@numMax", numMax);
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetFluxLog
|
||||
.FromSqlRaw("exec dbo.stp_FL_getFirstByMacc @IdxMacchina, @numMax", IdxMacchina, NumMax)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.FromSqlRaw("exec dbo.stp_FL_getFirstByMacc @IdxMacchina, @numMax", IdxMacchina, NumMax)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -543,17 +551,15 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<FluxLogModel>> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec)
|
||||
{
|
||||
List<FluxLogModel> dbResult = new List<FluxLogModel>();
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux))
|
||||
.OrderByDescending(x => x.dtEvento)
|
||||
.Take(MaxRec)
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux))
|
||||
.OrderByDescending(x => x.dtEvento)
|
||||
.Take(MaxRec)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -563,15 +569,13 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FluxLogInsertAsync(FluxLogModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
|
||||
var currRec = dbCtx
|
||||
.DbSetFluxLog
|
||||
.Add(newRec);
|
||||
await dbCtx.SaveChangesAsync();
|
||||
.DbSetFluxLog
|
||||
.Add(newRec);
|
||||
return await dbCtx.SaveChangesAsync()>0;
|
||||
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -581,8 +585,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FluxLogTakeSnapshotLastAsync(string idxMacc, DateTime dataInizio, DateTime dataFine)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var DataInizio = new SqlParameter("@DtMin", dataInizio);
|
||||
@@ -591,8 +594,7 @@ namespace MP.Data.Controllers
|
||||
var result = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_FL_TakeSnapshotLast @IdxMacchina, @DtMin, @DtMax", IdxMacchina, DataInizio, DataFine);
|
||||
fatto = result > 0;
|
||||
return fatto;
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -605,7 +607,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> KeepAliveUpsertAsync(string IdxMacc, DateTime OraServer, DateTime OraMacc)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var currRec = await dbCtx
|
||||
.DbSetKeepAlive
|
||||
@@ -638,7 +640,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink)
|
||||
{
|
||||
List<LinkMenuModel> dbResult = new List<LinkMenuModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetLinkMenu
|
||||
@@ -658,7 +660,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<ListValuesModel>> ListValuesFiltAsync(string tabName, string fieldName)
|
||||
{
|
||||
List<ListValuesModel> dbResult = new List<ListValuesModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var query = dbCtx
|
||||
.DbSetListValues
|
||||
@@ -682,7 +684,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<Macchine2SlaveModel>> Macchine2SlaveAsync()
|
||||
{
|
||||
List<Macchine2SlaveModel> dbResult = new List<Macchine2SlaveModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetM2S
|
||||
@@ -700,7 +702,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MacchineModel>> MacchineGetAllAsync()
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchine
|
||||
@@ -712,7 +714,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<MacchineModel?> MacchineGetByIdxAsync(string IdxMacchina)
|
||||
{
|
||||
MacchineModel dbResult = null;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchine
|
||||
@@ -729,7 +731,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
@@ -763,7 +765,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> MacchineUpsertAsync(MacchineModel entity)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
// Recuperiamo l'entità tracciata dal context
|
||||
var trackedEntity = await dbCtx
|
||||
@@ -791,7 +793,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MicroStatoMacchinaModel>> MicroStatoMacchinaGetByIdxMaccAsync(string IdxMacc)
|
||||
{
|
||||
List<MicroStatoMacchinaModel> dbResult = new List<MicroStatoMacchinaModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetMicroStatoMacc
|
||||
@@ -809,7 +811,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> MicroStatoMacchinaUpsertAsync(MicroStatoMacchinaModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var actRec = await dbCtx
|
||||
.DbSetMicroStatoMacc
|
||||
@@ -842,7 +844,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
|
||||
{
|
||||
List<MappaStatoExplModel> dbResult = new List<MappaStatoExplModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
||||
|
||||
@@ -862,7 +864,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlAutoDayGenAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataInizio = new SqlParameter("@DataInizio", dataInizio);
|
||||
@@ -884,7 +886,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlAutoDayGenFullAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo, int? pzPODL, int? pzPallet, string? keyRichiesta, int? tcAssegnato, string? codGruppo, bool flgCreaPODL, bool flgCheckTC)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataInizio = new SqlParameter("@DataInizio", dataInizio);
|
||||
@@ -913,7 +915,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<ODLExpModel> OdlCurrByMaccAsync(string idxMacchina)
|
||||
{
|
||||
ODLExpModel answ = new();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
// attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!!
|
||||
@@ -936,7 +938,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlFixMachineSlave(string idxMacchina, int numDayPrev, int doInsert)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var idxMaccParam = new SqlParameter("@IdxMacchina", idxMacchina ?? "");
|
||||
var numDayPrevParam = new SqlParameter("@NumDayPrev", numDayPrev);
|
||||
@@ -958,7 +960,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlFixMachineSlaveAsync(string idxMacchina, int numDayPrev, int doInsert)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var NumDayPrev = new SqlParameter("@NumDayPrev", numDayPrev);
|
||||
@@ -977,7 +979,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<ODLExpModel> OdlLastByMaccAsync(string idxMacchina)
|
||||
{
|
||||
ODLExpModel answ = new();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
// attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!!
|
||||
@@ -1001,7 +1003,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<ODLExpModel>> OdlListByMaccPeriodoAsync(string idxMacchina, DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
List<ODLExpModel> dbResult = new List<ODLExpModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataFrom = new SqlParameter("@dataFrom", dtStart);
|
||||
@@ -1023,7 +1025,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<PzProdModel> PezziProdMacchinaAsync(string idxMacchina)
|
||||
{
|
||||
PzProdModel dbResult = new PzProdModel();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
dbResult = (await dbCtx
|
||||
@@ -1046,7 +1048,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<PODLExpModel>> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree)
|
||||
{
|
||||
List<PODLExpModel> dbResult = new List<PODLExpModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var pCodArticolo = new SqlParameter("@CodArticolo", codArticolo);
|
||||
@@ -1069,7 +1071,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RecalcMseAsync(string idxMacchina, int maxAgeSec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var rigaProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now);
|
||||
var MaxAgeSec = new SqlParameter("@maxAgeSec ", maxAgeSec);
|
||||
@@ -1093,7 +1095,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegControlliInsertAsync(string idxMacchina, int matrOpr, bool esitoOk, string note, DateTime dataOra)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var MatrOpr = new SqlParameter("@MatrOpr", matrOpr);
|
||||
@@ -1114,7 +1116,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegDichiarInsertAsync(RegistroDichiarazioniModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var TagCode = new SqlParameter("@TagCode", newRec.TagCode);
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", newRec.IdxMacchina);
|
||||
@@ -1136,7 +1138,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegDichiarUpdateAsync(RegistroDichiarazioniModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var Original_IdxDich = new SqlParameter("@Original_IdxDich", newRec.IdxDich);
|
||||
var DtRec = new SqlParameter("@DtRec", newRec.DtRec);
|
||||
@@ -1157,7 +1159,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegScartiInsertAsync(RegistroScartiModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@idxMacchina", newRec.IdxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra", newRec.DataOra);
|
||||
@@ -1184,7 +1186,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> RemRebootLogAddAndCleanAsync(RemoteRebootLogModel newRec, bool doClean, int num2keep)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
// 1. Transazione minima: SOLO INSERT + COMMIT
|
||||
await using var tx = await dbCtx.Database.BeginTransactionAsync();
|
||||
@@ -1227,7 +1229,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemRebootLogAddAsync(RemoteRebootLogModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
@@ -1242,7 +1244,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetRemRebLog
|
||||
@@ -1258,7 +1260,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
var dbResult = await dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
@@ -1273,7 +1275,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemRebootLogKeepLastAsync(int num2keep)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pNum2Keep = new SqlParameter("@num2keep", num2keep);
|
||||
// La SP gestisce già la logica di soglia (1.5x), ma la specifico x sicurezza
|
||||
@@ -1291,7 +1293,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SignalLogInsertAsync(SignalLogModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var currRec = dbCtx
|
||||
.DbSetSignalLog
|
||||
@@ -1307,7 +1309,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<TransizioneStatiModel>> SMES_getHwTransitionsAsync(string idxMacchina, int idxTipo)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
|
||||
@@ -1327,7 +1329,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<TransizioneStatiModel>> SMES_getUserForcedAsync(string idxMacchina, int idxTipo)
|
||||
{
|
||||
await using var dbCtx = new MoonProContext(options);
|
||||
await using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
|
||||
@@ -1346,18 +1348,14 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public List<TransizioneIngressiModel> StateMachineIngressi(int idxFam)
|
||||
{
|
||||
List<TransizioneIngressiModel> dbResult = new List<TransizioneIngressiModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
|
||||
dbResult = dbCtx
|
||||
.DbSetSMI
|
||||
.FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn)
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
|
||||
return dbCtx
|
||||
.DbSetSMI
|
||||
.FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn)
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1366,7 +1364,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<TransizioneIngressiModel>> StateMachineIngressiAsync(int idxFam)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
|
||||
var dbResult = await dbCtx
|
||||
@@ -1386,7 +1384,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<StatoProdModel> StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra ", dtReq);
|
||||
@@ -1406,7 +1404,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<VMSFDModel>> VMSFDGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetMSFD
|
||||
@@ -1424,7 +1422,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<VMSFDModel?> VMSFDGetByMaccAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var dbResult = (await dbCtx
|
||||
@@ -1444,7 +1442,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<VMSFDModel>> VMSFDGetMultiByMaccAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
|
||||
@@ -1461,9 +1459,14 @@ namespace MP.Data.Controllers
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
#if false
|
||||
private static IConfiguration _configuration;
|
||||
#endif
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private DbContextOptions<MoonProContext> options;
|
||||
#if false
|
||||
private DbContextOptions<MoonProContext> options;
|
||||
#endif
|
||||
private DbContextOptions<MoonPro_FluxContext> optionsFlux;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
|
||||
@@ -15,18 +15,30 @@ namespace MP.Data.Controllers
|
||||
public class MpLandController : IDisposable
|
||||
{
|
||||
#region Public Constructors
|
||||
protected readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
protected readonly IDbContextFactory<MoonPro_STATSContext> _ctxFactorySta;
|
||||
|
||||
public MpLandController(IConfiguration configuration)
|
||||
public MpLandController(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL,
|
||||
IDbContextFactory<MoonPro_STATSContext> ctxFactorySta)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
_ctxFactorySta = ctxFactorySta;
|
||||
#if false
|
||||
string connStr = _configuration.GetConnectionString("MP.Land");
|
||||
if(string.IsNullOrEmpty(connStr))
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
connStr = _configuration.GetConnectionString("MP.Data");
|
||||
}
|
||||
options = new DbContextOptionsBuilder<MoonProContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
.Options;
|
||||
#endif
|
||||
Log.Info("Avviato MpLandController");
|
||||
}
|
||||
|
||||
@@ -34,6 +46,7 @@ namespace MP.Data.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Restituisce info dimensione, tabelle e num righe DB gestiti
|
||||
/// </summary>
|
||||
@@ -70,58 +83,53 @@ namespace MP.Data.Controllers
|
||||
// leggo per DB principale
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All")))
|
||||
{
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
// leggo per FluxLog
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux")))
|
||||
{
|
||||
using (var dbCtx = new MoonPro_FluxContext(_configuration))
|
||||
using var dbCtx = _ctxFactoryFL.CreateDbContext();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
// leggo per Stats
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats")))
|
||||
{
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using var dbCtx = _ctxFactorySta.CreateDbContext();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in AllDbInfo:{Environment.NewLine}{exc}");
|
||||
Log.Error($"Eccezione in AllDbInfoAsync:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elenco da tabella Config
|
||||
@@ -130,20 +138,18 @@ namespace MP.Data.Controllers
|
||||
public List<ConfigModel> ConfigGetAll()
|
||||
{
|
||||
List<ConfigModel> dbResult = new List<ConfigModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_configuration = null;
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,16 +159,13 @@ namespace MP.Data.Controllers
|
||||
public List<AnagOperatoriModel> ElencoOperatori()
|
||||
{
|
||||
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => s.MatrOpr > 0)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => s.MatrOpr > 0)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -172,13 +175,10 @@ namespace MP.Data.Controllers
|
||||
public List<MacchineModel> MacchineGetAll()
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using (MoonProContext localDbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetMacchine
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetMacchine
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -188,15 +188,12 @@ namespace MP.Data.Controllers
|
||||
public List<RemoteRebootLogModel> RemRebootLogGetAll()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.IdxReboot)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetRemRebLog
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.IdxReboot)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -206,15 +203,12 @@ namespace MP.Data.Controllers
|
||||
public List<RemoteRebootLogModel> RemRebootLogGetLast()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -224,15 +218,12 @@ namespace MP.Data.Controllers
|
||||
public List<RemoteRebootLogModel> RemRebootLogGetLastNoMacc()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_GetLastNoMachine")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_GetLastNoMachine")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -243,7 +234,7 @@ namespace MP.Data.Controllers
|
||||
public bool RollBackEntity(object item)
|
||||
{
|
||||
bool answ = false;
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -262,11 +253,30 @@ namespace MP.Data.Controllers
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private DbContextOptions<MoonProContext> options;
|
||||
private readonly IConfiguration _configuration;
|
||||
#if false
|
||||
private readonly DbContextOptions<MoonProContext> options;
|
||||
#endif
|
||||
private bool _disposed = false;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -19,11 +19,15 @@ namespace MP.Data.Controllers
|
||||
public MpStatsController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
string connStr = _configuration.GetConnectionString("MP.Stats");
|
||||
options = new DbContextOptionsBuilder<MoonPro_STATSContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
Log.Info("Avviata classe MpStatsController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
private DbContextOptions<MoonPro_STATSContext> options;
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
@@ -33,13 +37,10 @@ namespace MP.Data.Controllers
|
||||
public List<AzioniUL> ActionsGetAll()
|
||||
{
|
||||
List<AzioniUL> dbResult = new List<AzioniUL>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
using var dbCtx = new MoonPro_STATSContext(options);
|
||||
return dbCtx
|
||||
.DbSetAzioniUL
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,13 +50,10 @@ namespace MP.Data.Controllers
|
||||
public List<AnagFLTransModel> AnagFLTransGetAll()
|
||||
{
|
||||
List<AnagFLTransModel> dbResult = new List<AnagFLTransModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetAnagFLTrans
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = new MoonPro_STATSContext(options);
|
||||
return dbCtx
|
||||
.DbSetAnagFLTrans
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +65,7 @@ namespace MP.Data.Controllers
|
||||
public List<StatsAnagArticoli> ArticoliGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<StatsAnagArticoli> dbResult = new List<StatsAnagArticoli>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetArticoli
|
||||
@@ -88,7 +86,7 @@ namespace MP.Data.Controllers
|
||||
public List<StatsODL> CommesseGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<StatsODL> dbResult = new List<StatsODL>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetODL
|
||||
@@ -107,7 +105,7 @@ namespace MP.Data.Controllers
|
||||
public List<ConfigModel> ConfigGetAll()
|
||||
{
|
||||
List<ConfigModel> dbResult = new List<ConfigModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetConfig
|
||||
@@ -133,7 +131,7 @@ namespace MP.Data.Controllers
|
||||
public List<FLModel> FluxLogRawData(string IdxMacchina, DateTime DtStart, DateTime DtEnd, string fluxType)
|
||||
{
|
||||
List<FLModel> dbResult = new List<FLModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetFL
|
||||
@@ -153,7 +151,7 @@ namespace MP.Data.Controllers
|
||||
public List<string> FluxTypeList()
|
||||
{
|
||||
List<string> dbResult = new List<string>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetFL
|
||||
@@ -172,7 +170,7 @@ namespace MP.Data.Controllers
|
||||
public List<MacchineStatModel> MacchineEnergy()
|
||||
{
|
||||
List<MacchineStatModel> dbResult = new List<MacchineStatModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetMaccStat
|
||||
@@ -188,7 +186,7 @@ namespace MP.Data.Controllers
|
||||
public List<MacchineModel> MacchineGetAll()
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetMacchine
|
||||
@@ -204,7 +202,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MaccEnergyCheckModel>> MacchineEnergyCheckGetAllAsync()
|
||||
{
|
||||
List<MaccEnergyCheckModel> dbResult = new List<MaccEnergyCheckModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchineCheck
|
||||
@@ -222,7 +220,7 @@ namespace MP.Data.Controllers
|
||||
public bool RollBackEntity(object item)
|
||||
{
|
||||
bool answ = false;
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -248,7 +246,7 @@ namespace MP.Data.Controllers
|
||||
public List<ResControlli> StatControlliGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<ResControlli> dbResult = new List<ResControlli>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -280,7 +278,7 @@ namespace MP.Data.Controllers
|
||||
public List<DdbTurni> StatDdbGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, int FirstRecord, int NumRecord)
|
||||
{
|
||||
List<DdbTurni> dbResult = new List<DdbTurni>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -312,7 +310,7 @@ namespace MP.Data.Controllers
|
||||
public int StatDdbGetCount(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
int numResult = 0;
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
numResult = dbCtx
|
||||
.DbSetDdbTurni
|
||||
@@ -335,7 +333,7 @@ namespace MP.Data.Controllers
|
||||
public List<OdlEnergyModel> StatOdlEnergyGetFilt(string IdxMacchina, DateTime DtStart, DateTime DtEnd, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<OdlEnergyModel> dbResult = new List<OdlEnergyModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DtStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DtEnd);
|
||||
@@ -361,7 +359,7 @@ namespace MP.Data.Controllers
|
||||
public List<StatsODL> StatOdlGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<StatsODL> dbResult = new List<StatsODL>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -389,7 +387,7 @@ namespace MP.Data.Controllers
|
||||
public List<ResScarti> StatScartiGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<ResScarti> dbResult = new List<ResScarti>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -417,7 +415,7 @@ namespace MP.Data.Controllers
|
||||
public List<TurniOee> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<TurniOee> dbResult = new List<TurniOee>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -443,7 +441,7 @@ namespace MP.Data.Controllers
|
||||
public List<UserActionLog> StatUserLogGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<UserActionLog> dbResult = new List<UserActionLog>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -467,7 +465,7 @@ namespace MP.Data.Controllers
|
||||
public List<VocabolarioModel> VocabolarioGetAll()
|
||||
{
|
||||
List<VocabolarioModel> dbResult = new List<VocabolarioModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetVocabolario
|
||||
|
||||
@@ -688,7 +688,7 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante EvListInsert{Environment.NewLine}{exc}");
|
||||
Log.Error($"Eccezione durante EvListInsertAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
@@ -1029,7 +1029,7 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in MacchineByMatrOper{Environment.NewLine}{exc}");
|
||||
Log.Error($"Eccezione in MacchineByMatrOperAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
@@ -1709,7 +1709,7 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PODL_getByKey{Environment.NewLine}{exc}");
|
||||
Log.Error($"Eccezione durante PODL_getByKeyAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
using DnsClient.Protocol;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using static MP.Core.Objects.Enums;
|
||||
|
||||
namespace MP.Data.Controllers
|
||||
{
|
||||
@@ -19,6 +15,10 @@ namespace MP.Data.Controllers
|
||||
public MpVocController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
string connStr = _configuration.GetConnectionString("MP.Voc");
|
||||
options = new DbContextOptionsBuilder<MoonPro_VocContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
Log.Info("Avviata classe MpVocController");
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace MP.Data.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
private DbContextOptions<MoonPro_VocContext> options;
|
||||
/// <summary>
|
||||
/// Elenco da tabella Config
|
||||
/// </summary>
|
||||
@@ -33,15 +34,12 @@ namespace MP.Data.Controllers
|
||||
public List<ConfigModel> ConfigGetAll()
|
||||
{
|
||||
List<ConfigModel> dbResult = new List<ConfigModel>();
|
||||
using (var dbCtx = new MoonPro_VocContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = new MoonPro_VocContext(options);
|
||||
return dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -55,15 +53,12 @@ namespace MP.Data.Controllers
|
||||
public List<LingueModel> LingueGetAll()
|
||||
{
|
||||
List<LingueModel> dbResult = new List<LingueModel>();
|
||||
using (var dbCtx = new MoonPro_VocContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetLilngue
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Lingua)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = new MoonPro_VocContext(options);
|
||||
return dbCtx
|
||||
.DbSetLilngue
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Lingua)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,15 +68,12 @@ namespace MP.Data.Controllers
|
||||
public List<VocabolarioModel> VocabolarioGetAll()
|
||||
{
|
||||
List<VocabolarioModel> dbResult = new List<VocabolarioModel>();
|
||||
using (var dbCtx = new MoonPro_VocContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetVocabolario
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Lemma)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = new MoonPro_VocContext(options);
|
||||
return dbCtx
|
||||
.DbSetVocabolario
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Lemma)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using MP.AppAuth.Controllers;
|
||||
using MP.AppAuth.Services;
|
||||
using MP.Data.Controllers;
|
||||
using MP.Data.Repository.Anag;
|
||||
using MP.Data.Repository.Dossier;
|
||||
using MP.Data.Repository.FluxLog;
|
||||
using MP.Data.Repository.IOC;
|
||||
using MP.Data.Repository.MpLand;
|
||||
using MP.Data.Repository.MpMon;
|
||||
using MP.Data.Repository.MpVoc;
|
||||
using MP.Data.Repository.Mtc;
|
||||
using MP.Data.Repository.Production;
|
||||
using MP.Data.Repository.System;
|
||||
using MP.Data.Repository.Utils;
|
||||
using MP.Data.Services;
|
||||
using MP.Data.Services.IOC;
|
||||
using MP.Data.Services.Mtc;
|
||||
using MP.Data.Services.Utils;
|
||||
@@ -12,10 +23,18 @@ namespace MP.Data
|
||||
{
|
||||
public static class DataServiceCollectionExtensions
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per IOC
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddIocDataLayer(this IServiceCollection services)
|
||||
{
|
||||
// Repository Singleton
|
||||
services.TryAddSingleton<IMtcSetupRepository, MtcSetupRepository>();
|
||||
services.TryAddSingleton<IProductionRepository, ProductionRepository>();
|
||||
|
||||
// Repository Scoped
|
||||
services.TryAddScoped<IIocRepository, IocRepository>();
|
||||
@@ -33,5 +52,122 @@ namespace MP.Data
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per LAND
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddLandDataLayer(this IServiceCollection services)
|
||||
{
|
||||
// Controllers MP.AppAuth (dipendenze di AppAuthService)
|
||||
services.TryAddScoped<AppAuthController>();
|
||||
services.TryAddScoped<MPController>();
|
||||
services.TryAddScoped<AppUserController>();
|
||||
|
||||
// Servizi LAND
|
||||
services.TryAddSingleton<IMpLandRepository, MpLandRepository>();
|
||||
services.TryAddSingleton<MpIocController>();
|
||||
services.TryAddSingleton<SyncService>();
|
||||
services.TryAddSingleton<TabDataService>();
|
||||
services.TryAddSingleton<LandDataService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per MON
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddMonDataLayer(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddSingleton<IMpMonRepository, MpMonRepository>();
|
||||
services.TryAddSingleton<MonDataFeeder>();
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per SPEC
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddSpecDataLayer(this IServiceCollection services)
|
||||
{
|
||||
// ---------- Start Repository ----------
|
||||
services.TryAddScoped<IAnagRepository, AnagRepository>();
|
||||
|
||||
services.TryAddScoped<IProductionRepository, ProductionRepository>();
|
||||
services.TryAddScoped<IDossierRepository, DossierRepository>();
|
||||
services.TryAddScoped<IFluxLogRepository, FluxLogRepository>();
|
||||
services.TryAddScoped<ISystemRepository, SystemRepository>();
|
||||
services.TryAddScoped<IMpMonRepository, MpMonRepository>();
|
||||
services.TryAddScoped<IMpVocRepository, MpVocRepository>();
|
||||
services.TryAddScoped<IMpLandRepository, MpLandRepository>();
|
||||
// ---------- End Repository ----------
|
||||
|
||||
// ---------- Start Servizi ----------
|
||||
//services.TryAddSingleton<MpDataService>();
|
||||
// ---------- End Servizi ----------
|
||||
|
||||
// ---------- Start Altro ----------
|
||||
services.TryAddSingleton<MpIocController>();
|
||||
services.TryAddScoped<AppAuthController>();
|
||||
services.TryAddScoped<MPController>();
|
||||
services.TryAddScoped<AppUserController>();
|
||||
services.TryAddScoped<AppAuthService>();
|
||||
services.TryAddScoped<OrderDataSrv>();
|
||||
services.TryAddScoped<ListSelectDataSrv>();
|
||||
services.TryAddSingleton<SharedMemService>();
|
||||
services.TryAddSingleton<TabDataService>();
|
||||
services.TryAddScoped<TabDataFeeder>();
|
||||
services.AddScoped<ISessionStorageService, SessionStorageService>();
|
||||
services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||
// ---------- End Altro ----------
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per STATS
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddStatsDataLayer(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IMpVocRepository, MpVocRepository>();
|
||||
|
||||
services.AddSingleton<TranslateSrv>();
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per TAB
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddTabDataLayer(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddSingleton<IAnagRepository, AnagRepository>();
|
||||
services.TryAddSingleton<IProductionRepository, ProductionRepository>();
|
||||
services.TryAddSingleton<IMpMonRepository, MpMonRepository>();
|
||||
|
||||
services.TryAddSingleton<ISystemRepository, SystemRepository>();
|
||||
|
||||
services.TryAddSingleton<MpIocController>();
|
||||
services.TryAddSingleton<TabDataFeeder>();
|
||||
services.TryAddSingleton<StatusData>();
|
||||
services.TryAddSingleton<ListSelectDataSrv>();
|
||||
services.TryAddSingleton<OrderDataSrv>();
|
||||
services.TryAddSingleton<SharedMemService>();
|
||||
services.TryAddSingleton<TabDataService>();
|
||||
services.TryAddScoped<MessageService>();
|
||||
// aggiunta helper local/session storage service
|
||||
services.TryAddScoped<ISessionStorageService, SessionStorageService>();
|
||||
services.TryAddScoped<ILocalStorageService, LocalStorageService>();
|
||||
return services;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
@@ -16,6 +17,7 @@ namespace MP.Data.DbModels
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int AlarmLogId { get; set; } = 0;
|
||||
public DateTime DtRif { get; set; } = DateTime.Now;
|
||||
[Precision(18, 6)]
|
||||
public decimal Duration { get; set; } = 0;
|
||||
public string MachineId { get; set; } = "";
|
||||
public string MemAddress { get; set; } = "";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MP.Data.DbModels
|
||||
{
|
||||
@@ -6,6 +7,7 @@ namespace MP.Data.DbModels
|
||||
{
|
||||
[Key]
|
||||
public string DbName { get; set; } = "";
|
||||
[Precision(18, 6)]
|
||||
public decimal DbSizeMb { get; set; } = 0;
|
||||
public int NumTables { get; set; } = 0;
|
||||
public string BigTable { get; set; } = "";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
@@ -35,11 +36,13 @@ namespace MP.Data.DbModels
|
||||
/// <summary>
|
||||
/// Tempo Ciclo std
|
||||
/// </summary>
|
||||
[Precision(18, 6)]
|
||||
public decimal TCiclo { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Minuti prodotti (da TC e pz prod
|
||||
/// </summary>
|
||||
[Precision(18, 6)]
|
||||
public decimal MinProd { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +53,7 @@ namespace MP.Data.DbModels
|
||||
[NotMapped]
|
||||
public bool IsWork
|
||||
{
|
||||
get => IdxTipoEv == 1;
|
||||
get => IdxTipoEv == 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
@@ -19,7 +20,9 @@ namespace MP.Data.DbModels
|
||||
public string CodArticolo { get; set; } = "";
|
||||
public string IdxMacchina { get; set; }
|
||||
public int NumPezzi { get; set; }
|
||||
[Precision(18, 6)]
|
||||
public decimal Tcassegnato { get; set; }
|
||||
[Precision(18, 6)]
|
||||
public decimal TCRichAttr { get; set; }
|
||||
public DateTime? DataInizio { get; set; }
|
||||
public DateTime? DataFine { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
@@ -21,6 +22,7 @@ namespace MP.Data.DbModels
|
||||
[MaxLength(50)]
|
||||
public string IdxMacchina { get; set; }
|
||||
public int NumPezzi { get; set; }
|
||||
[Precision(18, 6)]
|
||||
public decimal Tcassegnato { get; set; }
|
||||
public DateTime? DataInizio { get; set; }
|
||||
public DateTime? DataFine { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
@@ -28,6 +29,7 @@ namespace MP.Data.DbModels
|
||||
[MaxLength(50)]
|
||||
public string IdxMacchina { get; set; }
|
||||
public int NumPezzi { get; set; } = 1;
|
||||
[Precision(18, 6)]
|
||||
public decimal Tcassegnato { get; set; } = 1;
|
||||
public DateTime? DueDate { get; set; }
|
||||
public int Priorita { get; set; } = 1;
|
||||
@@ -39,6 +41,8 @@ namespace MP.Data.DbModels
|
||||
public DateTime InsertDate { get; set; } = DateTime.Now;
|
||||
[MaxLength(500)]
|
||||
public string Recipe { get; set; } = "";
|
||||
public bool IsKitParent { get; set; } = false;
|
||||
public bool IsKitChild { get; set; } = false;
|
||||
|
||||
[NotMapped]
|
||||
public string CodFase
|
||||
@@ -66,7 +70,8 @@ namespace MP.Data.DbModels
|
||||
[NotMapped]
|
||||
public bool IsKit
|
||||
{
|
||||
get => KeyRichiesta.StartsWith("KIT");
|
||||
get => IsKitParent || IsKitChild; // KeyRichiesta.StartsWith("KIT");
|
||||
//get => KeyRichiesta.StartsWith("KIT");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,6 +79,7 @@ namespace MP.Data.DbModels
|
||||
/// </summary>
|
||||
[ForeignKey("IdxMacchina")]
|
||||
public virtual MacchineModel MachineNav { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Navigazione oggetto Articolo
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
@@ -29,6 +30,7 @@ namespace MP.Data.DbModels
|
||||
[MaxLength(50)]
|
||||
public string IdxMacchina { get; set; }
|
||||
public int NumPezzi { get; set; } = 1;
|
||||
[Precision(18, 6)]
|
||||
public decimal Tcassegnato { get; set; } = 1;
|
||||
public DateTime? DueDate { get; set; }
|
||||
public int Priorita { get; set; } = 1;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
@@ -24,10 +25,12 @@ namespace MP.Data.DbModels
|
||||
/// <summary>
|
||||
/// Score Cicli Associati
|
||||
/// </summary>
|
||||
[Precision(18, 6)]
|
||||
public decimal ChildScore { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// Score complessivo
|
||||
/// </summary>
|
||||
[Precision(18, 6)]
|
||||
public decimal TotalScore { get; set; } = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data
|
||||
{
|
||||
@@ -44,17 +44,17 @@ namespace MP.Data
|
||||
/// </summary>
|
||||
/// <param name="memKey">Chiave REDIS x salvare valore</param>
|
||||
/// <param name="message">Messaggio serializzato da inviare</param>
|
||||
public bool saveAndSendMessage(string memKey, string message)
|
||||
public async Task<bool> SaveAndSendMessageAsync(string memKey, string message)
|
||||
{
|
||||
bool answ = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
|
||||
// invio notifica tramite il canale richiesto
|
||||
answ = sendMessage(message);
|
||||
answ = await SendMessageAsync(message);
|
||||
if (redisDb != null)
|
||||
{
|
||||
redisDb.StringSetAsync(memKey, message);
|
||||
await redisDb.StringSetAsync(memKey, message);
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
@@ -68,7 +68,7 @@ namespace MP.Data
|
||||
}
|
||||
if (enableLog || numSent[memKey] > 30)
|
||||
{
|
||||
Log.Info($"saveAndSendMessage| mKey {memKey} x {numSent[memKey]} | {message.Length} size | {ts.TotalMilliseconds} ms");
|
||||
Log.Info($"SaveAndSendMessageAsync| mKey {memKey} x {numSent[memKey]} | {message.Length} size | {ts.TotalMilliseconds} ms");
|
||||
|
||||
numSent[memKey] = 0;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace MP.Data
|
||||
/// </summary>
|
||||
/// <param name="newMess"></param>
|
||||
/// <returns></returns>
|
||||
public bool sendMessage(string newMess)
|
||||
public async Task<bool> SendMessageAsync(string newMess)
|
||||
{
|
||||
bool answ = false;
|
||||
if (!string.IsNullOrEmpty(_channel))
|
||||
@@ -89,7 +89,7 @@ namespace MP.Data
|
||||
ISubscriber sub = redis.GetSubscriber();
|
||||
sub.Publish(_channel, newMess);
|
||||
#endif
|
||||
var numCli = redisSub.Publish(rChannel, newMess);
|
||||
var numCli = await redisSub.PublishAsync(rChannel, newMess);
|
||||
answ = numCli > 0;
|
||||
}
|
||||
return answ;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.DTO;
|
||||
using MP.Data.DbModels;
|
||||
using MP.Data.DbModels.Anag;
|
||||
using NLog;
|
||||
|
||||
#nullable disable
|
||||
// <Auto-Generated>
|
||||
@@ -12,27 +11,9 @@ namespace MP.Data
|
||||
{
|
||||
public partial class MoonProContext : DbContext
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
//public MoonProContext(IConfiguration configuration)
|
||||
//{
|
||||
// _configuration = configuration;
|
||||
//}
|
||||
|
||||
//public MoonProContext(DbContextOptions<MoonProContext> options, IConfiguration configuration)
|
||||
//: base(options)
|
||||
//{
|
||||
// _configuration = configuration;
|
||||
//}
|
||||
|
||||
public MoonProContext(DbContextOptions<MoonProContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
@@ -41,6 +22,7 @@ namespace MP.Data
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public virtual DbSet<CountResultDto> DbSetCounter { get; set; }
|
||||
|
||||
public virtual DbSet<DbSizeModel> DbSetDbSize { get; set; }
|
||||
public virtual DbSet<AlarmLogModel> DbSetAlarmLog { get; set; }
|
||||
@@ -90,7 +72,6 @@ namespace MP.Data
|
||||
public virtual DbSet<RegCheckModel> DbSetRegWithCheck { get; set; }
|
||||
public virtual DbSet<SignalLogModel> DbSetSignalLog { get; set; }
|
||||
|
||||
|
||||
public virtual DbSet<ST_Act> DbSetStAct { get; set; }
|
||||
public virtual DbSet<ST_ActRow> DbSetStActRow { get; set; }
|
||||
public virtual DbSet<ST_AnagGruppi> DbSetStAnagGruppi { get; set; }
|
||||
@@ -128,26 +109,8 @@ namespace MP.Data
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("MP.Data");
|
||||
if (string.IsNullOrEmpty(connString))
|
||||
{
|
||||
connString = _configuration.GetConnectionString("MP.All");
|
||||
}
|
||||
if (string.IsNullOrEmpty(connString))
|
||||
{
|
||||
connString = _configuration.GetConnectionString("MP.Land");
|
||||
}
|
||||
if (string.IsNullOrEmpty(connString))
|
||||
{
|
||||
connString = _configuration.GetConnectionString("MP.Mon");
|
||||
}
|
||||
if (string.IsNullOrEmpty(connString))
|
||||
{
|
||||
connString = _configuration.GetConnectionString("MP.STATS");
|
||||
}
|
||||
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
//optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;");
|
||||
// fallback si spera non necessario
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +118,10 @@ namespace MP.Data
|
||||
{
|
||||
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
|
||||
|
||||
|
||||
modelBuilder.Entity<CountResultDto>().HasNoKey();
|
||||
|
||||
|
||||
modelBuilder.Entity<StatsAnagArticoli>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.CodArticolo);
|
||||
|
||||
@@ -17,7 +17,9 @@ namespace MP.Data
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
#if false
|
||||
private IConfiguration _configuration;
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -27,15 +29,17 @@ namespace MP.Data
|
||||
/// Indispensabile x prima generazione migrations EFCore
|
||||
/// </summary>
|
||||
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. use DbContextoptions instead.")]
|
||||
public MoonPro_FluxContext()
|
||||
{
|
||||
}
|
||||
|
||||
#if false
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. use DbContextoptions instead.")]
|
||||
public MoonPro_FluxContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public MoonPro_FluxContext(DbContextOptions<MoonPro_FluxContext> options) : base(options)
|
||||
{
|
||||
@@ -69,6 +73,7 @@ namespace MP.Data
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
#if false
|
||||
string connString = _configuration.GetConnectionString("MP.Flux");
|
||||
if (!string.IsNullOrEmpty(connString))
|
||||
{
|
||||
@@ -77,7 +82,9 @@ namespace MP.Data
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_FluxData;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_FluxData;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,20 @@ namespace MP.Data
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
#if false
|
||||
private IConfiguration _configuration;
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
#if false
|
||||
public MoonPro_STATSContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public MoonPro_STATSContext(DbContextOptions<MoonPro_STATSContext> options) : base(options)
|
||||
{
|
||||
@@ -68,10 +72,7 @@ namespace MP.Data
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("MP.Stats");
|
||||
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
//optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;");
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels.Mtc;
|
||||
using MP.Data.DbModels.Utils;
|
||||
using NLog;
|
||||
using System;
|
||||
|
||||
#nullable disable
|
||||
@@ -13,14 +11,6 @@ namespace MP.Data
|
||||
{
|
||||
public partial class MoonPro_UtilsContext : DbContext
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
@@ -66,15 +56,8 @@ namespace MP.Data
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("MP.Utils");
|
||||
if (!string.IsNullOrEmpty(connString))
|
||||
{
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_Utils;Trusted_Connection=True;");
|
||||
}
|
||||
// fallback (si spera non necessario)
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_Utils;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Data.DbModels;
|
||||
using NLog;
|
||||
|
||||
@@ -17,16 +14,16 @@ namespace MP.Data
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
//private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MoonPro_VocContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
//public MoonPro_VocContext(IConfiguration configuration)
|
||||
//{
|
||||
// _configuration = configuration;
|
||||
//}
|
||||
|
||||
public MoonPro_VocContext(DbContextOptions<MoonPro_VocContext> options) : base(options)
|
||||
{
|
||||
@@ -52,11 +49,16 @@ namespace MP.Data
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
//if (!optionsBuilder.IsConfigured)
|
||||
//{
|
||||
// string connString = _configuration.GetConnectionString("MP.Voc");
|
||||
|
||||
// optionsBuilder.UseSqlServer(connString);
|
||||
//}
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("MP.Voc");
|
||||
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
// fallback si spera non necessario
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,489 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Core.DTO;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Anag
|
||||
{
|
||||
public class AnagRepository : BaseRepository, IAnagRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public AnagRepository(IDbContextFactory<MoonProContext> ctxFactory) : base(ctxFactory)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<AnagCountersModel> AnagCountersGetNextAsync(string cntType)
|
||||
{
|
||||
AnagCountersModel answ = new AnagCountersModel();
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
bool outTable = true;
|
||||
if (outTable)
|
||||
{
|
||||
var pCntType = new SqlParameter("@CntType", cntType);
|
||||
var pLastNum = new SqlParameter
|
||||
{
|
||||
ParameterName = "@LastNum",
|
||||
SqlDbType = SqlDbType.Int,
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetAnagCount
|
||||
.FromSqlRaw("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT", pCntType, pLastNum)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbResult != null)
|
||||
{
|
||||
answ = dbResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// se si volessero impiegare parametri OUTPUT (qui ne mancherebbe 1 nella stored x CntCode...)
|
||||
var pCntType = new SqlParameter("@CntType", cntType);
|
||||
var pLastNum = new SqlParameter
|
||||
{
|
||||
ParameterName = "@LastNum",
|
||||
SqlDbType = SqlDbType.Int,
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
var pCntCode = new SqlParameter
|
||||
{
|
||||
ParameterName = "@CntCode",
|
||||
SqlDbType = SqlDbType.NVarChar,
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
var dbResult = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT, @CntCode OUTPUT", pCntType, pLastNum, pCntCode);
|
||||
if (dbResult != 0)
|
||||
{
|
||||
answ.CntType = cntType;
|
||||
answ.CntCode = $"{pCntCode.Value}";
|
||||
int lNum = 0;
|
||||
int.TryParse($"{pLastNum.Value}", out lNum);
|
||||
answ.LastNum = lNum;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<vSelEventiBCodeModel>> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common")
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var pTableName = new SqlParameter("@TableName", TableName);
|
||||
var pFieldName = new SqlParameter("@FieldName", FieldName);
|
||||
var dbResult = await dbCtx
|
||||
.DbSetVSEB
|
||||
.FromSqlRaw("exec dbo.stp_vseb_getGenerallyAvailable @TableName, @FieldName", pTableName, pFieldName)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return dbResult ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagGruppiModel>> AnagGruppiAziendeAsync()
|
||||
{
|
||||
return await AnagGruppiGetTipoAsync("AZIENDA");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> AnagGruppiDeleteAsync(AnagGruppiModel updRec)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetAnagGruppi
|
||||
.AsNoTracking()
|
||||
.Where(x => x.CodGruppo == updRec.CodGruppo)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbRec != null)
|
||||
{
|
||||
dbCtx.DbSetAnagGruppi.Remove(dbRec);
|
||||
}
|
||||
var numRes = await dbCtx.SaveChangesAsync();
|
||||
return numRes != 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagGruppiModel>> AnagGruppiFaseAsync()
|
||||
{
|
||||
return await AnagGruppiGetTipoAsync("FASE");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagGruppiModel>> AnagGruppiGetTipoAsync(string tipoGruppo)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetAnagGruppi
|
||||
.Where(x => x.TipoGruppo == tipoGruppo)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.CodGruppo)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<RepartiDTO>> AnagGruppiRepartoDtoAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var listReparti = await AnagGruppiGetTipoAsync("REPARTO");
|
||||
|
||||
var listMacc = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
var listOpr = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
return listReparti
|
||||
.Select(x => new RepartiDTO()
|
||||
{
|
||||
CodGruppo = x.CodGruppo,
|
||||
TipoGruppo = x.TipoGruppo,
|
||||
DescrGruppo = x.DescrGruppo,
|
||||
SelEnabled = x.SelEnabled,
|
||||
CountMacc = listMacc.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.IdxMacchina).Distinct().Count(),
|
||||
CountOpr = listOpr.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.MatrOpr).Distinct().Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<RepartiDTO>> GruppiRepartoDtoByOperAsync(int matrOpr)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var listReparti = await AnagGruppiGetTipoAsync("REPARTO");
|
||||
|
||||
var listMacc = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
var listOpr = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
var gruppiOpr = await dbCtx.DbSetGrp2Oper
|
||||
.Where(x => x.MatrOpr == matrOpr)
|
||||
.Select(x => x.CodGruppo)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
return listReparti
|
||||
.Where(r => gruppiOpr.Contains(r.CodGruppo))
|
||||
.Select(x => new RepartiDTO()
|
||||
{
|
||||
CodGruppo = x.CodGruppo,
|
||||
TipoGruppo = x.TipoGruppo,
|
||||
DescrGruppo = x.DescrGruppo,
|
||||
SelEnabled = x.SelEnabled,
|
||||
CountMacc = listMacc.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.IdxMacchina).Distinct().Count(),
|
||||
CountOpr = listOpr.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.MatrOpr).Distinct().Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> AnagGruppiUpsertAsync(AnagGruppiModel updRec)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetAnagGruppi
|
||||
.AsNoTracking()
|
||||
.Where(x => x.CodGruppo == updRec.CodGruppo)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbRec != null)
|
||||
{
|
||||
dbRec.DescrGruppo = updRec.DescrGruppo;
|
||||
dbCtx.Entry(dbRec).State = EntityState.Modified;
|
||||
}
|
||||
else
|
||||
{
|
||||
await dbCtx.DbSetAnagGruppi.AddAsync(updRec);
|
||||
}
|
||||
var numRes = await dbCtx.SaveChangesAsync();
|
||||
return numRes != 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ListValuesModel>> AnagStatiCommAsync()
|
||||
{
|
||||
return await ListValuesFiltAsync("PODL", "StatoComm");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ListValuesModel>> AnagTipoArtLvAsync()
|
||||
{
|
||||
return await ListValuesFiltAsync("AnagArticoli", "Tipo");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<int> ArticoliCountAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<int> ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = "")
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
IQueryable<AnagArticoliModel> query = dbCtx.DbSetArticoli.AsNoTracking();
|
||||
|
||||
if (tipoArt != "*")
|
||||
{
|
||||
query = query.Where(x => EF.Functions.Like(x.Tipo, tipoArt));
|
||||
}
|
||||
if (azienda != "*")
|
||||
{
|
||||
query = query.Where(x => EF.Functions.Like(x.Azienda, azienda));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(searchVal))
|
||||
{
|
||||
string pattern = $"%{searchVal}%";
|
||||
query = query.Where(x =>
|
||||
EF.Functions.Like(x.CodArticolo, pattern) ||
|
||||
EF.Functions.Like(x.DescArticolo, pattern) ||
|
||||
EF.Functions.Like(x.Disegno, pattern));
|
||||
}
|
||||
|
||||
return await query.OrderBy(x => x.CodArticolo).CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<int> ArticoliCountUsedAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var result = await dbCtx
|
||||
.DbSetCounter
|
||||
.FromSqlRaw("EXEC stp_ART_CountUsed")
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
return result.FirstOrDefault()?.NumCount ?? 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ArticoliDeleteRecordAsync(AnagArticoliModel currRec)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var currVal = await dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo == currRec.CodArticolo)
|
||||
.FirstOrDefaultAsync();
|
||||
if (currVal != null)
|
||||
{
|
||||
dbCtx.DbSetArticoli.Remove(currVal);
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetByTipoAsync(string tipo, string azienda = "*")
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetArticoli
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Tipo.ToUpper() == tipo.ToUpper() && (azienda == "*" || x.Azienda.ToUpper() == azienda.ToUpper()))
|
||||
.OrderBy(x => x.CodArticolo)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "")
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
IQueryable<AnagArticoliModel> query = dbCtx.DbSetArticoli.AsNoTracking();
|
||||
|
||||
if (tipoArt != "*")
|
||||
{
|
||||
query = query.Where(x => EF.Functions.Like(x.Tipo, tipoArt));
|
||||
}
|
||||
if (azienda != "*")
|
||||
{
|
||||
query = query.Where(x => EF.Functions.Like(x.Azienda, azienda));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(searchVal))
|
||||
{
|
||||
string pattern = $"%{searchVal}%";
|
||||
query = query.Where(x =>
|
||||
EF.Functions.Like(x.CodArticolo, pattern) ||
|
||||
EF.Functions.Like(x.DescArticolo, pattern) ||
|
||||
EF.Functions.Like(x.Disegno, pattern));
|
||||
}
|
||||
|
||||
return await query.OrderBy(x => x.CodArticolo).Take(numRecord).ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetUnusedAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_ART_getNotUsed").AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetUsedAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_ART_getUsed").AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliInKitAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_TempKIT_getArtChild").AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ArticoliUpdateRecord(AnagArticoliModel editRec)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var currRec = await dbCtx.DbSetArticoli.FirstOrDefaultAsync(x => x.CodArticolo == editRec.CodArticolo);
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.Disegno = editRec.Disegno;
|
||||
currRec.DescArticolo = editRec.DescArticolo;
|
||||
currRec.Tipo = editRec.Tipo;
|
||||
currRec.Azienda = editRec.Azienda;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ListValuesModel>> ListValuesFiltAsync(string tabName, string fieldName)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetListValues
|
||||
.Where(x => x.TableName == tabName && x.FieldName == fieldName)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.ordinal)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> MacchineByMatrOperAsync(int MatrOpr)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
if (MatrOpr == 0)
|
||||
{
|
||||
return await dbCtx.DbSetMacchine.AsNoTracking().OrderBy(x => x.IdxMacchina).ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return await dbCtx.DbSetGrp2Oper
|
||||
.Where(g => g.MatrOpr == MatrOpr)
|
||||
.Join(dbCtx.DbSetGrp2Macc, g => g.CodGruppo, m => m.CodGruppo, (g, m) => m)
|
||||
.Distinct()
|
||||
.Join(dbCtx.DbSetMacchine, g => g.IdxMacchina, m => m.IdxMacchina, (g, m) => m)
|
||||
.Distinct()
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
return await dbCtx.DbSetMacchine.AsNoTracking().OrderBy(x => x.IdxMacchina).ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return await dbCtx.DbSetGrp2Macc
|
||||
.Where(g => g.CodGruppo == codGruppo)
|
||||
.Join(dbCtx.DbSetMacchine, g => g.IdxMacchina, m => m.IdxMacchina, (g, m) => m)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo)
|
||||
{
|
||||
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbOperatori
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.Where(g => g.CodGruppo == codGruppo)
|
||||
.Join(dbCtx.DbOperatori,
|
||||
g => g.MatrOpr,
|
||||
m => m.MatrOpr,
|
||||
(g, m) => m
|
||||
)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<int, int>> PODL_getDictOdlPodlAsync(List<int> missingIds)
|
||||
{
|
||||
if (missingIds == null || !missingIds.Any())
|
||||
return new Dictionary<int, int>();
|
||||
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
.Where(x => missingIds.Contains(x.IdxOdl))
|
||||
.ToDictionaryAsync(x => x.IdxOdl, x => x.IdxPromessa);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero dizionario traduzioni
|
||||
/// </summary>
|
||||
/// <param name="lingua">Codice lingua</param>
|
||||
/// <returns>Dizionario di traduzioni</returns>
|
||||
public Dictionary<string, string> VocabolarioGetLang(string lingua)
|
||||
{
|
||||
using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult();
|
||||
var rawList = dbCtx
|
||||
.DbSetVocabolario
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Lingua.ToLower() == lingua.ToLower())
|
||||
.OrderBy(x => x.Lemma)
|
||||
.ToList();
|
||||
// Proietto in dizionario
|
||||
return rawList
|
||||
.DistinctBy(t => t.Lemma, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(t => t.Lemma, t => t.Traduzione, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Anag
|
||||
{
|
||||
public abstract class BaseRepository : IBaseRepository
|
||||
{
|
||||
#region Protected Fields
|
||||
|
||||
protected readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonProContext> ctxFactory) => _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonProContext> CreateContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
using MP.Core.DTO;
|
||||
using MP.Data.DbModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Anag
|
||||
{
|
||||
public interface IAnagRepository
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Stacca un nuovo counter x il tipo richiesto
|
||||
/// </summary>
|
||||
/// <param name="cntType">Tipo di contatore</param>
|
||||
/// <returns>Modello del contatore aggiornato</returns>
|
||||
Task<AnagCountersModel> AnagCountersGetNextAsync(string cntType);
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce l'anagrafica EVENTI generalmente disponibile per OGNI macchina
|
||||
/// </summary>
|
||||
/// <param name="TableName">Nome Table x filtro (std: EvList)</param>
|
||||
/// <param name="FieldName">Nome Field x filtro (std: Common)</param>
|
||||
/// <returns>Lista di eventi generali</returns>
|
||||
Task<List<vSelEventiBCodeModel>> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common");
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo Azienda
|
||||
/// </summary>
|
||||
/// <returns>Lista di modelli anagrafica gruppi</returns>
|
||||
Task<List<AnagGruppiModel>> AnagGruppiAziendeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Delete record AnagraficaGruppi
|
||||
/// </summary>
|
||||
/// <param name="updRec">Record da eliminare</param>
|
||||
/// <returns>True se l'eliminazione � avvenuta</returns>
|
||||
Task<bool> AnagGruppiDeleteAsync(AnagGruppiModel updRec);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo Fasi
|
||||
/// </summary>
|
||||
/// <returns>Lista di modelli anagrafica gruppi</returns>
|
||||
Task<List<AnagGruppiModel>> AnagGruppiFaseAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gruppi x tipo modalit� Async
|
||||
/// </summary>
|
||||
/// <param name="tipoGruppo">Tipo di gruppo (es. REPARTO, FASE, AZIENDA)</param>
|
||||
/// <returns>Lista di modelli anagrafica gruppi</returns>
|
||||
Task<List<AnagGruppiModel>> AnagGruppiGetTipoAsync(string tipoGruppo);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo REPARTO (x associazione Macchine-Operatori) in formato DTO con conteggi del numero record trovati
|
||||
/// </summary>
|
||||
/// <returns>Lista di DTO reparti con conteggio macchine e operatori</returns>
|
||||
Task<List<RepartiDTO>> AnagGruppiRepartoDtoAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Upsert record AnagraficaGruppi (solo codice/descrizione)
|
||||
/// </summary>
|
||||
/// <param name="updRec">Record da inserire o aggiornare</param>
|
||||
/// <returns>True se l'operazione � riuscita</returns>
|
||||
Task<bool> AnagGruppiUpsertAsync(AnagGruppiModel updRec);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco valori ammessi x Stati commessa (es Yacht Baglietto)
|
||||
/// </summary>
|
||||
/// <returns>Lista di valori ammessi</returns>
|
||||
Task<List<ListValuesModel>> AnagStatiCommAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco valori ammessi x Tipo articoli
|
||||
/// </summary>
|
||||
/// <returns>Lista di valori ammessi</returns>
|
||||
Task<List<ListValuesModel>> AnagTipoArtLvAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio num articoli Async
|
||||
/// </summary>
|
||||
/// <returns>Conteggio totale articoli</returns>
|
||||
Task<int> ArticoliCountAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio articoli data condizione ricerca
|
||||
/// </summary>
|
||||
/// <param name="tipoArt">Tipo articolo</param>
|
||||
/// <param name="azienda">Azienda</param>
|
||||
/// <param name="searchVal">Valore di ricerca</param>
|
||||
/// <returns>Conteggio risultati ricerca</returns>
|
||||
Task<int> ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = "");
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio articoli IMPIEGATI (da stored stp_ART_getUsed) Async
|
||||
/// </summary>
|
||||
/// <returns>Conteggio articoli impiegati</returns>
|
||||
Task<int> ArticoliCountUsedAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazione Record Articolo
|
||||
/// </summary>
|
||||
/// <param name="currRec">Record da eliminare</param>
|
||||
/// <returns>True se eliminato</returns>
|
||||
Task<bool> ArticoliDeleteRecordAsync(AnagArticoliModel currRec);
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce elenco articoli dato tipo (es KIT)
|
||||
/// </summary>
|
||||
/// <param name="tipo">Tipo articolo (es. KIT)</param>
|
||||
/// <param name="azienda">Azienda (opzionale)</param>
|
||||
/// <returns>Lista di articoli per tipo</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetByTipoAsync(string tipo, string azienda = "*");
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli da filtro
|
||||
/// </summary>
|
||||
/// <param name="numRecord">Numero massimo di record</param>
|
||||
/// <param name="tipoArt">Tipo articolo</param>
|
||||
/// <param name="azienda">Azienda</param>
|
||||
/// <param name="searchVal">Valore di ricerca</param>
|
||||
/// <returns>Lista di articoli cercati</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "");
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli NON IMPIEGATI (da stored stp_ART_getNotUsed) Async
|
||||
/// </summary>
|
||||
/// <returns>Lista di articoli non impiegati</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetUnusedAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli IMPIEGATI (da stored stp_ART_getUsed) Async
|
||||
/// </summary>
|
||||
/// <returns>Lista di articoli non impiegati</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetUsedAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario associazione ODL/PODL
|
||||
/// </summary>
|
||||
/// <returns>Lista di articoli in kit</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliInKitAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Update Record Articolo
|
||||
/// </summary>
|
||||
/// <param name="editRec">Record da aggiornare</param>
|
||||
/// <returns>True se aggiornato</returns>
|
||||
Task<bool> ArticoliUpdateRecord(AnagArticoliModel editRec);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo REPARTOin formato DTO con conteggi del numero record trovati filtrati per operatore
|
||||
/// </summary>
|
||||
/// <returns>Lista di DTO reparti con conteggio macchine e operatori</returns>
|
||||
Task<List<RepartiDTO>> GruppiRepartoDtoByOperAsync(int matrOpr);
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco codice articoli che abbiano dati Dossier
|
||||
/// </summary>
|
||||
/// <returns>Lista di codici articolo</returns>
|
||||
Task<List<string>> ArticleWithDossierAsync();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elenco valori ammessi x tabella/colonna Async
|
||||
/// </summary>
|
||||
/// <param name="tabName">Nome tabella</param>
|
||||
/// <param name="fieldName">Nome colonna</param>
|
||||
/// <returns>Lista di valori ammessi</returns>
|
||||
Task<List<ListValuesModel>> ListValuesFiltAsync(string tabName, string fieldName);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Macchine dato operatore secondo gruppi (macchine/operatore)
|
||||
/// </summary>
|
||||
/// <param name="MatrOpr">Matricola operatore</param>
|
||||
/// <returns>Lista di macchine</returns>
|
||||
Task<List<MacchineModel>> MacchineByMatrOperAsync(int MatrOpr);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco da tabella Macchine filtro x gruppo
|
||||
/// </summary>
|
||||
/// <param name="codGruppo">Codice gruppo</param>
|
||||
/// <returns>Lista di macchine</returns>
|
||||
Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco operatori dato filtro gruppo
|
||||
/// </summary>
|
||||
/// <param name="codGruppo">Codice gruppo</param>
|
||||
/// <returns>Lista di operatori</returns>
|
||||
Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo);
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario associazione ODL/PODL
|
||||
/// </summary>
|
||||
/// <param name="missingIds">Lista di ID mancanti</param>
|
||||
/// <returns>Dizionario di associazione</returns>
|
||||
Task<Dictionary<int, int>> PODL_getDictOdlPodlAsync(List<int> missingIds);
|
||||
|
||||
/// <summary>
|
||||
/// Recupero dizionario traduzioni
|
||||
/// </summary>
|
||||
/// <param name="lingua">Codice lingua</param>
|
||||
/// <returns>Dizionario di traduzioni</returns>
|
||||
Dictionary<string, string> VocabolarioGetLang(string lingua);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MP.Data.Repository.Anag
|
||||
{
|
||||
public interface IBaseRepository
|
||||
{
|
||||
//Task<DataLayerContext> CreateContextAsync();
|
||||
//Task<bool> SaveChangesAsync(DataLayerContext ctx);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Dossier
|
||||
{
|
||||
public class DossierRepository : IDossierRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public DossierRepository(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> ArticleWithDossierAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.AsNoTracking()
|
||||
.Select(i => i.CodArticolo)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersDeleteRecordAsync(DossierModel currRec)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var currVal = await dbCtx
|
||||
.DbSetDossiers
|
||||
.Where(x => x.IdxDossier == currRec.IdxDossier)
|
||||
.FirstOrDefaultAsync();
|
||||
dbCtx
|
||||
.DbSetDossiers
|
||||
.Remove(currVal);
|
||||
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<DossierModel>> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.AsNoTracking()
|
||||
.Where(x => (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodArticolo == "*" || x.CodArticolo == CodArticolo) && (x.DtRif >= DtStart && x.DtRif <= DtEnd))
|
||||
.Include(m => m.MachineNav)
|
||||
.Include(a => a.ArticoloNav)
|
||||
.OrderByDescending(x => x.DtRif)
|
||||
.Take(MaxRec)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersInsertAsync(DossierModel newRec)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
await dbCtx
|
||||
.DbSetDossiers
|
||||
.AddAsync(newRec);
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersTakeParamsSnapshotLastAsync(string idxMacchina, DateTime dtMin, DateTime dtMax)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var pDtMin = new SqlParameter("@DtMin", dtMin);
|
||||
var pDtMax = new SqlParameter("@DtMax", dtMax);
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_FL_TakeSnapshotLast @IdxMacchina,@DtMin,@DtMax", pIdxMacchina, pDtMin, pDtMax);
|
||||
return dbResult != 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersUpdateValoreAsync(DossierModel editRec)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetDossiers
|
||||
.Where(x => x.IdxDossier == editRec.IdxDossier)
|
||||
.FirstOrDefaultAsync();
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.Valore = editRec.Valore;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
else
|
||||
{
|
||||
await dbCtx
|
||||
.DbSetDossiers
|
||||
.AddAsync(editRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Dossier
|
||||
{
|
||||
public interface IDossierRepository
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
Task<bool> DossiersDeleteRecordAsync(DossierModel currRec);
|
||||
|
||||
Task<List<DossierModel>> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec);
|
||||
|
||||
Task<bool> DossiersInsertAsync(DossierModel newRec);
|
||||
|
||||
Task<bool> DossiersTakeParamsSnapshotLastAsync(string idxMacchina, DateTime dtMin, DateTime dtMax);
|
||||
|
||||
Task<bool> DossiersUpdateValoreAsync(DossierModel editRec);
|
||||
|
||||
Task<List<string>> ArticleWithDossierAsync();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.DTO;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static EgwCoreLib.Utils.DtUtils;
|
||||
|
||||
namespace MP.Data.Repository.FluxLog
|
||||
{
|
||||
public class FluxLogRepository : IFluxLogRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public FluxLogRepository(IConfiguration configuration, IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<StatDedupDTO>> FluxLogDataReduxAsync(string idxMaccSel, List<string> fluxList, Periodo currPeriodo, Enums.ValSelection valMode, Enums.DataInterval intReq, int maxItem)
|
||||
{
|
||||
List<StatDedupDTO> procStats = new List<StatDedupDTO>();
|
||||
Log.Info($"Inizio FluxLogDataReduxAsync | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio:yyyy-MM-dd} --> {currPeriodo.Fine:yyyy-MM-dd}");
|
||||
TimeSpan step = TimeSpan.FromHours(1);
|
||||
switch (intReq)
|
||||
{
|
||||
case Enums.DataInterval.minute:
|
||||
step = TimeSpan.FromMinutes(1.00 / maxItem);
|
||||
break;
|
||||
|
||||
case Enums.DataInterval.hour:
|
||||
step = TimeSpan.FromHours(1.00 / maxItem);
|
||||
break;
|
||||
|
||||
case Enums.DataInterval.day:
|
||||
step = TimeSpan.FromDays(1.00 / maxItem);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel);
|
||||
var pOnlyTest = new SqlParameter("@OnlyTest", false);
|
||||
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
foreach (var item in fluxList)
|
||||
{
|
||||
Log.Info($"FluxLogDataReduxAsync | Flux: {item}");
|
||||
int numRecProc = 0;
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var pCodFlux = new SqlParameter("@CodFlux", item);
|
||||
DateTime dtCursStart = currPeriodo.Inizio;
|
||||
DateTime dtCursEnd = dtCursStart.Add(step);
|
||||
bool setCompleted = false;
|
||||
while (!setCompleted)
|
||||
{
|
||||
var currFlux = await dbCtx
|
||||
.DbSetFluxLog
|
||||
.Where(x => (x.CodFlux == item) && (x.dtEvento >= dtCursStart && x.dtEvento < dtCursEnd) && (x.IdxMacchina == idxMaccSel))
|
||||
.ToListAsync();
|
||||
|
||||
int numRec = currFlux.Count;
|
||||
numRecProc += numRec;
|
||||
if (numRec > maxItem)
|
||||
{
|
||||
List<Periodo> listPeriodi = new List<Periodo>();
|
||||
|
||||
switch (valMode)
|
||||
{
|
||||
case Enums.ValSelection.First:
|
||||
var recStart = currFlux.Skip(1).FirstOrDefault();
|
||||
listPeriodi.Add(new Periodo(recStart.dtEvento, dtCursEnd));
|
||||
break;
|
||||
|
||||
case Enums.ValSelection.Last:
|
||||
var recEnd = currFlux.LastOrDefault();
|
||||
listPeriodi.Add(new Periodo(dtCursStart, recEnd.dtEvento));
|
||||
break;
|
||||
|
||||
case Enums.ValSelection.Center:
|
||||
int idx = 1;
|
||||
var recCent = currFlux.Skip(idx / (maxItem + 1)).FirstOrDefault();
|
||||
listPeriodi.Add(new Periodo(dtCursStart, recCent.dtEvento));
|
||||
if (maxItem > 1)
|
||||
{
|
||||
for (int i = 2; i < maxItem; i++)
|
||||
{
|
||||
DateTime dtInizio = recCent.dtEvento;
|
||||
recCent = currFlux.Skip(i / (maxItem + 1)).FirstOrDefault();
|
||||
listPeriodi.Add(new Periodo(dtInizio, recCent.dtEvento));
|
||||
}
|
||||
}
|
||||
listPeriodi.Add(new Periodo(recCent.dtEvento.AddSeconds(1), dtCursEnd));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var slot in listPeriodi)
|
||||
{
|
||||
var pDtStart = new SqlParameter("@DtStart", slot.Inizio);
|
||||
var pDtEnd = new SqlParameter("@DtEnd", slot.Fine);
|
||||
await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC man.stp_ReduceFluxLog @IdxMacchina, @CodFlux, @DtStart, @DtEnd, @OnlyTest", pIdxMacchina, pCodFlux, pDtStart, pDtEnd, pOnlyTest);
|
||||
}
|
||||
}
|
||||
|
||||
dtCursStart = dtCursEnd;
|
||||
dtCursEnd = dtCursStart.Add(step);
|
||||
setCompleted = dtCursStart >= currPeriodo.Fine;
|
||||
}
|
||||
sw.Stop();
|
||||
StatDedupDTO currStat = new StatDedupDTO()
|
||||
{
|
||||
IdxMacchina = idxMaccSel,
|
||||
CodFlux = item,
|
||||
Interval = intReq,
|
||||
Num4Int = maxItem,
|
||||
NumRec = numRecProc,
|
||||
ProcTime = sw.Elapsed.TotalSeconds
|
||||
};
|
||||
procStats.Add(currStat);
|
||||
}
|
||||
Log.Info($"FINE FluxLogDataReduxAsync | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio:yyyy-MM-dd} --> {currPeriodo.Fine:yyyy-MM-dd}");
|
||||
return procStats;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<FluxLogModel>> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux))
|
||||
.OrderByDescending(x => x.dtEvento)
|
||||
.Take(MaxRec)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ParetoFluxLogDTO>> FluxLogParetoAsync(string idxMacchina, DateTime dtFrom, DateTime dtTo)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.Where(x => (string.IsNullOrEmpty(idxMacchina) || x.IdxMacchina == idxMacchina) && (dtFrom <= x.dtEvento && x.dtEvento <= dtTo))
|
||||
.AsNoTracking()
|
||||
.GroupBy(x => x.CodFlux)
|
||||
.Select(g => new ParetoFluxLogDTO() { IdxMacchina = idxMacchina, CodFlux = g.Key, Qty = g.Count() })
|
||||
.OrderByDescending(x => x.Qty)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using MP.Core.DTO;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using static EgwCoreLib.Utils.DtUtils;
|
||||
|
||||
namespace MP.Data.Repository.FluxLog
|
||||
{
|
||||
public interface IFluxLogRepository
|
||||
{
|
||||
Task<List<StatDedupDTO>> FluxLogDataReduxAsync(string idxMaccSel, List<string> fluxList, Periodo currPeriodo, Enums.ValSelection valMode, Enums.DataInterval intReq, int maxItem);
|
||||
|
||||
Task<List<FluxLogModel>> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec);
|
||||
|
||||
Task<List<ParetoFluxLogDTO>> FluxLogParetoAsync(string idxMacchina, DateTime dtFrom, DateTime dtTo);
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,7 @@ namespace MP.Data.Repository.IOC
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonProContext> ctxFactory)
|
||||
=> _ctxFactory = ctxFactory;
|
||||
protected BaseRepository(IDbContextFactory<MoonProContext> ctxFactory) => _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
@@ -24,24 +23,8 @@ namespace MP.Data.Repository.IOC
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonProContext> CreateContextAsync()
|
||||
=> await _ctxFactory.CreateDbContextAsync();
|
||||
protected async Task<MoonProContext> CreateContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Salvataggio dati asincrono
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> SaveChangesAsync(DataLayerContext ctx)
|
||||
=> await ctx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
|
||||
#if false
|
||||
protected readonly DataLayerContext _dbCtx;
|
||||
protected BaseRepository(DataLayerContext db) => _dbCtx = db;
|
||||
public async Task<bool> SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.MpLand
|
||||
{
|
||||
public interface IMpLandRepository
|
||||
{
|
||||
Task<List<DbSizeModel>> AllDbInfoAsync();
|
||||
|
||||
Task<List<ConfigModel>> ConfigGetAllAsync();
|
||||
|
||||
Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync();
|
||||
|
||||
Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync();
|
||||
|
||||
Task<List<RemoteRebootLogModel>> RemRebootLogGetLastNoMaccAsync();
|
||||
|
||||
Task<List<MacchineModel>> MacchineGetAllAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.MpLand
|
||||
{
|
||||
public class MpLandRepository : IMpLandRepository
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
private readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFluxLog;
|
||||
private readonly IDbContextFactory<MoonPro_STATSContext> _ctxFactoryStats;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MpLandRepository(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL,
|
||||
IDbContextFactory<MoonPro_STATSContext> ctxFactorySta)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFluxLog = ctxFactoryFL;
|
||||
_ctxFactoryStats= ctxFactorySta;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<DbSizeModel>> AllDbInfoAsync()
|
||||
{
|
||||
List<DbSizeModel> dbResult = new List<DbSizeModel>();
|
||||
string stp_DbInfo = @"
|
||||
;WITH TableRowCounts AS (
|
||||
SELECT
|
||||
t.name AS TableName,
|
||||
SUM(p.rows) AS RowNum
|
||||
FROM sys.tables t
|
||||
JOIN sys.partitions p ON t.object_id = p.object_id
|
||||
WHERE p.index_id IN (0, 1)
|
||||
GROUP BY t.name
|
||||
),
|
||||
LargestTable AS (
|
||||
SELECT TOP 1 RowNum, TableName
|
||||
FROM TableRowCounts
|
||||
ORDER BY RowNum DESC
|
||||
)
|
||||
SELECT
|
||||
DB_name() as DbName,
|
||||
CAST(SUM(size) * 8.0 / 1024 AS DECIMAL(18,2)) AS DbSizeMb,
|
||||
(SELECT COUNT(*) FROM sys.tables) AS NumTables,
|
||||
(SELECT TableName FROM LargestTable) AS BigTable,
|
||||
(SELECT RowNum FROM LargestTable) AS BigTableRows
|
||||
FROM sys.master_files
|
||||
WHERE database_id = DB_ID();
|
||||
";
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All")))
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux")))
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFluxLog.CreateDbContextAsync();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats")))
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryStats.CreateDbContextAsync();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> MacchineGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetMacchine
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetRemRebLog
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.IdxReboot)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
.AsNoTracking()
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastNoMaccAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_GetLastNoMachine")
|
||||
.AsNoTracking()
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MP.Data.DbModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.MpMon
|
||||
{
|
||||
public interface IMpMonRepository
|
||||
{
|
||||
Task<List<ConfigModel>> ConfigGetAllAsync();
|
||||
|
||||
Task<List<MacchineModel>> MacchineGetAllAsync();
|
||||
|
||||
Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo);
|
||||
|
||||
Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Data.DbModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.MpMon
|
||||
{
|
||||
public class MpMonRepository : IMpMonRepository
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MpMonRepository(IDbContextFactory<MoonProContext> ctxFactory)
|
||||
{
|
||||
_ctxFactory = ctxFactory;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> MacchineGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetMacchine
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
List<MacchineModel> dbResult;
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchine
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.Where(g => g.CodGruppo == codGruppo)
|
||||
.Join(dbCtx.DbSetMacchine,
|
||||
g => g.IdxMacchina,
|
||||
m => m.IdxMacchina,
|
||||
(g, m) => m
|
||||
)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
dbResult = dbResult
|
||||
.Where(x => !string.IsNullOrEmpty(x.locazione))
|
||||
.OrderBy(x => x.locazione).ToList();
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
||||
var dbResult = await dbCtx
|
||||
.DbSetMSE
|
||||
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using MP.Data.DbModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.MpVoc
|
||||
{
|
||||
public interface IMpVocRepository
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Recupero elenco config
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<ConfigModel>> ConfigGetAllAsync();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// recupero elenco lingue
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<LingueModel>> LingueGetAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupero tutte le voci dizionario, async
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<VocabolarioModel>> VocabolarioGetAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupero dizionario traduzioni x singola lingua
|
||||
/// </summary>
|
||||
/// <param name="lingua">Codice lingua</param>
|
||||
/// <returns>Dizionario di traduzioni</returns>
|
||||
Dictionary<string, string> VocabolarioGetLang(string lingua);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.MpVoc
|
||||
{
|
||||
public class MpVocRepository : IMpVocRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MpVocRepository(IDbContextFactory<MoonPro_VocContext> ctxFactory)
|
||||
{
|
||||
_ctxFactory = ctxFactory;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#if false
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<LingueModel>> LingueGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetLilngue
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Lingua)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<VocabolarioModel>> VocabolarioGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetVocabolario
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Lemma)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Dictionary<string, string> VocabolarioGetLang(string lingua)
|
||||
{
|
||||
using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult();
|
||||
var rawList = dbCtx
|
||||
.DbSetVocabolario
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Lingua.ToLower() == lingua.ToLower())
|
||||
.OrderBy(x => x.Lemma)
|
||||
.ToList();
|
||||
// Proietto in dizionario
|
||||
return rawList
|
||||
.DistinctBy(t => t.Lemma, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(t => t.Lemma, t => t.Traduzione, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IDbContextFactory<MoonPro_VocContext> _ctxFactory;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Production
|
||||
{
|
||||
public abstract class BaseRepository
|
||||
{
|
||||
#region Protected Fields
|
||||
|
||||
protected readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonProContext> ctxFactory) => _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonProContext> CreateContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Production
|
||||
{
|
||||
public interface IProductionRepository
|
||||
{
|
||||
#region ODL Methods
|
||||
|
||||
Task<List<ODLExpModel>> ListODLFiltAsync(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate);
|
||||
|
||||
Task<ODLExpModel> OdlByKeyAsync(int IdxOdl);
|
||||
|
||||
Task<bool> ODLCloseAsync(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi, bool confRett, int modoConfProd);
|
||||
|
||||
Task<List<ODLModel>> OdlGetCurrentAsync();
|
||||
|
||||
Task<List<StatODLModel>> OdlGetStatAsync(int IdxOdl);
|
||||
|
||||
Task<List<int>> OdlByBatchAsync(string batchSel);
|
||||
|
||||
#endregion
|
||||
|
||||
#region PODL Methods
|
||||
|
||||
Task<List<PODLExpModel>> ListPODLFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate);
|
||||
|
||||
Task<List<PODLExpModel>> ListPODL_ByCodArtAsync(string CodArticolo, bool OnlyAvail);
|
||||
|
||||
Task<List<PODLExpModel>> ListPODL_ByKitParentAsync(int IdxPodlParent);
|
||||
|
||||
Task<List<PODLExpModel>> ListPODL_KitFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate);
|
||||
|
||||
Task<PODLModel> PODL_getByKeyAsync(int idxPODL);
|
||||
|
||||
Task<PODLModel> PODL_getByOdlAsync(int idxODL);
|
||||
|
||||
Task<Dictionary<int, int>> PODL_getDictOdlPodlAsync(List<int> missingIds);
|
||||
|
||||
Task<bool> PODL_startSetup(PODLExpModel editRec, int matrOpr, double tcRich, int pzPallet, string note, DateTime dtEvent);
|
||||
|
||||
Task<bool> PODL_updateRecipe(int idxPODL, string recipeName);
|
||||
|
||||
Task<bool> PODLDeleteRecordAsync(PODLExpModel currRec);
|
||||
|
||||
Task<bool> PODLUpdateRecordAsync(PODLModel editRec);
|
||||
|
||||
Task<bool> PodlIstKitDeleteAsync(int IdxPODL);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Kit Methods
|
||||
|
||||
Task<bool> IstKitDeleteAsync(IstanzeKitModel rec2del);
|
||||
|
||||
Task<List<IstanzeKitModel>> IstKitFiltAsync(string keyKit, string keyExtOrd);
|
||||
|
||||
Task<bool> IstKitInsertByWKSAsync(string CodArtParent, string KeyFilt);
|
||||
|
||||
Task<bool> IstKitUpsertAsync(IstanzeKitModel editRec);
|
||||
|
||||
Task<bool> TemplateKitDeleteAsync(TemplateKitModel rec2del);
|
||||
|
||||
Task<List<TemplateKitModel>> TemplateKitFiltAsync(string KitCode, string codChild);
|
||||
|
||||
Task<bool> TemplateKitUpsertAsync(TemplateKitModel editRec, string codAzienda);
|
||||
|
||||
Task<bool> WipKitDeleteAsync(WipSetupKitModel rec2del);
|
||||
|
||||
Task<bool> WipKitDeleteOlderAsync(DateTime dateLimit);
|
||||
|
||||
Task<List<WipSetupKitModel>> WipKitFiltAsync(string KeyFilt);
|
||||
|
||||
Task<bool> WipKitUpsertAsync(WipSetupKitModel editRec);
|
||||
|
||||
Task<List<TksScoreModel>> TksScoreAsync(string KeyFilt, int MaxResult);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Macchine / Gruppi Methods
|
||||
|
||||
Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo);
|
||||
|
||||
Task<List<MacchineModel>> MacchineByMatrOperAsync(int MatrOpr);
|
||||
|
||||
Task<List<string>> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd);
|
||||
|
||||
Task<bool> Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del);
|
||||
|
||||
Task<bool> Grp2MaccInsertAsync(Gruppi2MaccModel upsRec);
|
||||
|
||||
Task<bool> Grp2OperDeleteAsync(Gruppi2OperModel rec2del);
|
||||
|
||||
Task<bool> Grp2OperInsertAsync(Gruppi2OperModel upsRec);
|
||||
|
||||
Task<StatoMacchineModel> StatoMacchinaAsync(string idxMacchina);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc Production Methods
|
||||
|
||||
Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000);
|
||||
|
||||
Task<List<AnagGiacenzeModel>> ListGiacenzeAsync(int IdxOdl);
|
||||
|
||||
Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo);
|
||||
Task<bool> OperatoriUpsertAsync(AnagOperatoriModel updRec);
|
||||
|
||||
Task<List<string>> ParametriGetFiltAsync(string IdxMacchina);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,879 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Production
|
||||
{
|
||||
public class ProductionRepository : IProductionRepository
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
|
||||
public ProductionRepository(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task<MoonProContext> GetMoonProContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods - ODL
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ODLExpModel>> ListODLFiltAsync(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
|
||||
var InCorso = new SqlParameter("@InCorso", inCorso);
|
||||
var CodArt = new SqlParameter("@CodArt", codArt);
|
||||
var KeyRich = new SqlParameter("@KeyRich", keyRichPart);
|
||||
var CodGruppo = new SqlParameter("@CodGruppo", Reparto);
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", IdxMacchina);
|
||||
var DataFrom = new SqlParameter("@DataFrom", startDate);
|
||||
var DataTo = new SqlParameter("@DataTo", endDate);
|
||||
|
||||
return await dbCtx
|
||||
.DbSetODLExp
|
||||
.FromSqlRaw("EXEC stp_ODL_getByFiltSpec @InCorso, @CodArt, @KeyRich, @CodGruppo, @IdxMacchina, @DataFrom, @DataTo", InCorso, CodArt, KeyRich, CodGruppo, IdxMacc, DataFrom, DataTo)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ODLExpModel> OdlByKeyAsync(int IdxOdl)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetODLExp
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.IdxOdl == IdxOdl);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ODLCloseAsync(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi, bool confRett, int modoConfProd)
|
||||
{
|
||||
bool fatto = false;
|
||||
if (idxOdl > 0)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
// preparo i parametri
|
||||
var IdxODL = new SqlParameter("@IdxODL", idxOdl);
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
|
||||
try
|
||||
{
|
||||
var dbResult = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_ODL_fineProd @IdxODL, @IdxMacchina", IdxODL, IdxMacchina);
|
||||
fatto = dbResult != 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
NLog.LogManager.GetCurrentClassLogger().Error($"Eccezione durante ODLCloseAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ODLModel>> OdlGetCurrentAsync()
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetODL
|
||||
.Where(x => x.DataInizio != null && x.DataFine == null)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<StatODLModel>> OdlGetStatAsync(int IdxOdl)
|
||||
{
|
||||
List<StatODLModel> dbResult = new List<StatODLModel>();
|
||||
if (IdxOdl > 0)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var IdxODL = new SqlParameter("@IdxODL", IdxOdl);
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetStatOdl
|
||||
.FromSqlRaw("EXEC stp_STAT_ODL @IdxODL", IdxODL)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<int>> OdlByBatchAsync(string batchSel)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_InveContext(_configuration);
|
||||
return await dbCtx
|
||||
.DbGiacenzeData
|
||||
.AsNoTracking()
|
||||
.Where(x => x.IdxOdl > 0)
|
||||
.Select(x => x.IdxOdl)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods - PODL
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<PODLExpModel>> ListPODLFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var Lanc = new SqlParameter("@Lanciato", lanciato);
|
||||
var KeyRich = new SqlParameter("@KeyRich", keyRichPart);
|
||||
var CodGrp = new SqlParameter("@CodGruppo", codGruppo);
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DateFrom = new SqlParameter("@DtInizio", startDate);
|
||||
var DateTo = new SqlParameter("@DtFine", endDate);
|
||||
|
||||
return await dbCtx
|
||||
.DbSetPODLExp
|
||||
.FromSqlRaw("EXEC stp_PODL_getByFiltSpec @Lanciato, @KeyRich, @CodGruppo, @IdxMacchina, @DtInizio, @DtFine", Lanc, KeyRich, CodGrp, IdxMacc, DateFrom, DateTo)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<PODLExpModel>> ListPODL_ByCodArtAsync(string CodArticolo, bool OnlyAvail)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var pCodArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
||||
var pOnlyAvail = new SqlParameter("@onlyAvail", OnlyAvail);
|
||||
|
||||
return await dbCtx
|
||||
.DbSetPODLExp
|
||||
.FromSqlRaw("EXEC stp_PODL_getByCodArt @CodArticolo, @onlyAvail", pCodArticolo, pOnlyAvail)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<PODLExpModel>> ListPODL_ByKitParentAsync(int IdxPodlParent)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var pIdxPodlParent = new SqlParameter("@IdxPodlParent", IdxPodlParent);
|
||||
|
||||
return await dbCtx
|
||||
.DbSetPODLExp
|
||||
.FromSqlRaw("EXEC stp_PODL_getByParentKitIdx @IdxPodlParent", pIdxPodlParent)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<PODLExpModel>> ListPODL_KitFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var Lanc = new SqlParameter("@Lanciato", lanciato);
|
||||
var KeyRich = new SqlParameter("@KeyRich", keyRichPart);
|
||||
var CodGrp = new SqlParameter("@CodGruppo", codGruppo);
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DateFrom = new SqlParameter("@DtInizio", startDate);
|
||||
var DateTo = new SqlParameter("@DtFine", endDate);
|
||||
|
||||
return await dbCtx
|
||||
.DbSetPODLExp
|
||||
.FromSqlRaw("EXEC stp_PODL_getByFiltSpecKit @Lanciato, @KeyRich, @CodGruppo, @IdxMacchina, @DtInizio, @DtFine", Lanc, KeyRich, CodGrp, IdxMacc, DateFrom, DateTo)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PODLModel> PODL_getByKeyAsync(int idxPODL)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
.Where(x => x.IdxPromessa == idxPODL)
|
||||
.Include(a => a.ArticoloNav)
|
||||
.FirstOrDefaultAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PODLModel> PODL_getByOdlAsync(int idxODL)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
.Where(x => x.IdxOdl == idxODL)
|
||||
.FirstOrDefaultAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<int, int>> PODL_getDictOdlPodlAsync(List<int> missingIds)
|
||||
{
|
||||
if (missingIds == null || !missingIds.Any())
|
||||
return new Dictionary<int, int>();
|
||||
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
.Where(x => missingIds.Contains(x.IdxOdl))
|
||||
.ToDictionaryAsync(x => x.IdxOdl, x => x.IdxPromessa);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> PODL_startSetup(PODLExpModel editRec, int matrOpr, double tcRich, int pzPallet, string note, DateTime dtEvent)
|
||||
{
|
||||
bool answ = false;
|
||||
PODLModel recPODL = new PODLModel()
|
||||
{
|
||||
IdxPromessa = editRec.IdxPromessa,
|
||||
KeyRichiesta = editRec.KeyRichiesta,
|
||||
KeyBCode = editRec.KeyBCode,
|
||||
IdxOdl = editRec.IdxOdl,
|
||||
CodArticolo = editRec.CodArticolo,
|
||||
CodGruppo = editRec.CodGruppo,
|
||||
IdxMacchina = editRec.IdxMacchina,
|
||||
NumPezzi = editRec.NumPezzi,
|
||||
Tcassegnato = editRec.Tcassegnato,
|
||||
DueDate = editRec.DueDate,
|
||||
Priorita = editRec.Priorita,
|
||||
PzPallet = editRec.PzPallet,
|
||||
Note = editRec.Note,
|
||||
CodCli = editRec.CodCli,
|
||||
InsertDate = editRec.InsertDate
|
||||
};
|
||||
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
.Where(x => x.IdxPromessa == recPODL.IdxPromessa)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (currRec != null)
|
||||
{
|
||||
var IdxPromessa = new SqlParameter("@idxPromessa", recPODL.IdxPromessa);
|
||||
var MatrOpr = new SqlParameter("@MatrOpr", matrOpr);
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", recPODL.IdxMacchina);
|
||||
var TCRichAttr = new SqlParameter("@TCRichAttr", tcRich);
|
||||
var PzPallet = new SqlParameter("@PzPallet", pzPallet);
|
||||
var Note = new SqlParameter("@Note", note);
|
||||
var DtEvento = new SqlParameter("@dtEvento", dtEvent);
|
||||
await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_ODL_inizioSetupPromessa @idxPromessa, @MatrOpr, @IdxMacchina, @TCRichAttr, @PzPallet, @Note, @dtEvento", IdxPromessa, MatrOpr, IdxMacchina, TCRichAttr, PzPallet, Note, DtEvento);
|
||||
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> PODL_updateRecipe(int idxPODL, string recipeName)
|
||||
{
|
||||
bool answ = false;
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetPODL
|
||||
.Where(x => x.IdxPromessa == idxPODL)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.Recipe = recipeName;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
answ = await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> PODLDeleteRecordAsync(PODLExpModel currRec)
|
||||
{
|
||||
PODLModel recPODL = new PODLModel()
|
||||
{
|
||||
IdxPromessa = currRec.IdxPromessa,
|
||||
KeyRichiesta = currRec.KeyRichiesta,
|
||||
KeyBCode = currRec.KeyBCode,
|
||||
IdxOdl = currRec.IdxOdl,
|
||||
CodArticolo = currRec.CodArticolo,
|
||||
CodGruppo = currRec.CodGruppo,
|
||||
IdxMacchina = currRec.IdxMacchina,
|
||||
NumPezzi = currRec.NumPezzi,
|
||||
Tcassegnato = currRec.Tcassegnato,
|
||||
DueDate = currRec.DueDate,
|
||||
Priorita = currRec.Priorita,
|
||||
PzPallet = currRec.PzPallet,
|
||||
Note = currRec.Note,
|
||||
CodCli = currRec.CodCli,
|
||||
InsertDate = currRec.InsertDate
|
||||
};
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var currVal = await dbCtx
|
||||
.DbSetPODL
|
||||
.Where(x => x.IdxPromessa == recPODL.IdxPromessa)
|
||||
.FirstOrDefaultAsync();
|
||||
dbCtx
|
||||
.DbSetPODL
|
||||
.Remove(currVal);
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> PODLUpdateRecordAsync(PODLModel editRec)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetPODL
|
||||
.Where(x => x.IdxPromessa == editRec.IdxPromessa)
|
||||
.FirstOrDefaultAsync();
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.CodGruppo = editRec.CodGruppo;
|
||||
currRec.CodArticolo = editRec.CodArticolo;
|
||||
currRec.IdxMacchina = editRec.IdxMacchina;
|
||||
currRec.KeyBCode = editRec.KeyBCode;
|
||||
currRec.KeyRichiesta = editRec.KeyRichiesta;
|
||||
currRec.NumPezzi = editRec.NumPezzi;
|
||||
currRec.Tcassegnato = editRec.Tcassegnato;
|
||||
currRec.Attivabile = editRec.Attivabile;
|
||||
currRec.Note = editRec.Note;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
else
|
||||
{
|
||||
await dbCtx
|
||||
.DbSetPODL
|
||||
.AddAsync(editRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> PodlIstKitDeleteAsync(int IdxPODL)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var pIdxPODL = new SqlParameter("@IdxPODL", IdxPODL);
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC dbo.stp_PodlIstKit_delete @IdxPODL", pIdxPODL);
|
||||
return dbResult != 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods - Kit
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> IstKitDeleteAsync(IstanzeKitModel rec2del)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetInstKit
|
||||
.Where(x => x.KeyKit == rec2del.KeyKit && x.KeyExtOrd == rec2del.KeyExtOrd)
|
||||
.FirstOrDefaultAsync();
|
||||
if (actRec != null)
|
||||
{
|
||||
dbCtx
|
||||
.DbSetInstKit
|
||||
.Remove(actRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<IstanzeKitModel>> IstKitFiltAsync(string keyKit, string keyExtOrd)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetInstKit
|
||||
.Where(x => (string.IsNullOrEmpty(keyKit) && string.IsNullOrEmpty(keyExtOrd)) || (x.KeyKit.Contains(keyKit) && !string.IsNullOrEmpty(keyKit)) || (x.KeyExtOrd.Contains(keyExtOrd) && !string.IsNullOrEmpty(keyExtOrd)))
|
||||
.AsNoTracking()
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> IstKitInsertByWKSAsync(string CodArtParent, string KeyFilt)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
|
||||
var pCodArtParent = new SqlParameter("@CodArtParent", CodArtParent);
|
||||
var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt);
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC dbo.stp_IstKit_insertByWKS @CodArtParent,@KeyFilt", pCodArtParent, pKeyFilt);
|
||||
return dbResult != 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> IstKitUpsertAsync(IstanzeKitModel editRec)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetInstKit
|
||||
.Where(x => x.KeyKit == editRec.KeyKit && x.KeyExtOrd == editRec.KeyExtOrd)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (actRec == null)
|
||||
{
|
||||
await dbCtx
|
||||
.DbSetInstKit
|
||||
.AddAsync(editRec);
|
||||
}
|
||||
else
|
||||
{
|
||||
actRec.CodArtParent = editRec.CodArtParent;
|
||||
actRec.CodArtChild = editRec.CodArtChild;
|
||||
actRec.QtyART = editRec.QtyART;
|
||||
actRec.QtyKIT = editRec.QtyKIT;
|
||||
dbCtx.Entry(actRec).State = EntityState.Modified;
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> TemplateKitDeleteAsync(TemplateKitModel rec2del)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetTempKit
|
||||
.Where(x => x.CodArtParent == rec2del.CodArtParent && x.CodArtChild == rec2del.CodArtChild)
|
||||
.FirstOrDefaultAsync();
|
||||
if (actRec != null)
|
||||
{
|
||||
dbCtx
|
||||
.DbSetTempKit
|
||||
.Remove(actRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<TemplateKitModel>> TemplateKitFiltAsync(string KitCode, string codChild)
|
||||
{
|
||||
List<TemplateKitModel> dbResult = new List<TemplateKitModel>();
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
dbResult = await dbCtx
|
||||
.DbSetTempKit
|
||||
.Where(x => (string.IsNullOrEmpty(KitCode) && string.IsNullOrEmpty(codChild)) || (x.CodArtParent.Contains(KitCode) && !string.IsNullOrEmpty(KitCode)) || (x.CodArtChild.Contains(codChild) && !string.IsNullOrEmpty(codChild)))
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> TemplateKitUpsertAsync(TemplateKitModel editRec, string codAzienda)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var recArt = await dbCtx
|
||||
.DbSetArticoli
|
||||
.FirstOrDefaultAsync(x => x.CodArticolo == editRec.CodArtParent);
|
||||
if (recArt == null)
|
||||
{
|
||||
AnagArticoliModel newRecArt = new AnagArticoliModel()
|
||||
{
|
||||
CodArticolo = editRec.CodArtParent,
|
||||
Tipo = "KIT",
|
||||
DescArticolo = $"Articolo KIT - {DateTime.Now:yyyy-MM-dd HH:mm:ss}",
|
||||
Disegno = "",
|
||||
Azienda = codAzienda,
|
||||
CurrRev = "",
|
||||
ProdRev = ""
|
||||
};
|
||||
dbCtx
|
||||
.DbSetArticoli
|
||||
.Add(newRecArt);
|
||||
}
|
||||
|
||||
var actRec = await dbCtx
|
||||
.DbSetTempKit
|
||||
.Where(x => x.CodArtParent == editRec.CodArtParent && x.CodArtChild == editRec.CodArtChild)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (actRec == null)
|
||||
{
|
||||
await dbCtx
|
||||
.DbSetTempKit
|
||||
.AddAsync(editRec);
|
||||
}
|
||||
else
|
||||
{
|
||||
actRec.Qty = editRec.Qty;
|
||||
dbCtx.Entry(actRec).State = EntityState.Modified;
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> WipKitDeleteAsync(WipSetupKitModel rec2del)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.KeyFilt == rec2del.KeyFilt && x.CodOrd == rec2del.CodOrd)
|
||||
.FirstOrDefaultAsync();
|
||||
if (actRec != null)
|
||||
{
|
||||
dbCtx
|
||||
.DbSetWipKit
|
||||
.Remove(actRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> WipKitDeleteOlderAsync(DateTime dateLimit)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.DataIns < dateLimit)
|
||||
.ToListAsync();
|
||||
if (actRec != null && actRec.Any())
|
||||
{
|
||||
dbCtx
|
||||
.DbSetWipKit
|
||||
.RemoveRange(actRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<WipSetupKitModel>> WipKitFiltAsync(string KeyFilt)
|
||||
{
|
||||
List<WipSetupKitModel> dbResult = new List<WipSetupKitModel>();
|
||||
if (!string.IsNullOrEmpty(KeyFilt))
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
dbResult = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.KeyFilt.Contains(KeyFilt))
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> WipKitUpsertAsync(WipSetupKitModel editRec)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.KeyFilt == editRec.KeyFilt && x.CodOrd == editRec.CodOrd)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (actRec == null)
|
||||
{
|
||||
dbCtx
|
||||
.DbSetWipKit
|
||||
.Add(editRec);
|
||||
}
|
||||
else
|
||||
{
|
||||
actRec.CodArt = editRec.CodArt;
|
||||
actRec.DescArt = editRec.DescArt;
|
||||
actRec.Qta = editRec.Qta;
|
||||
actRec.DataIns = editRec.DataIns;
|
||||
dbCtx.Entry(actRec).State = EntityState.Modified;
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<TksScoreModel>> TksScoreAsync(string KeyFilt, int MaxResult)
|
||||
{
|
||||
List<TksScoreModel> dbResult = new List<TksScoreModel>();
|
||||
if (!string.IsNullOrEmpty(KeyFilt))
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt);
|
||||
var pMaxRes = new SqlParameter("@maxResult", MaxResult);
|
||||
dbResult = await dbCtx
|
||||
.DbSetTksScore
|
||||
.FromSqlRaw("EXEC stp_TKS_Search @KeyFilt, @maxResult", pKeyFilt, pMaxRes)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods - Macchine/Gruppi
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
return await dbCtx
|
||||
.DbSetMacchine
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.Where(g => g.CodGruppo == codGruppo)
|
||||
.Join(dbCtx.DbSetMacchine,
|
||||
g => g.IdxMacchina,
|
||||
m => m.IdxMacchina,
|
||||
(g, m) => m
|
||||
)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> MacchineByMatrOperAsync(int MatrOpr)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
if (MatrOpr == 0)
|
||||
{
|
||||
return await dbCtx
|
||||
.DbSetMacchine
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.Where(g => g.MatrOpr == MatrOpr)
|
||||
.Join(dbCtx.DbSetGrp2Macc,
|
||||
g => g.CodGruppo,
|
||||
m => m.CodGruppo,
|
||||
(g, m) => m
|
||||
)
|
||||
.Distinct()
|
||||
.Join(dbCtx.DbSetMacchine,
|
||||
g => g.IdxMacchina,
|
||||
m => m.IdxMacchina,
|
||||
(g, m) => m
|
||||
)
|
||||
.Distinct()
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
.Where(x => x.dtEvento >= dtStart && x.dtEvento <= dtEnd)
|
||||
.Select(i => i.IdxMacchina)
|
||||
.Distinct()
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del)
|
||||
{
|
||||
bool answ = false;
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.Where(x => x.CodGruppo == rec2del.CodGruppo && x.IdxMacchina == rec2del.IdxMacchina)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbRec != null)
|
||||
{
|
||||
dbCtx.DbSetGrp2Macc.Remove(dbRec);
|
||||
int numDone = await dbCtx.SaveChangesAsync();
|
||||
answ = numDone != 0;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Grp2MaccInsertAsync(Gruppi2MaccModel upsRec)
|
||||
{
|
||||
bool answ = false;
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.Where(x => x.CodGruppo == upsRec.CodGruppo && x.IdxMacchina == upsRec.IdxMacchina)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbRec == null)
|
||||
{
|
||||
await dbCtx.DbSetGrp2Macc.AddAsync(upsRec);
|
||||
int numDone = await dbCtx.SaveChangesAsync();
|
||||
answ = numDone != 0;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Grp2OperDeleteAsync(Gruppi2OperModel rec2del)
|
||||
{
|
||||
bool answ = false;
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.Where(x => x.CodGruppo == rec2del.CodGruppo && x.MatrOpr == rec2del.MatrOpr)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbRec != null)
|
||||
{
|
||||
dbCtx.DbSetGrp2Oper.Remove(dbRec);
|
||||
int numDone = await dbCtx.SaveChangesAsync();
|
||||
answ = numDone != 0;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Grp2OperInsertAsync(Gruppi2OperModel upsRec)
|
||||
{
|
||||
bool answ = false;
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.Where(x => x.CodGruppo == upsRec.CodGruppo && x.MatrOpr == upsRec.MatrOpr)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbRec == null)
|
||||
{
|
||||
await dbCtx.DbSetGrp2Oper.AddAsync(upsRec);
|
||||
int numDone = await dbCtx.SaveChangesAsync();
|
||||
answ = numDone != 0;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<StatoMacchineModel> StatoMacchinaAsync(string idxMacchina)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetStatoMacc
|
||||
.Where(x => x.IdxMacchina == idxMacchina)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods - Misc
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
|
||||
{
|
||||
List<MappaStatoExplModel> dbResult = new List<MappaStatoExplModel>();
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
|
||||
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetMSE
|
||||
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagGiacenzeModel>> ListGiacenzeAsync(int IdxOdl)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_InveContext(_configuration);
|
||||
return await dbCtx
|
||||
.DbGiacenzeData
|
||||
.Where(x => x.IdxOdl == IdxOdl)
|
||||
.AsNoTracking()
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo)
|
||||
{
|
||||
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbOperatori
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.Where(g => g.CodGruppo == codGruppo)
|
||||
.Join(dbCtx.DbOperatori,
|
||||
g => g.MatrOpr,
|
||||
m => m.MatrOpr,
|
||||
(g, m) => m
|
||||
)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> OperatoriUpsertAsync(AnagOperatoriModel updRec)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbOperatori
|
||||
.FindAsync(updRec.MatrOpr);
|
||||
if (dbRec != null)
|
||||
{
|
||||
dbCtx.Entry(dbRec).CurrentValues.SetValues(updRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> ParametriGetFiltAsync(string IdxMacchina)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina))
|
||||
.Take(1000)
|
||||
.Select(i => i.CodFlux)
|
||||
.Distinct()
|
||||
.OrderBy(x => x)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.System
|
||||
{
|
||||
public interface ISystemRepository
|
||||
{
|
||||
Task<List<ConfigModel>> ConfigGetAllAsync();
|
||||
|
||||
Task<bool> ConfigUpdateAsync(ConfigModel updRec);
|
||||
|
||||
Task<bool> EvListInsertAsync(EventListModel newRec);
|
||||
|
||||
Task<bool> ForceDbMaintAsync(bool doExec, bool doUpdStat, bool doSave, int minPgCnt, int minAvgFrag, int maxAvgFragReb);
|
||||
|
||||
Task<List<LinkMenuModel>> ListLinkAllAsync();
|
||||
|
||||
Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink);
|
||||
|
||||
Task<List<LinkMenuModel>> ElencoLinkAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.System
|
||||
{
|
||||
public class SystemRepository : ISystemRepository
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public SystemRepository(IDbContextFactory<MoonProContext> ctxFactory, IConfiguration configuration)
|
||||
{
|
||||
_ctxFactory = ctxFactory;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ConfigUpdateAsync(ConfigModel updRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
ConfigModel dbResult = new();
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
dbResult = await dbCtx
|
||||
.DbSetConfig
|
||||
.Where(x => x.Chiave == updRec.Chiave)
|
||||
.FirstOrDefaultAsync();
|
||||
if (dbResult != null)
|
||||
{
|
||||
dbResult.Valore = updRec.Valore;
|
||||
fatto = await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> EvListInsertAsync(EventListModel newRec)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
_ = await dbCtx
|
||||
.DbSetEvList
|
||||
.AddAsync(newRec);
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ForceDbMaintAsync(bool doExec, bool doUpdStat, bool doSave, int minPgCnt, int minAvgFrag, int maxAvgFragReb)
|
||||
{
|
||||
await using var dbCtx = new MoonProAdminContext(_configuration);
|
||||
|
||||
_ = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC man.stp_Utility_Maintanance");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<LinkMenuModel>> ListLinkAllAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetLinkMenu
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Ordine)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink)
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetLinkMenu
|
||||
.Where(x => x.TipoLink == tipoLink)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Ordine)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<List<LinkMenuModel>> ElencoLinkAsync()
|
||||
{
|
||||
return ListLinkFiltAsync("SpecLink");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,7 @@ namespace MP.Data.Repository.Utils
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory)
|
||||
=> _ctxFactory = ctxFactory;
|
||||
protected BaseRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory) => _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
@@ -24,24 +23,9 @@ namespace MP.Data.Repository.Utils
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonPro_UtilsContext> CreateContextAsync()
|
||||
=> await _ctxFactory.CreateDbContextAsync();
|
||||
protected async Task<MoonPro_UtilsContext> CreateContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Salvataggio dati asincrono
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> SaveChangesAsync(DataLayerContext ctx)
|
||||
=> await ctx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
|
||||
#if false
|
||||
protected readonly DataLayerContext _dbCtx;
|
||||
protected BaseRepository(DataLayerContext db) => _dbCtx = db;
|
||||
public async Task<bool> SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
using static Org.BouncyCastle.Asn1.Cmp.Challenge;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -19,10 +21,12 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public BaseServ(IConfiguration configuration, IConnectionMultiplexer redConn)
|
||||
public BaseServ(IConfiguration configuration, IFusionCache cache, IConnectionMultiplexer redConn)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_cache = cache;
|
||||
|
||||
slowLogThresh = _configuration.GetValue<double>("ServerConf:slowLogThresh", 1);
|
||||
// Verifica conf trace...
|
||||
_traceEnabled = _configuration.GetValue<bool>("Otel:EnableTracing", false);
|
||||
|
||||
@@ -161,13 +165,23 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
protected static readonly ActivitySource ActivitySource = new ActivitySource("MP.IOC");
|
||||
|
||||
protected static IConfiguration _configuration = null!;
|
||||
/// <summary>
|
||||
/// Oggetto gestione FusionCache
|
||||
/// </summary>
|
||||
protected readonly IFusionCache _cache;
|
||||
|
||||
/// <summary>
|
||||
/// Path base chiavi REDIS
|
||||
/// </summary>
|
||||
protected readonly string _redisBaseKey = "MP:IOC";
|
||||
|
||||
/// <summary>
|
||||
/// Abilitazione operazioni tracing generiche
|
||||
/// </summary>
|
||||
protected readonly bool _traceEnabled = false;
|
||||
|
||||
protected IConfiguration _configuration = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
@@ -180,8 +194,19 @@ namespace MP.Data.Services
|
||||
protected IDatabase _redisDb = null!;
|
||||
|
||||
protected JsonSerializerSettings? JSSettings;
|
||||
|
||||
protected string MpIoNS = "";
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache Lunga standard (300 sec)
|
||||
/// </summary>
|
||||
protected int redisLongTimeCache = 300;
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache Breve standard (5 sec)
|
||||
/// </summary>
|
||||
protected int redisShortTimeCache = 5;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
@@ -281,6 +306,75 @@ namespace MP.Data.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementa gestione FusionCache+ tracking attività
|
||||
/// - recupero cache da memoria o da obj esterno + cache memoria
|
||||
/// - recupero da fetchFunc se mancasse + store in cache L1/L2
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="cacheKey"></param>
|
||||
/// <param name="fetchFunc"></param>
|
||||
/// <param name="expiration"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task<T> GetOrFetchAsync<T>(string operationName, string cacheKey, Func<Task<T>> fetchFunc, TimeSpan expiration, params string[] tagList)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity(operationName);
|
||||
string source;
|
||||
var tryGet = await _cache.TryGetAsync<T>(cacheKey);
|
||||
if (tryGet.HasValue)
|
||||
{
|
||||
source = "MEMORY";
|
||||
var result = tryGet.Value!;
|
||||
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
// se supero la soglia loggo...
|
||||
if (activity?.Duration.TotalMilliseconds > slowLogThresh)
|
||||
{
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool fromDb = false;
|
||||
// cache in redis
|
||||
var cacheOptions = new FusionCacheEntryOptions()
|
||||
.SetDuration(expiration)
|
||||
.SetFailSafe(true);
|
||||
// cache in RAM per 1/3 del tempo x risparmiare risorse
|
||||
cacheOptions.MemoryCacheDuration = expiration / 3;
|
||||
|
||||
var final = await _cache.GetOrSetAsync<T>(
|
||||
cacheKey,
|
||||
async _ =>
|
||||
{
|
||||
fromDb = true;
|
||||
return await fetchFunc();
|
||||
},
|
||||
options: cacheOptions,
|
||||
tags: tagList
|
||||
);
|
||||
|
||||
source = fromDb ? "DB" : "REDIS";
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
// switch log in base a source..
|
||||
switch (source)
|
||||
{
|
||||
case "DB":
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Info);
|
||||
break;
|
||||
|
||||
case "REDIS":
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Debug);
|
||||
break;
|
||||
|
||||
default:
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms");
|
||||
break;
|
||||
}
|
||||
return final!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper generale di lettura da cache o da funzione (DB) con caching successivo
|
||||
/// </summary>
|
||||
@@ -327,6 +421,18 @@ namespace MP.Data.Services
|
||||
return result!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce un timeout dal valore secondi richiesti + tempo random +/-3%
|
||||
/// </summary>
|
||||
/// <param name="durationSec"></param>
|
||||
/// <returns></returns>
|
||||
protected TimeSpan GetRandTOut(double durationSec)
|
||||
{
|
||||
double noise = (rand.NextDouble() * 0.06) - 0.03;
|
||||
double rValue = durationSec * (1 + noise);
|
||||
return TimeSpan.FromSeconds(rValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper trace messaggio log (SE abilitato)
|
||||
/// </summary>
|
||||
@@ -396,6 +502,7 @@ namespace MP.Data.Services
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private bool _disposed = false;
|
||||
|
||||
/// <summary>
|
||||
@@ -408,12 +515,14 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
private int cacheTtlShort = 60 * 1;
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Path base chiavi REDIS
|
||||
/// Soglia minima (ms) per log timing in console
|
||||
/// </summary>
|
||||
protected readonly string _redisBaseKey = "MP:IOC";
|
||||
private double slowLogThresh = 0;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -23,17 +23,19 @@ namespace MP.Data.Services.IOC
|
||||
public IocService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IFusionCache cache,
|
||||
IIocRepository repo,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
//Microsoft.Extensions.Caching.Memory.IMemoryCache cache
|
||||
IFusionCache cache) : base(config, redis)
|
||||
IServiceScopeFactory scopeFactory
|
||||
) : base(config, cache, redis)
|
||||
{
|
||||
_className = "IocServ";
|
||||
int.TryParse(config.GetValue<string>("ServerConf:redisLongTimeCache"), out redisLongTimeCache);
|
||||
int.TryParse(config.GetValue<string>("ServerConf:redisShortTimeCache"), out redisShortTimeCache);
|
||||
_repo = repo;
|
||||
_scopeFactory = scopeFactory;
|
||||
_cache = cache;
|
||||
#if false
|
||||
_cache = cache;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
@@ -79,7 +81,7 @@ namespace MP.Data.Services.IOC
|
||||
result = await GetCurrOdlByProdAsync(idxMacchina);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
_redisDb.StringSet(currKey, rawData, GetRandTOut(redisLongTimeCache));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -261,16 +263,18 @@ namespace MP.Data.Services.IOC
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Restituisce un timeout dai minuti richiesti + tempo random 1..60 sec
|
||||
/// </summary>
|
||||
/// <param name="stdMinutes"></param>
|
||||
/// <returns></returns>
|
||||
protected TimeSpan getRandTOut(double stdMinutes)
|
||||
protected TimeSpan GetRandTOut(double stdMinutes)
|
||||
{
|
||||
double rndValue = stdMinutes + (double)rand.Next(1, 60) / 60;
|
||||
return TimeSpan.FromMinutes(rndValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
@@ -278,7 +282,9 @@ namespace MP.Data.Services.IOC
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly IFusionCache _cache;
|
||||
#if false
|
||||
private readonly IFusionCache _cache;
|
||||
#endif
|
||||
|
||||
private readonly string _className;
|
||||
|
||||
@@ -295,9 +301,11 @@ namespace MP.Data.Services.IOC
|
||||
/// </summary>
|
||||
private string dtFormat = "yyyyMMddHHmmssfff";
|
||||
|
||||
#if false
|
||||
private int redisLongTimeCache = 5;
|
||||
|
||||
private int redisShortTimeCache = 2;
|
||||
private int redisShortTimeCache = 2;
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -417,7 +425,7 @@ namespace MP.Data.Services.IOC
|
||||
{
|
||||
result = await _repo.ConfigGetAllAsync();
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, GetRandTOut(redisLongTimeCache));
|
||||
}
|
||||
Log.Debug($"ConfigGetAllAsync Read from {source}");
|
||||
if (result == null)
|
||||
@@ -468,10 +476,6 @@ namespace MP.Data.Services.IOC
|
||||
/// <returns></returns>
|
||||
private async Task<T> GetOrFetchAsync<T>(string cacheKey, Func<Task<T>> fetchFunc, TimeSpan expiration)
|
||||
{
|
||||
// GetOrSetAsync di Fusion cache:
|
||||
// - TryGetValue, se mancasse crea un lock solo per QUELLA key
|
||||
// - Esegue fetchFunc (la logica Redis + DB)
|
||||
// - Salva in memoria e rilascia il lock
|
||||
return await _cache.GetOrSetAsync<T>(
|
||||
cacheKey,
|
||||
async ct => await fetchFunc(),
|
||||
@@ -548,7 +552,7 @@ namespace MP.Data.Services.IOC
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchina).ToHashSet<string>();
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}, TimeSpan.FromMinutes(15));
|
||||
@@ -570,7 +574,7 @@ namespace MP.Data.Services.IOC
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchinaSlave).Distinct().ToHashSet<string>();
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}, TimeSpan.FromMinutes(15));
|
||||
@@ -597,7 +601,7 @@ namespace MP.Data.Services.IOC
|
||||
result = await _repo.Macchine2SlaveAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
@@ -1066,19 +1070,19 @@ namespace MP.Data.Services.IOC
|
||||
string currVals = $"idxMacchina: {idxMacchina} | valOut: {valore} | dtEve: {dtEve} | dtCurr:{dtCurr}";
|
||||
if (dtEve == null || dtCurr == null)
|
||||
{
|
||||
Log.Warn($"procInput: null found | {currVals}");
|
||||
Log.Warn($"{_className} | procInput: null found | {currVals}");
|
||||
}
|
||||
else if (dtEve.Length < 17 || dtCurr.Length < 17)
|
||||
{
|
||||
Log.Info($"procInput: invalid data | {currVals}");
|
||||
Log.Info($"{_className} | procInput: invalid data | {currVals}");
|
||||
}
|
||||
else if (string.IsNullOrEmpty(idxMacchina))
|
||||
{
|
||||
Log.Info($"procInput: missing IdxMacchina | {currVals}");
|
||||
Log.Info($"{_className} | procInput: missing IdxMacchina | {currVals}");
|
||||
}
|
||||
else if (string.IsNullOrEmpty(valore))
|
||||
{
|
||||
Log.Info($"procInput: missing valOut | {currVals}");
|
||||
Log.Info($"{_className} | procInput: missing valOut | {currVals}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -21,8 +22,14 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public LandDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public LandDataService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
Repository.MpLand.IMpLandRepository mpLandRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_mpLandRepository = mpLandRepository;
|
||||
// conf DB
|
||||
string connStr = _configuration.GetConnectionString("MP.Land");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
@@ -31,28 +38,21 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new Controllers.MpLandController(configuration);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"LandService | MpLandController OK");
|
||||
sb.AppendLine($"LandService | MpLandRepository OK");
|
||||
Log.Info(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public static MpLandController dbController { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce info dimensione, tabelle e num righe DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DbSizeModel> AllDbInfo()
|
||||
public async Task<List<DbSizeModel>> AllDbInfoAsync()
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
@@ -61,7 +61,7 @@ namespace MP.Data.Services
|
||||
List<DbSizeModel> result = new List<DbSizeModel>();
|
||||
// cerco in _redisConn...
|
||||
string currKey = $"{redisBaseKey}:DbInfo:ALL";
|
||||
RedisValue rawData = _redisDb.StringGet(currKey);
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<DbSizeModel>>($"{rawData}");
|
||||
@@ -69,17 +69,17 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.AllDbInfo();
|
||||
result = await _mpLandRepository.AllDbInfoAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, UltraFastCache);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<DbSizeModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"AllDbInfo | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"AllDbInfoAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -88,15 +88,15 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
/// <param name="UserName"></param>
|
||||
/// <returns></returns>
|
||||
public List<IobDTO> IobListAll()
|
||||
public async Task<List<IobDTO>> IobListAllAsync()
|
||||
{
|
||||
string source = "DB";
|
||||
List<IobDTO>? dbResult = new List<IobDTO>();
|
||||
string currKey = $"{redisBaseKey}:IobList";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
string? rawData = _redisDb.StringGet(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData) && rawData.Length > 2)
|
||||
var rawData = await _redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<IobDTO>>(rawData);
|
||||
@@ -105,10 +105,10 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
// recupero RRL missing
|
||||
var listRRl = dbController.RemRebootLogGetLast();
|
||||
var listRRlAdd = dbController.RemRebootLogGetLastNoMacc();
|
||||
var listRRl = await _mpLandRepository.RemRebootLogGetLastAsync();
|
||||
var listRRlAdd = await _mpLandRepository.RemRebootLogGetLastNoMaccAsync();
|
||||
// recupero lista macchine
|
||||
var ListMacch = dbController.MacchineGetAll();
|
||||
var ListMacch = await _mpLandRepository.MacchineGetAllAsync();
|
||||
// ...converto in DTO
|
||||
dbResult = ListMacch
|
||||
.Select(x => new IobDTO(x, IobInfo(x.IdxMacchina), MachIobConf(x.IdxMacchina)))
|
||||
@@ -125,14 +125,14 @@ namespace MP.Data.Services
|
||||
|
||||
// serializzo in cache _redisConn
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
_redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<IobDTO>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"IobListAll | {source} | {sw.ElapsedMilliseconds} ms");
|
||||
Log.Debug($"IobListAllAsync | {source} | {sw.ElapsedMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.RemRebootLogGetAll();
|
||||
result = _mpLandRepository.RemRebootLogGetAllAsync().GetAwaiter().GetResult();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, UltraFastCache);
|
||||
@@ -194,7 +194,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.RemRebootLogGetLast();
|
||||
result = _mpLandRepository.RemRebootLogGetLastAsync().GetAwaiter().GetResult();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, UltraFastCache);
|
||||
@@ -219,7 +219,6 @@ namespace MP.Data.Services
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
dbController.Dispose();
|
||||
}
|
||||
|
||||
// Free unmanaged resources here
|
||||
@@ -234,6 +233,7 @@ namespace MP.Data.Services
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly Repository.MpLand.IMpLandRepository _mpLandRepository;
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private bool _disposed = false;
|
||||
private string redisBaseKey = "MP:LAND:Cache";
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DbModels;
|
||||
using MP.Data.Repository.Anag;
|
||||
using MP.Data.Repository.Production;
|
||||
using MP.Data.Repository.System;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
@@ -8,8 +11,8 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -18,32 +21,34 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
public class ListSelectDataSrv : BaseServ
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private readonly IAnagRepository _anagRepository;
|
||||
private readonly IProductionRepository _productionRepository;
|
||||
private readonly ISystemRepository _systemRepository;
|
||||
private bool _disposed = false;
|
||||
private string redisBaseKey = "MP:ALL:Cache";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public ListSelectDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public ListSelectDataSrv(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
IAnagRepository anagRepository,
|
||||
IProductionRepository productionRepository,
|
||||
ISystemRepository systemRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
// conf DB
|
||||
string connStr = _configuration.GetConnectionString("MP.All");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
Log.Error("ConnString empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
dbController = new Controllers.MpSpecController(configuration);
|
||||
sb.AppendLine($"ListSelectDataSrv | MpSpecController OK");
|
||||
Log.Info(sb.ToString());
|
||||
}
|
||||
_anagRepository = anagRepository;
|
||||
_productionRepository = productionRepository;
|
||||
_systemRepository = systemRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public static Controllers.MpSpecController dbController { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -54,14 +59,14 @@ namespace MP.Data.Services
|
||||
/// <param name="azienda">cod azienda, * = tutte</param>
|
||||
/// <param name="searchVal">Ricerca testuale</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetSearch(int numRecord, string azienda, string searchVal)
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetSearch(int numRecord, string tipoArt, string azienda, string searchVal)
|
||||
{
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<AnagArticoliModel>? result = new List<AnagArticoliModel>();
|
||||
// cerco in _redisConn...
|
||||
string currKey = $"{redisBaseKey}:Art:{azienda}:{searchVal}:{numRecord}";
|
||||
string currKey = $"{redisBaseKey}:Art:{azienda}:{tipoArt}:{searchVal}:{numRecord}";
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
@@ -70,10 +75,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ArticoliGetSearch(numRecord, azienda, searchVal);
|
||||
#if false
|
||||
result = await Task.FromResult(dbController.ArticoliGetSearch(numRecord, azienda, searchVal));
|
||||
#endif
|
||||
result = await _anagRepository.ArticoliGetSearchAsync(numRecord, tipoArt, azienda, searchVal);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
@@ -83,7 +85,7 @@ namespace MP.Data.Services
|
||||
result = new List<AnagArticoliModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ArticoliGetSearch | azienda: {azienda} | searchVal: {searchVal} | numRecord: {numRecord} | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Trace($"ArticoliGetSearchAsync | azienda: {azienda} | tipoArt: {tipoArt} | searchVal: {searchVal} | numRecord: {numRecord} | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -107,7 +109,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ConfigGetAll();
|
||||
result = await _systemRepository.ConfigGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, LongCache);
|
||||
@@ -117,7 +119,7 @@ namespace MP.Data.Services
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -163,7 +165,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbController.ListLinkAll());
|
||||
result = await _systemRepository.ListLinkAllAsync();
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
@@ -173,7 +175,7 @@ namespace MP.Data.Services
|
||||
result = new List<LinkMenuModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ListLinkAll | tipoLink: * | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ListLinkAllAsync | tipoLink: * | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -199,7 +201,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbController.ListLinkFilt(tipoLink));
|
||||
result = await _systemRepository.ListLinkFiltAsync(tipoLink);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
@@ -235,7 +237,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbController.MacchineByMatrOper(MatrOpr));
|
||||
result = await _productionRepository.MacchineByMatrOperAsync(MatrOpr);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
@@ -257,12 +259,6 @@ namespace MP.Data.Services
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
dbController.Dispose();
|
||||
}
|
||||
|
||||
// Free unmanaged resources here
|
||||
_disposed = true;
|
||||
}
|
||||
@@ -273,14 +269,6 @@ namespace MP.Data.Services
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private bool _disposed = false;
|
||||
private string redisBaseKey = "MP:ALL:Cache";
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
@@ -391,7 +379,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
return answ;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,6 @@ namespace MP.Data.Services
|
||||
|
||||
public event Action EA_OperUpdated = null!;
|
||||
|
||||
public event Action EA_PageUpdated = null!;
|
||||
|
||||
public event Action EA_ResetFooterTimer = null!;
|
||||
|
||||
#endregion Public Events
|
||||
|
||||
#region Public Properties
|
||||
@@ -707,26 +703,12 @@ namespace MP.Data.Services
|
||||
|
||||
private AnagOperatoriModel? _rigaOper;
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga IN SECONDI
|
||||
/// </summary>
|
||||
private int cacheTtlLong = 60 * 5;
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache breve IN SECONDI
|
||||
/// </summary>
|
||||
private int cacheTtlShort = 60 * 1;
|
||||
|
||||
private string lastIdxMacc = "";
|
||||
|
||||
private DateTime lastUserUpd = DateTime.Now;
|
||||
|
||||
private Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private string redisBaseKey = "MP:TAB:User";
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MonDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public MonDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpMon.IMpMonRepository mpMonRepository) : base(configuration, redConn, mpMonRepository)
|
||||
{
|
||||
// setup canali pub/sub
|
||||
dataPipe = new MessagePipe(redisConn, Constants.MON_ACT_MSE_DATA_KEY);
|
||||
@@ -113,17 +113,17 @@ namespace MP.Data.Services
|
||||
if (resto == 0)
|
||||
{
|
||||
// invio in channel blink il segnale
|
||||
blinkPipe.sendMessage("true");
|
||||
await blinkPipe.SendMessageAsync("true");
|
||||
Log.Debug("Elapsed Fast Timer Blink");
|
||||
}
|
||||
else
|
||||
{
|
||||
// invio in channel blink segnale false
|
||||
blinkPipe.sendMessage("false");
|
||||
await blinkPipe.SendMessageAsync("false");
|
||||
// rileggo dati...
|
||||
var newData = await MseGetAll();
|
||||
// invio tramite la pipe...
|
||||
dataPipe.sendMessage(JsonConvert.SerializeObject(newData));
|
||||
await dataPipe.SendMessageAsync(JsonConvert.SerializeObject(newData));
|
||||
Log.Debug("Elapsed Fast Timer reload");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ using MP.Data.Repository.Mtc;
|
||||
using StackExchange.Redis;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Mtc
|
||||
{
|
||||
@@ -18,7 +19,8 @@ namespace MP.Data.Services.Mtc
|
||||
public MtcSetupService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IMtcSetupRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IMtcSetupRepository repo) : base(config, cache, redis)
|
||||
{
|
||||
_className = "MtcSetup";
|
||||
_repo = repo;
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.Conf;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data.DbModels;
|
||||
using MP.Data.Repository.Production;
|
||||
using MP.Data.Repository.System;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -21,32 +20,31 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
public class OrderDataSrv : BaseServ
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private readonly IProductionRepository _productionRepository;
|
||||
private readonly ISystemRepository _systemRepository;
|
||||
private bool _disposed = false;
|
||||
private string redisBaseKey = "MP:ALL:Cache";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public OrderDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public OrderDataSrv(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
IProductionRepository productionRepository,
|
||||
ISystemRepository systemRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
// conf DB
|
||||
string connStr = _configuration.GetConnectionString("MP.All");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
Log.Error("ConnString empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new Controllers.MpSpecController(configuration);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"OrderDataSrv | MpSpecController OK");
|
||||
Log.Info(sb.ToString());
|
||||
}
|
||||
_productionRepository = productionRepository;
|
||||
_systemRepository = systemRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public static Controllers.MpSpecController dbController { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -71,7 +69,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ConfigGetAll();
|
||||
result = await _systemRepository.ConfigGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, LongCache);
|
||||
@@ -81,7 +79,7 @@ namespace MP.Data.Services
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -114,7 +112,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbController.ListODLFilt(inCorso, CodArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate));
|
||||
result = await _productionRepository.ListODLFiltAsync(inCorso, CodArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
@@ -124,7 +122,7 @@ namespace MP.Data.Services
|
||||
result = new List<ODLExpModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ListODLFilt | CodArt: {CodArt} | IdxMacchina: {IdxMacchina} | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ListODLFiltAsync | CodArt: {CodArt} | IdxMacchina: {IdxMacchina} | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -136,12 +134,6 @@ namespace MP.Data.Services
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
dbController.Dispose();
|
||||
}
|
||||
|
||||
// Free unmanaged resources here
|
||||
_disposed = true;
|
||||
}
|
||||
@@ -151,13 +143,5 @@ namespace MP.Data.Services
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private bool _disposed = false;
|
||||
private string redisBaseKey = "MP:ALL:Cache";
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -13,7 +14,11 @@ namespace MP.Data.Services
|
||||
/// Init servizio TAB
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public SchedulerDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public SchedulerDataService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -15,7 +16,11 @@ namespace MP.Data.Services
|
||||
/// Init servizio TAB
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public SharedMemService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public SharedMemService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.Conf;
|
||||
using MP.Data.Controllers;
|
||||
using MP.Data.DbModels;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
@@ -20,9 +19,10 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatusData(IConfiguration configuration, IConnectionMultiplexer redConn)
|
||||
public StatusData(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpMon.IMpMonRepository mpMonRepository)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_mpMonRepository = mpMonRepository;
|
||||
|
||||
// setup componenti REDIS
|
||||
this.redisConn = redConn;
|
||||
@@ -42,9 +42,8 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new MpMonController(configuration);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"StatusData | MpMonController OK");
|
||||
sb.AppendLine($"StatusData | MpMonRepository OK");
|
||||
Log.Info(sb.ToString());
|
||||
}
|
||||
|
||||
@@ -70,8 +69,6 @@ namespace MP.Data.Services
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public static MpMonController dbController { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario dei tag configurati per IOB
|
||||
/// </summary>
|
||||
@@ -102,7 +99,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ConfigGetAll();
|
||||
result = await _mpMonRepository.ConfigGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, LongCache);
|
||||
@@ -112,7 +109,7 @@ namespace MP.Data.Services
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -186,7 +183,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbController.MacchineGetAll());
|
||||
result = await _mpMonRepository.MacchineGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
@@ -198,7 +195,6 @@ namespace MP.Data.Services
|
||||
sw.Stop();
|
||||
Log.Debug($"MacchineGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
//return Task.FromResult(dbController.MacchineGetAll());
|
||||
}
|
||||
|
||||
public async Task<List<MacchineModel>> MacchineGetByGruppo(string CodGruppo)
|
||||
@@ -217,8 +213,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbController.MacchineGetFilt(CodGruppo));
|
||||
//result = dbController.MacchineGetFilt(CodGruppo);
|
||||
result = await _mpMonRepository.MacchineGetFiltAsync(CodGruppo);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
@@ -339,7 +334,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await dbController.MseGetAllAsync(maxAge);
|
||||
result = await _mpMonRepository.MseGetAllAsync(maxAge);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(Constants.redisMseKey, rawData, UltraFastCache);
|
||||
@@ -383,8 +378,6 @@ namespace MP.Data.Services
|
||||
MachineProdStatus.Clear();
|
||||
// REDIS dispose
|
||||
redisDb = null;
|
||||
// Clear database controller
|
||||
dbController.Dispose();
|
||||
}
|
||||
|
||||
// Free unmanaged resources here
|
||||
@@ -397,6 +390,7 @@ namespace MP.Data.Services
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
private readonly Repository.MpMon.IMpMonRepository _mpMonRepository;
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private bool _disposed = false;
|
||||
|
||||
@@ -512,7 +506,7 @@ namespace MP.Data.Services
|
||||
if (fileConfData.IobSetup.ContainsKey("***"))
|
||||
{
|
||||
// recupero elenco macchine...
|
||||
var elencoMacc = dbController.MacchineGetAll();
|
||||
var elencoMacc = _mpMonRepository.MacchineGetAllAsync().GetAwaiter().GetResult();
|
||||
// x ogni macchina creo le righe standard da conf...
|
||||
var baseConf = fileConfData.IobSetup.Where(x => x.Key == "***").FirstOrDefault();
|
||||
foreach (var item in elencoMacc)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public TabDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public TabDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpMon.IMpMonRepository mpMonRepository) : base(configuration, redConn, mpMonRepository)
|
||||
{
|
||||
// setup canali pub/sub
|
||||
dataPipe = new MessagePipe(redisConn, Constants.TAB_ACT_MSE_DATA_KEY, false);
|
||||
@@ -133,17 +133,17 @@ namespace MP.Data.Services
|
||||
if (resto == 0)
|
||||
{
|
||||
// invio in channel blink il segnale
|
||||
blinkPipe.sendMessage("true");
|
||||
await blinkPipe.SendMessageAsync("true");
|
||||
Log.Trace("Elapsed Fast Timer Blink");
|
||||
}
|
||||
else
|
||||
{
|
||||
// invio in channel blink segnale false
|
||||
blinkPipe.sendMessage("false");
|
||||
await blinkPipe.SendMessageAsync("false");
|
||||
// rileggo dati...
|
||||
var newData = await MseGetAll();
|
||||
// invio tramite la pipe...
|
||||
dataPipe.sendMessage(JsonConvert.SerializeObject(newData));
|
||||
await dataPipe.SendMessageAsync(JsonConvert.SerializeObject(newData));
|
||||
Log.Trace("Elapsed Fast Timer reload");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.DTO;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data.Controllers;
|
||||
using MP.Data.DbModels;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
@@ -15,6 +16,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -26,7 +28,12 @@ namespace MP.Data.Services
|
||||
/// Init servizio TAB
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public TabDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public TabDataService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
MpIocController iocContr
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
@@ -41,7 +48,7 @@ namespace MP.Data.Services
|
||||
StringBuilder sb = new StringBuilder();
|
||||
dbTabController = new Controllers.MpTabController(configuration);
|
||||
sb.AppendLine($"TabDataService | MpTabController OK");
|
||||
dbIocController = new Controllers.MpIocController(configuration);
|
||||
dbIocController = iocContr;// new Controllers.MpIocController(configuration);
|
||||
sb.AppendLine($"TabDataService | MpIocController OK");
|
||||
dbInveController = new Controllers.MpInveController(configuration);
|
||||
sb.AppendLine($"TabDataService | MpInveController OK");
|
||||
@@ -392,7 +399,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ArticoliGetByTipo | Read from {readType}: {ts.TotalMilliseconds}ms");
|
||||
Log.Debug($"ArticoliGetByTipoAsync | Read from {readType}: {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -505,7 +512,7 @@ namespace MP.Data.Services
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1485,7 +1492,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
sw.Stop();
|
||||
|
||||
string callName = $"MacchineByMatrOper.{source}";
|
||||
string callName = $"MacchineByMatrOperAsync.{source}";
|
||||
int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds);
|
||||
if (numRec >= nRecLog)
|
||||
{
|
||||
@@ -2412,7 +2419,7 @@ namespace MP.Data.Services
|
||||
#if false
|
||||
Log.Debug($"PODL_getByKey | {idxPODL} | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
#endif
|
||||
string callName = $"PODL_getByKey.{source}";
|
||||
string callName = $"PODL_getByKeyAsync.{source}";
|
||||
int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds);
|
||||
if (numRec >= nRecLog)
|
||||
{
|
||||
@@ -3417,7 +3424,7 @@ namespace MP.Data.Services
|
||||
result = new StatoMacchineModel();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"StatoMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatoMacchinaAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3498,7 +3505,7 @@ namespace MP.Data.Services
|
||||
result = new List<TemplateKitModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"TemplateKitFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"TemplateKitFiltAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3945,75 +3952,13 @@ namespace MP.Data.Services
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria _redisConn dato pat2Flush, metodo sincrono
|
||||
/// </summary>
|
||||
/// <param name="pat2Flush"></param>
|
||||
/// <returns></returns>
|
||||
private bool ExecFlushRedisPattern(RedisValue pat2Flush)
|
||||
{
|
||||
bool answ = false;
|
||||
var masterEndpoint = _redisConn.GetEndPoints()
|
||||
.Where(ep => _redisConn.GetServer(ep).IsConnected && !_redisConn.GetServer(ep).IsReplica)
|
||||
.FirstOrDefault();
|
||||
|
||||
// sepattern è "*" elimino intero DB...
|
||||
if (masterEndpoint != null && (pat2Flush.Equals(new RedisValue("*")) || pat2Flush == RedisValue.Null))
|
||||
{
|
||||
_redisConn.GetServer(masterEndpoint).FlushDatabase(database: _redisDb.Database);
|
||||
}
|
||||
else
|
||||
{
|
||||
var server = _redisConn.GetServer(masterEndpoint);
|
||||
var keys = server.Keys(database: _redisDb.Database, pattern: pat2Flush, pageSize: 1000);
|
||||
var batch = new List<RedisKey>();
|
||||
foreach (var key in keys)
|
||||
{
|
||||
batch.Add(key);
|
||||
|
||||
// Flush in batches of 1000
|
||||
if (batch.Count >= 1000)
|
||||
{
|
||||
foreach (var item in batch)
|
||||
_redisDb.KeyDelete(item);
|
||||
|
||||
batch.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Flush remaining keys
|
||||
foreach (var item in batch)
|
||||
_redisDb.KeyDelete(item);
|
||||
}
|
||||
answ = true;
|
||||
#if false
|
||||
var listEndpoints = redisConn.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConn.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
redisDb.KeyDelete(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// notifico update ai client in ascolto x reset cache
|
||||
NotifyReloadRequest($"FlushRedisCache | {pat2Flush}");
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria _redisConn dato pat2Flush in async
|
||||
/// </summary>
|
||||
/// <param name="pat2Flush"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ExecFlushRedisPatternAsync(RedisValue pat2Flush)
|
||||
private async new Task<bool> ExecFlushRedisPatternAsync(RedisValue pat2Flush)
|
||||
{
|
||||
bool answ = false;
|
||||
var masterEndpoint = _redisConn.GetEndPoints()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.Conf;
|
||||
using MP.Data.DbModels;
|
||||
using MP.Data.Repository.FluxLog;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
@@ -13,6 +14,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -23,35 +25,57 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public TranslateSrv(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public TranslateSrv(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
Repository.MpVoc.IMpVocRepository mpVocRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
// conf DB
|
||||
string connStr = _configuration.GetConnectionString("MP.Voc");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
Log.Error("MP.Voc: ConnString empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new Controllers.MpVocController(configuration);
|
||||
InitDict();
|
||||
sw.Stop();
|
||||
Log.Info($"TranslateSrv | MpVocController OK | {sw.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
_mpVocRepository = mpVocRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public static Controllers.MpVocController dbController { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue traduzione dato vocabolario da Lingua + Lemma
|
||||
/// </summary>
|
||||
/// <param name="lemma"></param>
|
||||
/// <param name="lingua"></param>
|
||||
/// <returns></returns>
|
||||
public string Traduci(string lemma, string lingua = "IT")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(lemma)) return string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(lingua)) return lemma;
|
||||
|
||||
string linguaKey = lingua.ToLowerInvariant().Trim();
|
||||
string cacheKey = $"vocab:{linguaKey}";
|
||||
|
||||
// FusionCache gestisce il lock e recupera l'intero dizionario della lingua.
|
||||
// Se è in L1 (Memory), restituisce l'oggetto C# istantaneamente.
|
||||
// Se non c'è, passa a L2 (Redis) o invoca la factory per caricarlo.
|
||||
var dizionarioLingua = _cache.GetOrSet<Dictionary<string, string>>(
|
||||
cacheKey,
|
||||
_ => _mpVocRepository.VocabolarioGetLang(linguaKey),
|
||||
options => options
|
||||
.SetDuration(TimeSpan.FromHours(8)) // Durata logica della cache
|
||||
.SetFailSafe(true, TimeSpan.FromHours(1)) // Se Redis/DB è giù, usa i vecchi dati L1
|
||||
);
|
||||
|
||||
// Ricerca O(1) nel dizionario in memoria
|
||||
if (dizionarioLingua != null && dizionarioLingua.TryGetValue(lemma, out var traduzione))
|
||||
{
|
||||
return traduzione;
|
||||
}
|
||||
|
||||
// Fallback: se la parola non è censita, restituisce il lemma originale (lingua + lemma)
|
||||
return $"{lingua}_{lemma}";
|
||||
}
|
||||
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Recupero elenco config
|
||||
/// </summary>
|
||||
@@ -73,7 +97,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ConfigGetAll();
|
||||
result = await _mpVocRepository.ConfigGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, LongCache);
|
||||
@@ -83,9 +107,10 @@ namespace MP.Data.Services
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Pulizia cache Redis (tutta)
|
||||
@@ -93,12 +118,15 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FlushCache()
|
||||
{
|
||||
#if false
|
||||
RedisValue pattern = new RedisValue($"{redisBaseKey}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// rileggo vocabolario!
|
||||
var rawData = await VocabolarioGetAll();
|
||||
DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione);
|
||||
return answ;
|
||||
return answ;
|
||||
#endif
|
||||
return await FlushFusionCacheAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -107,9 +135,51 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FlushCache(string KeyReq)
|
||||
{
|
||||
#if false
|
||||
RedisValue pattern = new RedisValue($"{redisBaseKey}:{KeyReq}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
return answ;
|
||||
#endif
|
||||
return await FlushFusionCacheAsync(KeyReq);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancellazione FusionCache (totale)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> FlushFusionCacheAsync()
|
||||
{
|
||||
await _cache.ClearAsync(allowFailSafe: false);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancellazione FusionCache dato singolo tag
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> FlushFusionCacheAsync(string tag)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tag)) return false;
|
||||
|
||||
await _cache.RemoveByTagAsync(tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancellazione FusionCache dato elenco tags
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> FlushFusionCacheAsync(List<string> listTags)
|
||||
{
|
||||
if (listTags == null || listTags.Count == 0) return false;
|
||||
|
||||
// Generiamo i Task di rimozione ed eseguiamoli in parallelo su Redis/L1
|
||||
var tasks = listTags
|
||||
.Where(tag => !string.IsNullOrWhiteSpace(tag))
|
||||
.Select(tag => _cache.RemoveByTagAsync(tag).AsTask());
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,6 +188,17 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<List<LingueModel>> LingueGetAll()
|
||||
{
|
||||
string currKey = $"{redisBaseKey}:Lang";
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "LingueGetAll",
|
||||
cacheKey: currKey,
|
||||
expiration: GetRandTOut(redisShortTimeCache),
|
||||
fetchFunc: async () => await _mpVocRepository.LingueGetAllAsync() ?? new(),
|
||||
tagList: [currKey]
|
||||
);
|
||||
|
||||
#if false
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -133,7 +214,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.LingueGetAll();
|
||||
result = await _mpVocRepository.LingueGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
@@ -144,9 +225,11 @@ namespace MP.Data.Services
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"LingueGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Traduzione termine
|
||||
/// </summary>
|
||||
@@ -162,7 +245,8 @@ namespace MP.Data.Services
|
||||
answ = DictVocab[key];
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Recupero elenco config
|
||||
@@ -170,6 +254,18 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<List<VocabolarioModel>> VocabolarioGetAll()
|
||||
{
|
||||
string currKey = $"{redisBaseKey}:VocAll";
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "VocabolarioGetAll",
|
||||
cacheKey: currKey,
|
||||
expiration: GetRandTOut(redisShortTimeCache),
|
||||
fetchFunc: async () => await _mpVocRepository.VocabolarioGetAllAsync() ?? new(),
|
||||
tagList: [currKey]
|
||||
);
|
||||
|
||||
|
||||
#if false
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -185,7 +281,7 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.VocabolarioGetAll();
|
||||
result = await _mpVocRepository.VocabolarioGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
@@ -196,63 +292,41 @@ namespace MP.Data.Services
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"VocabolarioGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Vocabolario x recupero rapido traduzioni
|
||||
/// </summary>
|
||||
protected static Dictionary<string, string> DictVocab = new Dictionary<string, string>();
|
||||
protected static Dictionary<string, string> DictVocab = new Dictionary<string, string>();
|
||||
#endif
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
DictVocab.Clear();
|
||||
dbController.Dispose();
|
||||
}
|
||||
|
||||
// Free unmanaged resources here
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
// Call base class implementation.
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private bool _disposed = false;
|
||||
|
||||
private string redisBaseKey = "MP:Voc:Cache";
|
||||
|
||||
private readonly Repository.MpVoc.IMpVocRepository _mpVocRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Inizializzazione dict vari
|
||||
/// </summary>
|
||||
private static void InitDict()
|
||||
{
|
||||
// inizializzo dizionario vocabolario
|
||||
var rawData = dbController.VocabolarioGetAll();
|
||||
DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Esegue flush memoria _redisConn dato pat2Flush
|
||||
/// </summary>
|
||||
@@ -291,26 +365,10 @@ namespace MP.Data.Services
|
||||
}
|
||||
}
|
||||
answ = true;
|
||||
#if false
|
||||
var listEndpoints = redisConn.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConn.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,8 @@ namespace MP.Data.Services.Utils
|
||||
public StatsAggrService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsAggrRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsAggrRepository repo) : base(config, cache, redis)
|
||||
{
|
||||
_className = "StatsAggr";
|
||||
_repo = repo;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils
|
||||
public StatsCodeService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsCodeRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsCodeRepository repo
|
||||
) : base(config, cache, redis)
|
||||
{
|
||||
_className = "StatsStatusCode";
|
||||
_repo = repo;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils
|
||||
public StatsDetailService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsDetailRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsDetailRepository repo
|
||||
) : base(config,cache, redis)
|
||||
{
|
||||
_className = "StatsDetail";
|
||||
_repo = repo;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils
|
||||
public StatsErrService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsErrRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsErrRepository repo
|
||||
) : base(config,cache, redis)
|
||||
{
|
||||
_className = "StatsErr";
|
||||
_repo = repo;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.INVE</RootNamespace>
|
||||
<Version>8.16.2604.2716</Version>
|
||||
<Version>8.16.2606.408</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MAPOINVE </i>
|
||||
<h4>Versione: 8.16.2604.2716</h4>
|
||||
<h4>Versione: 8.16.2606.408</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2604.2716
|
||||
8.16.2606.408
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2604.2716</version>
|
||||
<version>8.16.2606.408</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/MP.INVE.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace MP.IOC.Controllers
|
||||
/// <summary>
|
||||
/// Sistema Dossier/Snapshot giornalieri x impianto indicato, andando a generare 1 Dossier
|
||||
/// giornaliero x ogni giornata dall'ultimo registrato alla data corrente
|
||||
/// es: http://url_site/MP/IO/IOB/fixDailyDossier/SIMUL_03
|
||||
/// es: http://url_site/MP/IOC/api/IOB/fixDailyDossier/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
@@ -174,7 +174,7 @@ namespace MP.IOC.Controllers
|
||||
/// <summary>
|
||||
/// Sistema ODL giornalieri x impianto indicato, andando a generare 1 ODL giornaliero x ogni
|
||||
/// giornata dall'ultimo ODL aperto alla data corrente
|
||||
/// es: http://url_site/MP/IO/IOB/fixDailyOdl/SIMUL_03
|
||||
/// es: http://url_site/MP/IOC/api/IOB/fixDailyOdl/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
@@ -218,7 +218,7 @@ namespace MP.IOC.Controllers
|
||||
/// Sistema ODL giornalieri x impianto indicato, andando a generare 1 ODL giornaliero x ogni
|
||||
/// giornata dall'ultimo ODL aperto alla data corrente + conferma pezzi (es TFT x ODL
|
||||
/// giornalieri energia)
|
||||
/// es: http://url_site/MP/IO/IOB/fixDailyOdlConfPzCount/SIMUL_03
|
||||
/// es: http://url_site/MP/IOC/api/IOB/fixDailyOdlConfPzCount/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
@@ -525,7 +525,7 @@ namespace MP.IOC.Controllers
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce data-ora inizio dell'odl correntemente in lavorazione sulla macchina...
|
||||
/// es: http://url_site/MP/IO/IOB/getCurrOdlStart/SIMUL_03
|
||||
/// es: http://url_site/MP/IOC/api/IOB/getCurrOdlStart/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
+16
-1547
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>8.16.2605.1119</Version>
|
||||
<Version>8.16.2606.408</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+12
-4
@@ -42,18 +42,26 @@ logger.Info("RedisScript Provider configured");
|
||||
// Metodi principali x accesso dati
|
||||
var connStr = builder.Configuration.GetConnectionString("MP.Data")
|
||||
?? throw new InvalidOperationException("ConnString 'MP.Data' mancante.");
|
||||
|
||||
builder.Services.AddMemoryCache();
|
||||
|
||||
builder.Services.AddDbContextFactory<MoonProContext>(options =>
|
||||
options.UseSqlServer(connStr)
|
||||
.EnableSensitiveDataLogging(false) // true solo in Sviluppo
|
||||
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));
|
||||
|
||||
// MP.Data DbContext for Stats repositories
|
||||
string utilsConnString = builder.Configuration.GetConnectionString("MP.Utils") ?? "Server=localhost;Database=MoonPro_Utils; integrated security=True; MultipleActiveResultSets=True; App=MP.IOC;";
|
||||
string connStrUtils = builder.Configuration.GetConnectionString("MP.Utils")
|
||||
?? throw new InvalidOperationException("ConnString 'MP.Utils' mancante.");
|
||||
//?? "Server=localhost;Database=MoonPro_Utils; integrated security=True; MultipleActiveResultSets=True; App=MP.IOC;";
|
||||
builder.Services.AddDbContextFactory<MoonPro_UtilsContext>(options =>
|
||||
options.UseSqlServer(utilsConnString));
|
||||
options.UseSqlServer(connStrUtils).EnableSensitiveDataLogging(false)
|
||||
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));
|
||||
|
||||
var connStrFL = builder.Configuration.GetConnectionString("MP.Flux")
|
||||
?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante.");
|
||||
builder.Services.AddDbContextFactory<MoonPro_FluxContext>(options =>
|
||||
options.UseSqlServer(connStrFL)
|
||||
.EnableSensitiveDataLogging(false) // true solo in Sviluppo
|
||||
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));
|
||||
|
||||
// MP.Data Services Utils - Statistiche DB
|
||||
builder.Services.AddIocDataLayer();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 8.16.2605.1119</h4>
|
||||
<h4>Versione: 8.16.2606.408</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2605.1119
|
||||
8.16.2606.408
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2605.1119</version>
|
||||
<version>8.16.2606.408</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -5,6 +5,7 @@ using MP.Data.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Land.Components
|
||||
{
|
||||
@@ -21,9 +22,10 @@ namespace MP.Land.Components
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override void OnParametersSet()
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
ReloadData();
|
||||
await ReloadDataAsync();
|
||||
}
|
||||
|
||||
protected void SortRequested(Sorter.SortCallBack e)
|
||||
@@ -117,9 +119,9 @@ namespace MP.Land.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadData()
|
||||
private async Task ReloadDataAsync()
|
||||
{
|
||||
ListRecord = LDService.AllDbInfo();
|
||||
ListRecord = await LDService.AllDbInfoAsync();
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>MP.Land</RootNamespace>
|
||||
<Version>8.16.2605.0811</Version>
|
||||
<Version>8.16.2606.0408</Version>
|
||||
<Configurations>Debug;Release;Debug_LiManDebug</Configurations>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
<RunAnalyzersDuringBuild>True</RunAnalyzersDuringBuild>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user