Merge tag 'AddFtpIob03' into develop

Fix gestione reset file txt x ODL corrente + test TAB3 + fix creazione
folder ODL se missing, test vari
This commit is contained in:
Samuele Locatelli
2024-10-08 18:35:03 +02:00
9 changed files with 167 additions and 32 deletions
+8 -4
View File
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using static System.Net.Mime.MediaTypeNames;
@@ -375,7 +376,7 @@ namespace EgwProxy.Ftp.Test
esitoStep = $"Completato mirror R2L: {sw.ElapsedMilliseconds:N1} ms";
break;
case stepType.getRemoteList:
case stepType.delFileList:
if (item.paramList != null && item.paramList.Count > 1)
{
sw.Restart();
@@ -386,15 +387,18 @@ namespace EgwProxy.Ftp.Test
List<FluentFTP.FtpListItem> resListFilt = new List<FluentFTP.FtpListItem>();
foreach (var flItem in resList)
{
if(flItem.Type == FluentFTP.FtpObjectType.File && flItem.Name.Contains(fileSearch))
if(flItem.Type == FluentFTP.FtpObjectType.File && flItem.Name.EndsWith(fileSearch))
{
resListFilt.Add(flItem);
}
}
// elimino quelli trovati
if (resListFilt.Count>0)
{
esitoStep = $"Trovati {resListFilt.Count} file";
var fList = resListFilt.Select(x => x.FullName).ToList();
var numDel = ftpClient.DeleteFileList(fList);
// indico esito eliminazione
esitoStep = $"Eliminati {numDel}/{resListFilt.Count} file";
}
else
{
+1 -1
View File
@@ -32,10 +32,10 @@ namespace EgwProxy.Ftp.Test
createDir,
delDir,
delFile,
delFileList,
downloadDir,
downloadFile,
genRandomDir,
getRemoteList,
listContent,
mirrorDirL2R,
mirrorDirR2L,
+2 -2
View File
@@ -8,10 +8,10 @@
{
"id": "01",
"description": "Generate Local Folder Data",
"action": "getRemoteList",
"action": "delFileList",
"paramList": [
"ftpdata/syncfolder/",
".txt"
"File_000.txt"
]
},
//{
+33 -2
View File
@@ -102,7 +102,7 @@ namespace EgwProxy.Ftp
}
/// <summary>
/// Eliminazionedirectory remota
/// Eliminazione file remoto
/// </summary>
/// <param name="remoteFile">Nome file remoto da eliminare</param>
public bool DeleteFile(string remoteFile)
@@ -124,6 +124,37 @@ namespace EgwProxy.Ftp
return answ;
}
/// <summary>
/// Eliminazione lista di files remoti
/// </summary>
/// <param name="remFileList">Lista file remoti da eliminare</param>
public int DeleteFileList(List<string> remFileList)
{
int numDone = 0;
tryConnect();
try
{
foreach (var remoteFile in remFileList)
{
// Elimina folder
client.DeleteFile(remoteFile);
// verifico se sia presente...
bool fExist = client.FileExists(remoteFile);
if (!fExist)
{
numDone++;
}
}
}
catch (Exception exc)
{
Log.Error($"Eccezione in DeleteFileList{Environment.NewLine}{exc}");
}
// chiudo!
client.Disconnect();
return numDone;
}
/// <summary>
/// Verifica esistenza directory su server FTP remoto
/// </summary>
@@ -455,7 +486,7 @@ namespace EgwProxy.Ftp
#region Private Properties
private FtpClient client { get; set; }
private FtpClient client { get; set; } = new FtpClient();
#endregion Private Properties
+2
View File
@@ -96,6 +96,7 @@ namespace IOB_UT_NEXT
CreateDir,
DelDir,
DelFile,
//DelFileList,
DownloadDir,
DownloadFile,
GenRandomDir,
@@ -103,6 +104,7 @@ namespace IOB_UT_NEXT
MirrorDirL2R,
MirrorDirR2L,
PingServer,
RemoveFileByName,
UploadDir,
UploadFile
}
+2 -2
View File
@@ -50,8 +50,8 @@ DISABLE_SEND_WDST=TRUE
; gestioni PING
MAX_TRY_PING=3
VETO_QUEUE_IN=5
VETO_PING_SEC=5
VETO_QUEUE_IN=2
VETO_PING_SEC=2
MAX_ELAPSED_TIME_SEC=60
;VETO_SEND_SNAPSHOT=3
+1 -1
View File
@@ -111,7 +111,7 @@
<HintPath>..\packages\EasyModbusTCP.5.6.0\lib\net40\EasyModbus.dll</HintPath>
</Reference>
<Reference Include="EgwProxy.Ftp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EgwProxy.Ftp.3.6.2410.809\lib\EgwProxy.Ftp.dll</HintPath>
<HintPath>..\packages\EgwProxy.Ftp.3.6.2410.816\lib\EgwProxy.Ftp.dll</HintPath>
</Reference>
<Reference Include="EgwProxy.Gomba, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EgwProxy.Gomba.3.6.2309.1416\lib\EgwProxy.Gomba.dll</HintPath>
+117 -19
View File
@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
@@ -60,7 +61,7 @@ namespace IOB_WIN_NEXT.IobNet
if (!string.IsNullOrEmpty(ftpConfFile))
{
loadFtpConfFile(ftpConfFile);
// mi calcolo ed imposto la ftpClient + Remote BaseDir...
// mi calcolo ed imposto la ftpClientMan + Remote BaseDir...
string actKey = "RemoteDir";
if (currFtpTaskList != null && currFtpTaskList.ListTask.Count > 0)
{
@@ -79,10 +80,10 @@ namespace IOB_WIN_NEXT.IobNet
}
}
}
if (!ftpClient.IsConfigured)
if (!ftpClientMan.IsConfigured)
{
// setup ftpClient!
ftpClient = new Manager(fTask.ServerAddr, fTask.ConnUser, fTask.ConnPasswd, fTask.RawCert, fTask.SkipCert);
// setup ftpClientMan!
ftpClientMan = new Manager(fTask.ServerAddr, fTask.ConnUser, fTask.ConnPasswd, fTask.RawCert, fTask.SkipCert);
}
}
}
@@ -172,6 +173,14 @@ namespace IOB_WIN_NEXT.IobNet
case taskType.startSetup:
case taskType.stopSetup:
//verifico odl x prima cosa...
pzCntReload(true);
// faccio pulizia preliminare della commessa corrente...
bool cleanDone = RemPlaceholder(RemoteBaseDir, fNameOdl);
if (cleanDone)
{
lgInfo($"Cleaned {fNameOdl} during startSetup | remDir: {RemoteBaseDir}");
}
// verifico di avere già un ODL corrente...
if (currIdxODL == 0)
{
@@ -181,16 +190,15 @@ namespace IOB_WIN_NEXT.IobNet
{
string odlFolder = $"ODL{currIdxODL:00000000}";
// scrivo file ultima richiesta setup
string fName = $"{item.Key}.txt";
string basePath = System.Windows.Forms.Application.StartupPath;
string tempDir = Path.Combine(basePath, "temp");
string locFile = Path.Combine(tempDir, fName);
string locFile = Path.Combine(tempDir, fNameOdl);
// salva col nome FISSO di ODL_CORRENTE
string remFile = $"{RemoteBaseDir}/{odlFolder}/{fNameOdl}";
//string remFile = $"{RemoteBaseDir}/{odlFolder}/{fName}";
// creo file locale
File.WriteAllText(locFile, item.Value);
// creo file temp x invio
// invio file x ODL attivo
currActParam.Add("LocalFile", locFile);
currActParam.Add("RemoteFile", remFile);
currAct = new ActionConfig()
@@ -211,11 +219,19 @@ namespace IOB_WIN_NEXT.IobNet
lgError($"Error in startSetup | fileUpload | locFile: {locFile} | remFile: {remFile}");
}
}
break;
case taskType.endProd:
// cerco tutti i file dell'odl arttivo e li elimino
bool okRemove = RemPlaceholder(RemoteBaseDir, fNameOdl);
if (okRemove)
{
taskVal = $"Cleaned CurrOdlFile: {item.Key} --> {item.Value} | remDir: {RemoteBaseDir} | fName: {fNameOdl}";
}
else
{
lgError($"Error in CurrOdlFile | remDir: {RemoteBaseDir} | fName: {fNameOdl}");
}
break;
default:
@@ -232,6 +248,36 @@ namespace IOB_WIN_NEXT.IobNet
return taskDone;
}
/// <summary>
/// Rimuove eventuali file placeholder di ODL corrente preesistenti
/// </summary>
/// <param name="remDir"></param>
/// <param name="fNameOdl"></param>
private bool RemPlaceholder(string remDir, string fNameOdl)
{
bool fatto = false;
try
{
Dictionary<string, string> currActParam = new Dictionary<string, string>();
currActParam.Add("RemoteDir", remDir);
currActParam.Add("FileName2Del", fNameOdl);
ActionConfig currAct = new ActionConfig()
{
Id = "01",
Description = "Clean Curr ODL Files",
Action = ActType.RemoveFileByName,
ParamList = currActParam
};
// eseguo step...
fatto = doStep(currAct);
}
catch (Exception exc)
{
lgError($"Eccezione in RemPlaceholder{Environment.NewLine}{exc}");
}
return fatto;
}
/// <summary>
/// Effettua processing CUSTOM x FTP:
/// - prende ogni conf specifica
@@ -253,12 +299,12 @@ namespace IOB_WIN_NEXT.IobNet
// imposto nuovo veto...
ActionResetVeto(srvFtp);
// ora setup server FTP x item...
ftpClient = new Manager(srvFtp.ServerAddr, srvFtp.ConnUser, srvFtp.ConnPasswd, srvFtp.RawCert, srvFtp.SkipCert);
ftpClientMan = new Manager(srvFtp.ServerAddr, srvFtp.ConnUser, srvFtp.ConnPasswd, srvFtp.RawCert, srvFtp.SkipCert);
// test server ok...
if (ftpClient.ServerOk())
if (ftpClientMan.ServerOk())
{
int stepDone = 0;
string srvType = ftpClient.ServerType();
string srvType = ftpClientMan.ServerType();
lgTrace($"Connesso a server {srvType} | {srvFtp.ServerAddr} | inizio processing {srvFtp.StepsList.Count} steps");
// ciclo tra i vari steps!
foreach (var step in srvFtp.StepsList)
@@ -450,7 +496,7 @@ namespace IOB_WIN_NEXT.IobNet
/// <summary>
/// CLient connessioni FTP
/// </summary>
private Manager ftpClient { get; set; } = new Manager("", "", "", "", false);
private Manager ftpClientMan { get; set; } = new Manager("", "", "", "", false);
/// <summary>
/// Directpry remota di abse
@@ -538,7 +584,7 @@ namespace IOB_WIN_NEXT.IobNet
sw.Restart();
remoteVal = step.ParamList["RemoteDir"] ?? "";
//verifico dir remota
fatto = ftpClient.DirExists(remoteVal);
fatto = ftpClientMan.DirExists(remoteVal);
}
else
{
@@ -560,14 +606,14 @@ namespace IOB_WIN_NEXT.IobNet
sw.Restart();
remoteVal = step.ParamList["RemoteDir"] ?? "";
//verifico dir remota
bool dirExist = ftpClient.DirExists(remoteVal);
bool dirExist = ftpClientMan.DirExists(remoteVal);
if (dirExist)
{
lgTrace("Error: Folder already exists!");
}
else
{
fatto = ftpClient.CreateDir(remoteVal);
fatto = ftpClientMan.CreateDir(remoteVal);
}
}
else
@@ -618,12 +664,12 @@ namespace IOB_WIN_NEXT.IobNet
Directory.CreateDirectory(localVal);
}
//verifico dir remota
var preTest = ftpClient.DirExists(remoteVal);
var preTest = ftpClientMan.DirExists(remoteVal);
if (preTest)
{
// chiamo metodo MIRROR x calcolare esattamente se ci siano stati
// download di sync...
var mirResult = ftpClient.MirrorRemoteDir(localVal, remoteVal, FluentFTP.FtpFolderSyncMode.Mirror);
var mirResult = ftpClientMan.MirrorRemoteDir(localVal, remoteVal, FluentFTP.FtpFolderSyncMode.Mirror);
// ciclo cercando eventuali info da emttere in DynData...
foreach (var result in mirResult)
{
@@ -668,6 +714,49 @@ namespace IOB_WIN_NEXT.IobNet
case ActType.PingServer:
break;
case ActType.RemoveFileByName:
string fName2Del = "";
int numRem = 0;
if (step.ParamList != null && step.ParamList.Count > 1)
{
sw.Restart();
remoteVal = step.ParamList["RemoteDir"] ?? "";
fName2Del = step.ParamList["FileName2Del"] ?? "";
//verifico dir remota
fatto = ftpClientMan.DirExists(remoteVal);
if (fatto)
{
// recupero elenco di TUTTI i file presenti
List<FluentFTP.FtpListItem> resList = ftpClientMan.GetRemoteList(remoteVal, true);
List<FluentFTP.FtpListItem> list2del = new List<FluentFTP.FtpListItem>();
// cerco tutti i file che indicano ODL attivo e li elimino
foreach (var flItem in resList)
{
if (flItem.Type == FluentFTP.FtpObjectType.File && flItem.Name.EndsWith(fName2Del))
{
list2del.Add(flItem);
}
}
// elimino quelli trovati
if (list2del.Count > 0)
{
var fList = list2del.Select(x => x.FullName).ToList();
numRem = ftpClientMan.DeleteFileList(fList);
}
}
}
else
{
lgError("Error: missing parameters!");
}
sw.Stop();
if (fatto)
{
lgInfo($"RemoveFileByName | path: {remoteVal} | name: {fName2Del} | # del: {numRem} | {sw.ElapsedMilliseconds:N1} ms");
}
break;
case ActType.UploadDir:
break;
@@ -677,7 +766,16 @@ namespace IOB_WIN_NEXT.IobNet
sw.Restart();
localVal = step.ParamList["LocalFile"] ?? "";
remoteVal = step.ParamList["RemoteFile"] ?? "";
fatto = ftpClient.SendFile(localVal, remoteVal);
//verifico dir remota
string remoteDir = remoteVal.Substring(0, remoteVal.LastIndexOf("/"));
bool dirExist = ftpClientMan.DirExists(remoteDir);
if (!dirExist)
{
fatto = ftpClientMan.CreateDir(remoteDir);
}
fatto = ftpClientMan.SendFile(localVal, remoteVal);
if (!fatto)
{
lgError($"Error: {localVal} NOT uploaded!");
+1 -1
View File
@@ -3,7 +3,7 @@
<package id="Autoupdater.NET.Official" version="1.8.4" targetFramework="net462" />
<package id="Costura.Fody" version="5.7.0" targetFramework="net462" developmentDependency="true" />
<package id="EasyModbusTCP" version="5.6.0" targetFramework="net462" />
<package id="EgwProxy.Ftp" version="3.6.2410.809" targetFramework="net462" />
<package id="EgwProxy.Ftp" version="3.6.2410.816" targetFramework="net462" />
<package id="EgwProxy.Gomba" version="3.6.2309.1416" targetFramework="net462" />
<package id="EgwProxy.Icoel" version="3.6.2309.708" targetFramework="net462" />
<package id="EgwProxy.MultiCncLib" version="3.6.2207.1211" targetFramework="net462" />