- inizio modifica x inclusione calcolo MD5 e import DB Ricette
This commit is contained in:
Samuele Locatelli
2025-07-16 16:28:05 +02:00
parent def34dce68
commit 95f2b208c9
8 changed files with 204 additions and 140 deletions
+1 -68
View File
@@ -6,12 +6,8 @@ using System.Threading.Tasks;
namespace IOB_UT_NEXT
{
public class FtpActConf
public class FtpActConf : GenActConf
{
/// <summary>
/// ID azione configurata
/// </summary>
public string ActionId { get; set; } = "000";
/// <summary>
/// IP / DNS name del ServerAddr FTP
@@ -43,69 +39,6 @@ namespace IOB_UT_NEXT
/// </summary>
public bool SkipCert { get; set; } = true;
/// <summary>
/// Tempo di attesa in SEC standard prima della prossima ri-esecuzione
/// </summary>
public int ReExecVeto { get; set; } = 60;
/// <summary>
/// Note opzionali
/// </summary>
public string Note { get; set; } = "";
/// <summary>
/// Elenco step da eseguire
/// </summary>
public List<ActionConfig> StepsList { get; set; }
}
/// <summary>
/// Configurazione di un singolo step FTP
/// </summary>
public class ActionConfig
{
/// <summary>
/// ID azione (per ordinamento)
/// </summary>
public string Id { get; set; } = "00";
/// <summary>
/// Descrizione step
/// </summary>
public string Description { get; set; } = "00";
/// <summary>
/// Azione richiesta
/// </summary>
public ActType Action { get; set; } = ActType.CheckDir;
/// <summary>
/// Dizionario parametri specifici per azione richiesta (dipendenti da azione...)
/// </summary>
public Dictionary<string, string> ParamList { get; set; } = new Dictionary<string, string>();
}
/// <summary>
/// Enum azioni FTP gestite/da gestire
/// </summary>
public enum ActType
{
CheckDir,
CheckFile,
CreateDir,
DelDir,
DelFile,
//DelFileList,
DownloadDir,
DownloadFile,
GenRandomDir,
ListContent,
MirrorDirL2R,
MirrorDirR2L,
PingServer,
RemoveFileByName,
UploadDir,
UploadFile
}
}
+80
View File
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IOB_UT_NEXT
{
public class GenActConf
{
/// <summary>
/// ID azione configurata
/// </summary>
public string ActionId { get; set; } = "000";
/// <summary>
/// Tempo di attesa in SEC standard prima della prossima ri-esecuzione
/// </summary>
public int ReExecVeto { get; set; } = 60;
/// <summary>
/// Note opzionali
/// </summary>
public string Note { get; set; } = "";
/// <summary>
/// Elenco step da eseguire
/// </summary>
public List<ActionConfig> StepsList { get; set; }
/// <summary>
/// Configurazione di un singolo step FTP
/// </summary>
public class ActionConfig
{
/// <summary>
/// ID azione (per ordinamento)
/// </summary>
public string Id { get; set; } = "00";
/// <summary>
/// Descrizione step
/// </summary>
public string Description { get; set; } = "00";
/// <summary>
/// Azione richiesta
/// </summary>
public ActType Action { get; set; } = ActType.CheckDir;
/// <summary>
/// Dizionario parametri specifici per azione richiesta (dipendenti da azione...)
/// </summary>
public Dictionary<string, string> ParamList { get; set; } = new Dictionary<string, string>();
}
/// <summary>
/// Enum azioni gestite/da gestire
/// </summary>
public enum ActType
{
CheckDir,
CheckFile,
CreateDir,
DelDir,
DelFile,
//DelFileList,
DownloadDir,
DownloadFile,
GenRandomDir,
ListContent,
MirrorDirL2R,
MirrorDirR2L,
PingServer,
RemoveFileByName,
UploadDir,
UploadFile
}
}
}
+5
View File
@@ -180,10 +180,12 @@
<Compile Include="Config\Special\SiemensDto.cs" />
<Compile Include="Config\Special\StepActionDto.cs" />
<Compile Include="DataModel\Fimat.cs" />
<Compile Include="DataModel\UstdData.cs" />
<Compile Include="DataQueue.cs" />
<Compile Include="FileProcMan.cs" />
<Compile Include="DataModel\FluxData.cs" />
<Compile Include="FtpActConf.cs" />
<Compile Include="GenActConf.cs" />
<Compile Include="IniFile.cs" />
<Compile Include="IntConditionCheck.cs" />
<Compile Include="BitConditionCheck.cs" />
@@ -213,10 +215,13 @@
<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" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="Tools\ImportTaglierinaConf.json" />
<None Include="Tools\RefExcConv.json" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+11
View File
@@ -59,11 +59,22 @@ namespace IOB_UT_NEXT
#endregion Public Methods
}
/// <summary>
/// Elenco task di tipo FTP
/// </summary>
public class FtpTaskList
{
public List<FtpActConf> ListTask { get; set; } = new List<FtpActConf>();
}
/// <summary>
/// Elenco task generici
/// </summary>
public class GenTaskList
{
public List<GenActConf> ListTask { get; set; } = new List<GenActConf>();
}
/// <summary>
/// Gestione dati di timing
/// </summary>
+5 -5
View File
@@ -13,6 +13,11 @@ namespace IOB_UT_NEXT
{
#region Public Fields
/// <summary>
/// Hash REDIS x dati IOB
/// </summary>
public string redIobKey = "";
/// <summary>
/// Hash REDIS x dati IOB
/// </summary>
@@ -1425,11 +1430,6 @@ namespace IOB_UT_NEXT
/// </summary>
protected string redIobChannel = "IobChannel";
/// <summary>
/// Hash REDIS x dati IOB
/// </summary>
protected string redIobKey = "";
/// <summary>
/// Hash REDIS x dati server
/// </summary>
+28 -28
View File
@@ -110,7 +110,7 @@ namespace IOB_WIN_FTP.Iob
// Verificare il protocollo: dovrebbe togliere SOLO i task eseguiti...
Dictionary<string, string> taskDone = new Dictionary<string, string>();
ActionConfig currAct = new ActionConfig();
GenActConf.ActionConfig currAct = new GenActConf.ActionConfig();
var currActParam = new Dictionary<string, string>();
string actKey = "RemoteDir";
string newDir = "";
@@ -153,11 +153,11 @@ namespace IOB_WIN_FTP.Iob
actKey = "RemoteDir";
newDir = $"{RemoteBaseDir}/{item.Value}";
currActParam.Add(actKey, newDir);
currAct = new ActionConfig()
currAct = new GenActConf.ActionConfig()
{
Id = "01",
Description = "Verifica esistenza directory",
Action = ActType.CheckDir,
Action = GenActConf.ActType.CheckDir,
ParamList = currActParam
};
//eseguo step...
@@ -166,11 +166,11 @@ namespace IOB_WIN_FTP.Iob
if (!dirOk)
{
// nuovo act x crearla!
currAct = new ActionConfig()
currAct = new GenActConf.ActionConfig()
{
Id = "02",
Description = "Creazione directory",
Action = ActType.CreateDir,
Action = GenActConf.ActType.CreateDir,
ParamList = currActParam
};
//eseguo step...
@@ -359,15 +359,15 @@ namespace IOB_WIN_FTP.Iob
if (!string.IsNullOrEmpty(reqFolder))
{
// verifico se ci sia...
ActionConfig currAct = new ActionConfig();
GenActConf.ActionConfig currAct = new GenActConf.ActionConfig();
var currActParam = new Dictionary<string, string>();
// compongo remDir dai 2 parametri...
currActParam.Add("RemoteDir", $"{RemoteBaseDir}/{reqFolder}");
currAct = new ActionConfig()
currAct = new GenActConf.ActionConfig()
{
Id = "01",
Description = "Verifica esistenza directory",
Action = ActType.CheckDir,
Action = GenActConf.ActType.CheckDir,
ParamList = currActParam
};
//eseguo step...
@@ -655,7 +655,7 @@ namespace IOB_WIN_FTP.Iob
/// <param name="step"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private bool doStep(ActionConfig step)
private bool doStep(GenActConf.ActionConfig step)
{
bool fatto = false;
string remoteVal = "";
@@ -666,7 +666,7 @@ namespace IOB_WIN_FTP.Iob
// faccio switch in base al tipo di azione da eseguire...
switch (step.Action)
{
case ActType.CheckDir:
case GenActConf.ActType.CheckDir:
if (step.ParamList != null && step.ParamList.Count > 0)
{
sw.Restart();
@@ -685,10 +685,10 @@ namespace IOB_WIN_FTP.Iob
}
break;
case ActType.CheckFile:
case GenActConf.ActType.CheckFile:
break;
case ActType.CreateDir:
case GenActConf.ActType.CreateDir:
if (step.ParamList != null && step.ParamList.Count > 0)
{
sw.Restart();
@@ -715,29 +715,29 @@ namespace IOB_WIN_FTP.Iob
}
break;
case ActType.DelDir:
case GenActConf.ActType.DelDir:
break;
case ActType.DelFile:
case GenActConf.ActType.DelFile:
break;
case ActType.DownloadDir:
case GenActConf.ActType.DownloadDir:
break;
case ActType.DownloadFile:
case GenActConf.ActType.DownloadFile:
break;
case ActType.GenRandomDir:
case GenActConf.ActType.GenRandomDir:
break;
case ActType.ListContent:
case GenActConf.ActType.ListContent:
break;
case ActType.MirrorDirL2R:
case GenActConf.ActType.MirrorDirL2R:
break;
case ActType.MirrorDirR2L:
case GenActConf.ActType.MirrorDirR2L:
// eseguo mirroring directory
actKey = "FtpSync";
actVal = "SRC --> DEST | Size";
@@ -808,10 +808,10 @@ namespace IOB_WIN_FTP.Iob
break;
case ActType.PingServer:
case GenActConf.ActType.PingServer:
break;
case ActType.RemoveFileByName:
case GenActConf.ActType.RemoveFileByName:
string fName2Del = "";
int numRem = 0;
if (step.ParamList != null && step.ParamList.Count > 1)
@@ -854,10 +854,10 @@ namespace IOB_WIN_FTP.Iob
break;
case ActType.UploadDir:
case GenActConf.ActType.UploadDir:
break;
case ActType.UploadFile:
case GenActConf.ActType.UploadFile:
if (step.ParamList != null && step.ParamList.Count > 1)
{
sw.Restart();
@@ -964,11 +964,11 @@ namespace IOB_WIN_FTP.Iob
Dictionary<string, string> currActParam = new Dictionary<string, string>();
currActParam.Add("RemoteDir", remDir);
currActParam.Add("FileName2Del", fNameOdl);
ActionConfig currAct = new ActionConfig()
GenActConf.ActionConfig currAct = new GenActConf.ActionConfig()
{
Id = "01",
Description = "Clean Curr ODL Files",
Action = ActType.RemoveFileByName,
Action = GenActConf.ActType.RemoveFileByName,
ParamList = currActParam
};
// eseguo step...
@@ -996,11 +996,11 @@ namespace IOB_WIN_FTP.Iob
// invio file x ODL attivo
currActParam.Add("LocalFile", locFile);
currActParam.Add("RemoteFile", remFile);
ActionConfig currAct = new ActionConfig()
GenActConf.ActionConfig currAct = new GenActConf.ActionConfig()
{
Id = "01",
Description = "Upload File",
Action = ActType.UploadFile,
Action = GenActConf.ActType.UploadFile,
ParamList = currActParam
};
// eseguo step...
+2
View File
@@ -70,6 +70,8 @@ ENABLE_DYN_DATA=TRUE
DISABLE_SEND_WDST=TRUE
PARAM_CONF=L021.json
REST_CONF=L021.json
;parametri speciali x gestione checkfile
FileInPath=C:\Steamware\EmmegiFPW\FileTaglierina.xlsx
[BRANCH]
NAME=master
+72 -39
View File
@@ -4,6 +4,7 @@ using IOB_UT_NEXT.Config;
//using IOB_WIN_WS.DTO;
using MapoSDK;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.IO;
@@ -311,15 +312,15 @@ namespace IOB_WIN_WS.IobWs
parentForm.commPlcActive = true;
// chiamo metodo connect
var rawResp = ExecuteCallGet(GetUrlResource("GetStatus"), true);
lgInfo($"GetConnection | {rawResp} | EmmegiFPW.tryConnect");
var rawData = ExecuteCallGet(GetUrlResource("GetStatus"), true);
lgInfo($"GetConnection | {rawData} | EmmegiFPW.tryConnect");
if (!string.IsNullOrEmpty(rawResp))
if (!string.IsNullOrEmpty(rawData))
{
connectionOk = true;
queueInEnabCurr = true;
// salvo lo status con i relativi contenuti...
SaveCurrStatus(rawResp);
SaveCurrStatus(rawData);
if (adpRunning)
{
lgInfo("Connessione EmmegiFPW OK");
@@ -327,7 +328,7 @@ namespace IOB_WIN_WS.IobWs
}
else
{
lgError($"Errore check connessione EmmegiFPW | rawData: {rawResp}");
lgError($"Errore check connessione EmmegiFPW | rawData: {rawData}");
}
}
catch (Exception exc)
@@ -378,7 +379,7 @@ namespace IOB_WIN_WS.IobWs
}
}
private EmmegiResp.StatusDTO currStatusDTO = new EmmegiResp.StatusDTO();
private EmmegiResp.StatusDTO currStatusDTO { get; set; } = new EmmegiResp.StatusDTO();
private EmmegiResp.MachineStatus currState
{
@@ -408,10 +409,10 @@ namespace IOB_WIN_WS.IobWs
/// <summary>
/// Struttura delle risposte alle chiamare REST specifiche
/// </summary>
internal class EmmegiResp
public class EmmegiResp
{
internal enum MachineStatus
public enum MachineStatus
{
// manuale
ON,
@@ -439,7 +440,7 @@ namespace IOB_WIN_WS.IobWs
#region Internal Classes
[XmlRoot("result_workstation_status")]
internal class StatusDTO
public class StatusDTO
{
[XmlElement("workstation")]
public Workstation Workstation { get; set; }
@@ -448,7 +449,7 @@ namespace IOB_WIN_WS.IobWs
/// <summary>
/// Obj workstation
/// </summary>
internal class Workstation
public class Workstation
{
[XmlElement("id")]
@@ -482,7 +483,7 @@ namespace IOB_WIN_WS.IobWs
/// <summary>
/// Obj WorkstationId
/// </summary>
internal class WorkstationId
public class WorkstationId
{
[XmlAttribute("id")]
public string IdValue { get; set; }
@@ -697,6 +698,11 @@ namespace IOB_WIN_WS.IobWs
{
bool answ = false;
// verifico esistenza file csv preesistenti, se fossero stati creati otlre xx Ore prima li considera scaduti
// processo scrittura files PODL con OPRxxx x ogni file missing/scaduto
// NB: impiego array json + dati degli ODL non ancora eseguiti
// conf path e file
string basePath = @"x:\";
string srcFile = "DATA/TEMPLATE_ODL_USDT.csv";
@@ -735,36 +741,9 @@ namespace IOB_WIN_WS.IobWs
answ = true;
}
return answ;
}
/// <summary>
/// Effettua eventuale file import, archiviando file importati
/// - es gestione file excel di Giacovelli
/// - es gestione ritorno ricette FIMAT
/// </summary>
/// <returns></returns>
protected virtual bool ProcessFileImport()
{
bool answ = false;
/* ------------------------------------------
* esecuzione cablata, si potrebbe costruire una cosa più flessibile tramite conf:
* Oggetto MultiStepFileImport
* {
* StepName: Step01
* ProcType: Excel2Json
* FolderIn: xxx
* FolderOut: xxx
* FolderErr: xxx
* },{
* StepName: Step02
* ProcType: Json2RegGiac
* FolderIn: xxx
* FolderOut: xxx
* FolderErr: xxx
* }
* ------------------------------------------*/
#if false
if (!string.IsNullOrEmpty(fileImportFolder))
{
// verifico esistenza folders...
@@ -851,6 +830,60 @@ namespace IOB_WIN_WS.IobWs
}
}
}
}
#endif
}
/// <summary>
/// Effettua eventuale file import del file excel come array json in REDIS
/// </summary>
/// <returns></returns>
protected override bool ProcessFileImport()
{
bool answ = false;
/* ------------------------------------------
* esecuzione cablata, si potrebbe costruire una cosa più flessibile tramite conf,
* la procedura prevede:
* - controllo MD5 file sorgente *.xlsx
* - verifica MD5 precedente
* - verifica in redis del dict seralizzato
*
* in caso di mancanza REDIS o variazione MD5 --> lancio script import dati col relativo file di conf
* ------------------------------------------*/
// init condizioni check
bool cachePresent = false;
bool changedFile = true;
// cerco il file da controllare
string FileInPath = IOBConfFull.OptParGet("FileInPath");
if (!string.IsNullOrEmpty(FileInPath))
{
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);
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);
}
// 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;
}
}
}
return answ;
}