Files
Mapo-IOB-WIN/IOB-WIN-NEXT/Iob/GenericNext.cs
T
Samuele Locatelli 8bb0f158b5 SPLIT PROGETTO!!!
- proj di base con le 2 form da ereditare
- progetto globale che contiene TUTTI gli adapter (pronto a venire spezzettato
- gettate le basi x "portare fuori" i vari componenti oppure fare compilazione condizonale
2024-12-20 10:16:32 +01:00

119 lines
4.5 KiB
C#

using EgwProxy.Ftp;
using EgwProxy.MultiCncLib.App.Native;
using IOB_UT_NEXT;
using IOB_WIN_FORM;
using MapoSDK;
using MathNet.Numerics.Statistics;
using MTConnect;
using MTConnect.Clients;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
using static IOB_UT_NEXT.BaseAlarmConf;
using static IOB_UT_NEXT.CustomObj;
using static IOB_UT_NEXT.DataModel.Fimat;
using static MapoSDK.WharehouseData;
namespace IOB_WIN_NEXT.Iob
{
public class GenericNext : IOB_WIN_FORM.Iob.Generic
{
public GenericNext(AdapterFormNext caller, IobConfiguration IOBConf): base((IOB_WIN_FORM.AdapterForm)caller, IOBConf)
{
}
/// <summary>
/// Effettua upload verso server FTP della macchina dei files nella folder indicata
/// </summary>
/// <param name="folderDir"></param>
/// <returns></returns>
protected override bool iobSendFTP(string folderDir)
{
bool answ = false;
//leggo CONF
string ftpServ = getOptPar("FTP_SERVER");
string ftpUser = getOptPar("FTP_USER");
string ftpPass = getOptPar("FTP_PWD");
string ftpCert = getOptPar("FTP_CERT");
string doSkip = getOptPar("FTP_SKIP");
string remDir = getOptPar("FTP_REM_DIR");
string locDir = getOptPar("FTP_LOC_DIR");
// procedo SE TROVO conf...
if (string.IsNullOrEmpty($"{ftpServ}{ftpUser}{ftpPass}"))
{
lgError($"Impossibile eseguire iobSendFTP x mancanza parametri | ftpServ: {ftpServ} | ftpUser: {ftpUser} | ftpPass: {ftpPass}");
}
else
{
bool ftpSkip = false;
bool.TryParse(doSkip, out ftpSkip);
var ftpClient = new Manager(ftpServ, ftpUser, ftpPass, ftpCert, ftpSkip);
var testServer = ftpClient.ServerOk();
if (testServer)
{
lgInfo($"FTP: server found at {ftpServ}");
var srvType = ftpClient.ServerType();
lgInfo($"FTP Server type: {srvType}");
var preTest = ftpClient.DirExists(remDir);
if (!preTest)
{
var dirCreate = ftpClient.CreateDir(remDir);
lgInfo($"FTP: created remote dir {remDir}");
}
// test directory...
string basePath = Application.StartupPath;
string localPath = Path.Combine(basePath, locDir);
lgInfo($"basePath: {basePath} | localPath: {localPath}");
var fileList = Directory.GetFiles(localPath, "*.csv");
int numfile = 0;
foreach (var file in fileList)
{
string fName = file.Split('\\').Last();
string remName = $"{remDir}\\{fName}";
ftpClient.SendFile(file, remName);
numfile++;
}
var dirUploaded = (numfile == fileList.Count());
if (dirUploaded)
{
lgInfo($"FTP: uploaded dir content {locDir} --> {remDir}");
}
// se ok --> sposto invio
DateTime adesso = DateTime.Now;
string archBasePath = Path.Combine(basePath, "DATA", "HIST", $"{adesso:yyyy}");
baseUtils.checkDir(archBasePath);
string archPath = Path.Combine(archBasePath, $"{adesso:MMddHHmmss}");
baseUtils.checkDir(archPath);
lgInfo($"Richiesta Dir Move | {localPath} | {archPath}");
foreach (var item in fileList)
{
string fName = item.Split('\\').Last();
string destName = $"{archPath}\\{fName}";
File.Move(item, destName);
}
//Directory.Move(localPath, archBasePath);
lgInfo($"FTP: Archived dir content {localPath} --> {archPath}");
}
}
return answ;
}
}
}