fix controlllo path pdf x UNC + timeout ping
This commit is contained in:
+37
-1
@@ -7,6 +7,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace AppData
|
||||
{
|
||||
@@ -804,7 +806,25 @@ namespace AppData
|
||||
{
|
||||
try
|
||||
{
|
||||
answ = File.Exists(pdfPath);
|
||||
string parentDir = Path.GetDirectoryName(pdfPath);
|
||||
bool shareOk = true;
|
||||
bool dirOk = true;
|
||||
if (IsUnc(parentDir))
|
||||
{
|
||||
string pathRoot = Path.GetPathRoot(parentDir);
|
||||
Uri newUri = new Uri(pathRoot);
|
||||
// tento PING
|
||||
PingReply pingResult = NKC.testPingDevice(newUri.Host);
|
||||
shareOk = (pingResult.Status == IPStatus.Success);
|
||||
}
|
||||
if (shareOk)
|
||||
{
|
||||
dirOk = Directory.Exists(parentDir);
|
||||
if (dirOk)
|
||||
{
|
||||
answ = File.Exists(pdfPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
@@ -1242,6 +1262,22 @@ namespace AppData
|
||||
return answ;
|
||||
}
|
||||
|
||||
public static bool IsUnc(string path)
|
||||
{
|
||||
string root = Path.GetPathRoot(path);
|
||||
|
||||
// Check if root starts with "\\", clearly an UNC
|
||||
if (root.StartsWith(@"\\"))
|
||||
return true;
|
||||
|
||||
// Check if the drive is a network drive
|
||||
DriveInfo drive = new DriveInfo(root);
|
||||
if (drive.DriveType == DriveType.Network)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// restitusice ultima chiamata REST registrata su REDIS
|
||||
/// </summary>
|
||||
|
||||
+215
-181
@@ -8,8 +8,212 @@ namespace NKC_SDK
|
||||
{
|
||||
public class NKC
|
||||
{
|
||||
#region utils comunicazione HTTP
|
||||
#region Protected Fields
|
||||
|
||||
/// <summary>
|
||||
/// file locale per persistenza BUNK
|
||||
/// </summary>
|
||||
protected string persistFileName = "data/persistFile.json";
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Classe per effettuare comunicazioni con NKC
|
||||
/// </summary>
|
||||
/// <param name="baseIp">IP di base x ping</param>
|
||||
/// <param name="baseUrl">URL di abse x chiamate REST</param>
|
||||
/// <param name="codPost">Codice posstazione/macchina x cui si fa chiamata</param>
|
||||
public NKC(string baseIp, string baseUrl, string codPost)
|
||||
{
|
||||
_baseIp = baseIp;
|
||||
_baseUrl = baseUrl;
|
||||
_codPost = codPost;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
/// <summary>
|
||||
/// DnsName/IP di base x chaimate
|
||||
/// </summary>
|
||||
protected string _baseIp { get; set; } = "seriate.steamware.net";
|
||||
|
||||
/// <summary>
|
||||
/// URL di base per la comunicazione
|
||||
///
|
||||
/// PROD: http://seriate.steamware.net:8083/NKC/
|
||||
/// DEV: https://localhost:44388/
|
||||
/// </summary>
|
||||
protected string _baseUrl { get; set; } = @"http://seriate.steamware.net:8083/NKC/";
|
||||
|
||||
/// <summary>
|
||||
/// COD macchina x cui si effettua chiamata
|
||||
/// </summary>
|
||||
protected string _codPost { get; set; } = "";
|
||||
|
||||
protected string urlAlive
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Alive";
|
||||
}
|
||||
}
|
||||
|
||||
protected string urlAliveClock
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Alive/1";
|
||||
}
|
||||
}
|
||||
|
||||
protected string urlCurrBunk
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk";
|
||||
}
|
||||
}
|
||||
|
||||
protected string urlCurrSheet4Mac
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Sheet/{_codPost}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// URL x salvataggio dati SHEET
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected string urlPutSheetList
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Sheet/{_codPost}";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto che contiene l'oggetto SHEET WorkList corrente salvato LOCALMENTE
|
||||
/// </summary>
|
||||
public SheetWorkList persistedSheetList
|
||||
{
|
||||
get
|
||||
{
|
||||
SheetWorkList answ = new SheetWorkList();
|
||||
try
|
||||
{
|
||||
string rawdata = File.ReadAllText(persistFileName);
|
||||
answ = JsonConvert.DeserializeObject<SheetWorkList>(rawdata);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Instance.Error($"Eccezione durante recupero locale della SheetList{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
// serializzo oggetto
|
||||
string rawdata = JsonConvert.SerializeObject(value);
|
||||
// salvo in locale
|
||||
File.WriteAllText(persistFileName, rawdata);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Instance.Error($"Eccezione durante salvataggio locale della SheetList{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua test alive all'indirizzo del server
|
||||
/// </summary>
|
||||
public bool testAlive
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = false;
|
||||
string returnData = callUrl(urlAlive);
|
||||
returnData = JsonConvert.DeserializeObject<string>(returnData);
|
||||
answ = returnData == "OK";
|
||||
// rendo!
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua test ping all'indirizzo del server
|
||||
/// </summary>
|
||||
public DateTime testClock
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime oggi = DateTime.Today;
|
||||
DateTime answ = oggi.AddYears(-oggi.Year + 1900).AddMonths(-oggi.Month).AddDays(-oggi.Day + 1);
|
||||
// recupero!
|
||||
string returnData = callUrl(urlAliveClock);
|
||||
try
|
||||
{
|
||||
DateTime.TryParse(JsonConvert.DeserializeObject<string>(returnData), out answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Instance.Error($"Eccezione durante testClock, ricevuto {returnData}{Environment.NewLine}{exc}");
|
||||
}
|
||||
// rendo!
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua test ping all'indirizzo del server
|
||||
/// </summary>
|
||||
public PingReply testPing
|
||||
{
|
||||
get
|
||||
{
|
||||
Ping myPing = new Ping();
|
||||
// timeout a 1 sec!
|
||||
PingReply answ = myPing.Send(_baseIp, 1000);
|
||||
// rendo!
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected string urlGetBunk(int currBunkId)
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk/{currBunkId}?showNext=false";
|
||||
}
|
||||
|
||||
protected string urlNextBunk(int currBunkId)
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk/{currBunkId}?showNext=true";
|
||||
}
|
||||
|
||||
protected string urlPutBunk(int currBunkId)
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk/{currBunkId}";
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Effettua chiamata URL e restituisce risultato
|
||||
@@ -34,6 +238,7 @@ namespace NKC_SDK
|
||||
// restituisco valore!
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua chiamata URL e restituisce risultato
|
||||
/// </summary>
|
||||
@@ -86,151 +291,14 @@ namespace NKC_SDK
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region URL di base
|
||||
|
||||
protected string urlAlive
|
||||
public static PingReply testPingDevice(string address)
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Alive";
|
||||
}
|
||||
Ping myPing = new Ping();
|
||||
// timeout a 1 sec!
|
||||
PingReply answ = myPing.Send(address, 2000);
|
||||
// rendo!
|
||||
return answ;
|
||||
}
|
||||
protected string urlAliveClock
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Alive/1";
|
||||
}
|
||||
}
|
||||
protected string urlCurrBunk
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk";
|
||||
}
|
||||
}
|
||||
protected string urlCurrSheet4Mac
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Sheet/{_codPost}";
|
||||
}
|
||||
}
|
||||
protected string urlGetBunk(int currBunkId)
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk/{currBunkId}?showNext=false";
|
||||
}
|
||||
protected string urlNextBunk(int currBunkId)
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk/{currBunkId}?showNext=true";
|
||||
}
|
||||
protected string urlPutBunk(int currBunkId)
|
||||
{
|
||||
return $"{_baseUrl}api/Bunk/{currBunkId}";
|
||||
}
|
||||
/// <summary>
|
||||
/// URL x salvataggio dati SHEET
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected string urlPutSheetList
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{_baseUrl}api/Sheet/{_codPost}";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// file locale per persistenza BUNK
|
||||
/// </summary>
|
||||
protected string persistFileName = "data/persistFile.json";
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// URL di base per la comunicazione
|
||||
///
|
||||
/// PROD: http://seriate.steamware.net:8083/NKC/
|
||||
/// DEV: https://localhost:44388/
|
||||
/// </summary>
|
||||
protected string _baseUrl { get; set; } = @"http://seriate.steamware.net:8083/NKC/";
|
||||
/// <summary>
|
||||
/// DnsName/IP di base x chaimate
|
||||
/// </summary>
|
||||
protected string _baseIp { get; set; } = "seriate.steamware.net";
|
||||
/// <summary>
|
||||
/// COD macchina x cui si effettua chiamata
|
||||
/// </summary>
|
||||
protected string _codPost { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Classe per effettuare comunicazioni con NKC
|
||||
/// </summary>
|
||||
/// <param name="baseIp">IP di base x ping</param>
|
||||
/// <param name="baseUrl">URL di abse x chiamate REST</param>
|
||||
/// <param name="codPost">Codice posstazione/macchina x cui si fa chiamata</param>
|
||||
public NKC(string baseIp, string baseUrl, string codPost)
|
||||
{
|
||||
_baseIp = baseIp;
|
||||
_baseUrl = baseUrl;
|
||||
_codPost = codPost;
|
||||
}
|
||||
/// <summary>
|
||||
/// Effettua test ping all'indirizzo del server
|
||||
/// </summary>
|
||||
public PingReply testPing
|
||||
{
|
||||
get
|
||||
{
|
||||
Ping myPing = new Ping();
|
||||
// timeout a 1 sec!
|
||||
PingReply answ = myPing.Send(_baseIp, 1000);
|
||||
// rendo!
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Effettua test alive all'indirizzo del server
|
||||
/// </summary>
|
||||
public bool testAlive
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = false;
|
||||
string returnData = callUrl(urlAlive);
|
||||
returnData = JsonConvert.DeserializeObject<string>(returnData);
|
||||
answ = returnData == "OK";
|
||||
// rendo!
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Effettua test ping all'indirizzo del server
|
||||
/// </summary>
|
||||
public DateTime testClock
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime oggi = DateTime.Today;
|
||||
DateTime answ = oggi.AddYears(-oggi.Year + 1900).AddMonths(-oggi.Month).AddDays(-oggi.Day + 1);
|
||||
// recupero!
|
||||
string returnData = callUrl(urlAliveClock);
|
||||
try
|
||||
{
|
||||
DateTime.TryParse(JsonConvert.DeserializeObject<string>(returnData), out answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Instance.Error($"Eccezione durante testClock, ricevuto {returnData}{Environment.NewLine}{exc}");
|
||||
}
|
||||
// rendo!
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
#region metodi per SheetWorklist
|
||||
|
||||
/// <summary>
|
||||
/// Recupera elenco dei fogli ATTIVI
|
||||
@@ -254,6 +322,7 @@ namespace NKC_SDK
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua salvataggio dell'elenco dei fogli (1..n) su NKC
|
||||
/// </summary>
|
||||
@@ -276,42 +345,7 @@ namespace NKC_SDK
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Oggetto che contiene l'oggetto SHEET WorkList corrente salvato LOCALMENTE
|
||||
/// </summary>
|
||||
public SheetWorkList persistedSheetList
|
||||
{
|
||||
get
|
||||
{
|
||||
SheetWorkList answ = new SheetWorkList();
|
||||
try
|
||||
{
|
||||
string rawdata = File.ReadAllText(persistFileName);
|
||||
answ = JsonConvert.DeserializeObject<SheetWorkList>(rawdata);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Instance.Error($"Eccezione durante recupero locale della SheetList{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
// serializzo oggetto
|
||||
string rawdata = JsonConvert.SerializeObject(value);
|
||||
// salvo in locale
|
||||
File.WriteAllText(persistFileName, rawdata);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Instance.Error($"Eccezione durante salvataggio locale della SheetList{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,15 +167,20 @@ namespace NKC_WF.Controllers
|
||||
case procStatus.completed:
|
||||
if (isValidation || isTesting)
|
||||
{
|
||||
// verifico PDF, se NON OK --> errore
|
||||
bool pdfOk = true;
|
||||
string pdfPath = "";
|
||||
foreach (var item in rispStima.PartList)
|
||||
// se richiesto CheckPDF
|
||||
if (memLayer.ML.CRB("checkPdfPathTV"))
|
||||
{
|
||||
pdfOk = pdfOk && ComLib.checkPdfExistAccessible(item, out pdfPath);
|
||||
if (!pdfOk)
|
||||
// verifico PDF, se NON OK --> errore
|
||||
string pdfPath = "";
|
||||
foreach (var item in rispStima.PartList)
|
||||
{
|
||||
DLMan.taEL.insertQuery(DateTime.Now, "Check PDF path", $"{rispStima.BatchID}", $"{rispStima.BatchID}.{item.PartExtCode}", $"Error: PDF file not found: {pdfPath}");
|
||||
pdfOk = pdfOk && ComLib.checkPdfExistAccessible(item, out pdfPath);
|
||||
if (!pdfOk)
|
||||
{
|
||||
// codice è B.xxx dove xxx = BatchID
|
||||
DLMan.taEL.insertQuery(DateTime.Now, "Check PDF path", $"B.{rispStima.BatchID}", $"{rispStima.BatchID}.{item.PartExtCode}", $"Error: PDF file not found: {pdfPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user