- ok ricerca file xlsx
- ok rilettura inc ache REDIS della conf
This commit is contained in:
Samuele Locatelli
2025-07-16 17:42:51 +02:00
parent 95f2b208c9
commit de9e329ae4
8 changed files with 116 additions and 121 deletions
+38
View File
@@ -9,6 +9,11 @@ namespace IOB_UT_NEXT
{
#region Public Constructors
/// <summary>
/// Init di base
/// </summary>
/// <param name="toolDir"></param>
/// <param name="exeFileName"></param>
public FileProcMan(string toolDir, string exeFileName)
{
this.confFileNameOut = "conf.json";
@@ -17,6 +22,34 @@ namespace IOB_UT_NEXT
appPath = Path.Combine(baseDir, exeName);
}
/// <summary>
/// Init con chiave Redis (es Emmegi FPW)
/// </summary>
/// <param name="toolDir"></param>
/// <param name="exeFileName"></param>
/// <param name="redisKey"></param>
/// <param name="refConfFileName"></param>
public FileProcMan(string toolDir, string exeFileName, string redisKey, string refConfFileName)
{
this.confFileNameOut = "conf.json";
this.redisKey = redisKey;
this.baseDir = toolDir;
this.exeName = exeFileName;
appPath = Path.Combine(baseDir, exeName);
// leggo file di conf base
string refConfFile = Path.Combine(baseDir, refConfFileName);
this.refConf = File.ReadAllText(refConfFile);
}
/// <summary>
/// Init completa (es Fimat/Giacovelli)
/// </summary>
/// <param name="archiveDir"></param>
/// <param name="convertDir"></param>
/// <param name="toolDir"></param>
/// <param name="exeFileName"></param>
/// <param name="refConfFileName"></param>
/// <param name="sheetName"></param>
public FileProcMan(string archiveDir, string convertDir, string toolDir, string exeFileName, string refConfFileName, string sheetName)
{
this.archDir = archiveDir;
@@ -90,6 +123,7 @@ namespace IOB_UT_NEXT
protected string exeName = "";
protected string refConf = "";
protected string sheetName = "";
protected string redisKey = "";
#endregion Protected Fields
@@ -115,6 +149,10 @@ namespace IOB_UT_NEXT
rawContent = rawContent.Replace("{{FileInPath}}", fixJsonDir(item));
rawContent = rawContent.Replace("{{FileOutPath}}", outFileName);
rawContent = rawContent.Replace("{{TargetSheetName}}", sheetName);
if (redisKey != null)
{
rawContent = rawContent.Replace("{{redisKey}}", redisKey);
}
rawContent = rawContent.Replace("987654321", $"{idxOdl}");
// calcolo nome file conf specifico
confFileNameOut = $"conf_{outFileName}";
+3 -1
View File
@@ -215,7 +215,9 @@
<Content Include="ExtLib\krcc64.dll" />
<Content Include="ExtLib\S_Fwlib32_V6.3.1.exe" />
<Content Include="ILLink\ILLink.Descriptors.LibraryBuild.xml" />
<Content Include="Tools\ExcImport.exe" />
<Content Include="Tools\ExcImport.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
+1
View File
@@ -72,6 +72,7 @@ PARAM_CONF=L021.json
REST_CONF=L021.json
;parametri speciali x gestione checkfile
FileInPath=C:\Steamware\EmmegiFPW\FileTaglierina.xlsx
FileImportConf=FPW_import.json
[BRANCH]
NAME=master
-104
View File
@@ -1,104 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace IOB_WIN_WS.DTO
{
public class EmmegiDTO
{
/// <summary>
/// Converte valore raw stato impianto nel formato specifico
/// </summary>
/// <returns></returns>
public static StatusDTO GetStatus(string xmlRaw)
{
StatusDTO answ = new StatusDTO();
// deserializzo
var serializer = new XmlSerializer(typeof(StatusDTO));
using (var reader = new StringReader(xmlRaw))
{
answ = (StatusDTO)serializer.Deserialize(reader);
}
return answ;
}
public enum MachineStatus
{
// manuale
ON,
// attrezzaggio = zero assi
SETUP,
// pronta, in automatico, in attesa carico pezzi
READY,
// posizionamento (teste morse o cambio utensili)
POSITIONING,
// attesa (carico/scarico barra, operazioni utente)
WAIT,
// in lavorazione effettiva
WORKING,
// emergenza
EMERGENCY,
// in allarme
ALARM,
// offline (poweroff?)
OFF_LINE,
OFF,
ERROR
}
[XmlRoot("result_workstation_status")]
public class StatusDTO
{
[XmlElement("workstation")]
public Workstation Workstation { get; set; }
}
/// <summary>
/// Obj workstation
/// </summary>
public class Workstation
{
[XmlElement("id")]
public WorkstationId Id { get; set; }
[XmlElement("status")]
public MachineStatus Status { get; set; }
[XmlElement("status_timestamp")]
public string StatusTimestampRaw { get; set; }
[XmlIgnore]
public DateTime StatusTimestamp
{
get => DateTime.ParseExact(StatusTimestampRaw, "yyyy-MM-dd HH:mm:ss", null);
}
[XmlElement("operator")]
public string Operator { get; set; }
[XmlElement("job_id")]
public string JobId { get; set; }
[XmlElement("operations")]
public int Operations { get; set; }
[XmlElement("tot_operations")]
public int TotalOperations { get; set; }
}
/// <summary>
/// Obj WorkstationId
/// </summary>
public class WorkstationId
{
[XmlAttribute("id")]
public string IdValue { get; set; }
}
}
}
+51 -16
View File
@@ -8,6 +8,7 @@ using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
@@ -44,7 +45,10 @@ namespace IOB_WIN_WS.IobWs
{
setupRestConf(getOptPar("REST_CONF"));
}
// sistemo conf errori e samplePeriod...
// sistemo chiavi specifiche redis...
rKeyConf = $"{redisMan.redIobKey}:Conf:ParamsUSTD";
rKeyMD5 = $"{redisMan.redIobKey}:FPW:FILE-MD5";
lgInfo("Rest - 02");
if (EnableTest)
@@ -53,6 +57,29 @@ namespace IOB_WIN_WS.IobWs
}
}
/// <summary>
/// Effettua rilettura DB conf ricette FPW
/// </summary>
private void ReloadConfDb()
{
// verifico presenza in cache REDIS
string rawData = redisMan.getRSV(rKeyConf);
if(!string.IsNullOrEmpty(rawData))
{
// deserializzo!
}
}
private Dictionary<string, string> ConfDbFPW = new Dictionary<string, string>();
/// <summary>
/// chiave salvataggio conf USTD
/// </summary>
private string rKeyConf = "";
/// <summary>
/// chiave check file config md5
/// </summary>
private string rKeyMD5 = "";
#endregion Public Constructors
#region Public Methods
@@ -856,6 +883,9 @@ namespace IOB_WIN_WS.IobWs
// init condizioni check
bool cachePresent = false;
bool changedFile = true;
string newMd5 = "";
string oldMd5 = "";
string rawData = "";
// cerco il file da controllare
string FileInPath = IOBConfFull.OptParGet("FileInPath");
if (!string.IsNullOrEmpty(FileInPath))
@@ -863,25 +893,30 @@ namespace IOB_WIN_WS.IobWs
if (File.Exists(FileInPath))
{
// verifico presenza in cache REDIS
string rKey = "IOB-WIN:Conf:ParamsUSTD";
// $"{redisMan.redIobKey}:FPW:RECIPE-FILE";
string rawData = redisMan.getRSV(rKey);
rawData = redisMan.getRSV(rKeyConf);
cachePresent = !string.IsNullOrEmpty(rawData) && rawData.Length > 2;
if (cachePresent)
{
// calcolo MD5
string newMd5 = baseUtils.GetFileMd5(FileInPath);
// verifico MD5 precedente
rKey = $"{redisMan.redIobKey}:FPW:FILE-MD5";
string oldMd5 = redisMan.getRSV(rKey);
changedFile = !newMd5.Equals(oldMd5);
}
// calcolo MD5
newMd5 = baseUtils.GetFileMd5(FileInPath);
// verifico MD5 precedente
oldMd5 = redisMan.getRSV(rKeyMD5);
changedFile = string.IsNullOrEmpty(oldMd5) || !newMd5.Equals(oldMd5);
// se c'è una condizione di trigger effettuo import chiamando task esterno + conf file
if (changedFile || !cachePresent)
{
// avvio proc import tramite exe tool esterno...
answ = true;
// recupero path file di conf x import
string FileConfPath = IOBConfFull.OptParGet("FileImportConf");
if (!string.IsNullOrEmpty(FileConfPath))
{
// da verificare exclToolDirPath
exclToolDirPath = "Tools";
// avvio proc import tramite exe tool esterno...
FileProcMan fpm = new FileProcMan("Tools", "ExcImport.exe", rKeyConf, FileConfPath);
fpm.doProcess(FileInPath, 0);
answ = true;
// aggiorno md5...
rKeyMD5 = $"{redisMan.redIobKey}:FPW:FILE-MD5";
redisMan.setRSV(rKeyMD5, newMd5);
}
}
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"ArchiveDir": "",
"ConvertDir": "",
"FileInPath": "C:\\Steamware\\EmmegiFPW\\FileTaglierina.xlsx",
"FileOutPath": "",
"IdxODL": 0,
"ProcessParamInt": {
"Codice": 0,
"Serie": 1,
"LungPezzo": 4,
"QuotaUscita": 5,
"LungBarra": 6,
"Altezza": 7
},
"ProcessParamStr": {},
"RedisDB": 10,
"RedisOut": "{{redisKey}}",
"RedisTTL": 360,
"Return": "Redis",
"ReturnDataType": "ParamTaglioUstd",
"TargetName": "Ricette",
"Type": "Excel"
}