155 lines
6.4 KiB
C#
155 lines
6.4 KiB
C#
using Core;
|
|
using LiMan.Transfer;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using RestSharp;
|
|
using RestSharp.Serializers.NewtonsoftJson;
|
|
using System;
|
|
|
|
namespace MyApp // Note: actual namespace depends on the project name.
|
|
{
|
|
internal class Program
|
|
{
|
|
protected static string dataFolder = "";
|
|
protected static string archFolder = "";
|
|
protected static string reqName = "request.json";
|
|
protected static string apiUrl = "https://liman.egalware.com/ELM.Api/";
|
|
|
|
|
|
/// <summary>
|
|
/// Classe logger
|
|
/// </summary>
|
|
public static Logger lg = LogManager.GetCurrentClassLogger();
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
string myLine = "--------------------------------------";
|
|
logInfo(myLine);
|
|
logInfo("LiMan data transfer");
|
|
logInfo(myLine);
|
|
|
|
//verifico di avere parametro x directory con contenuto...
|
|
if (args == null || args.Count() < 2)
|
|
{
|
|
logError("Warning: Missing args !!!");
|
|
logError("");
|
|
logError("Syntax: LiMan.Transfer data_folder archive_folder");
|
|
logError("data_folder: path to container for request.json file + *.zip file(s) to upload");
|
|
logError("archive_folder: where to put trasferred data");
|
|
logError("");
|
|
}
|
|
else
|
|
{
|
|
// verifico primo parametro
|
|
dataFolder = args[0];
|
|
archFolder = args[1];
|
|
if (!Directory.Exists(dataFolder))
|
|
{
|
|
logError("Error! data directory not found. Exiting");
|
|
}
|
|
else
|
|
{
|
|
// quella archivio se non ci fosse la creo
|
|
if (!Directory.Exists(archFolder))
|
|
{
|
|
Directory.CreateDirectory(archFolder);
|
|
}
|
|
|
|
// cerco il file di conf x invio
|
|
string fileName = Path.Combine(dataFolder, reqName);
|
|
if (!File.Exists(fileName))
|
|
{
|
|
logError("Missing conf file!");
|
|
}
|
|
else
|
|
{
|
|
// deserializzo conf
|
|
logInfo($"Found file {fileName}");
|
|
|
|
|
|
try
|
|
{
|
|
// client chiamate rest
|
|
var client = new RestClient(apiUrl);
|
|
client.UseNewtonsoftJson();
|
|
|
|
SupportRequest newSuppReq = new SupportRequest();
|
|
string rawData = "";
|
|
if (File.Exists(fileName))
|
|
{
|
|
rawData = File.ReadAllText(fileName);
|
|
}
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
// fare: composizione richiesta da parametri chiave
|
|
newSuppReq = JsonConvert.DeserializeObject<SupportRequest>(rawData);
|
|
}
|
|
else
|
|
{
|
|
string hostName = utils.machineName;
|
|
string listIP = string.Join(", ", utils.machineIp);
|
|
// genero il ticket
|
|
newSuppReq = new SupportRequest()
|
|
{
|
|
CodApp = "MAPO-IOB-WIN-NEXT",
|
|
CodImp = "",
|
|
CodInst = "SteamWare",
|
|
ContactEmail = "info@steamware.net",
|
|
ContactName = "Default Config",
|
|
ContactPhone = "035-460560",
|
|
MasterKey = "a3BRQz/1B34uvvcDoE/D38ssH/c/KSsjpn39wZsxOVsck9rGnBkF3xfUnj3edYIl",
|
|
ReqBody = $"File Upload - MISSING license file | machine: {utils.machineName} | IP: {listIP}",
|
|
Tipo = TipologiaTicket.FileUpload,
|
|
idxSubLic = 0
|
|
};
|
|
}
|
|
var ticketReq = new RestRequest("/api/ticket/sendReq", DataFormat.Json).AddJsonBody(newSuppReq);
|
|
|
|
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
var ticketResp = await client.PostAsync<TicketDTO>(ticketReq);
|
|
// preparo richiesta x upload file
|
|
var fileUploadReq = new RestRequest("/api/filesave/single");
|
|
fileUploadReq.AddParameter("ticketId", ticketResp.idxTicket);
|
|
// cerco OGNI file zip nella folder indicata...
|
|
var fileList = Directory.GetFiles(dataFolder, "*.zip");
|
|
foreach (var file in fileList)
|
|
{
|
|
fileUploadReq.AddFile("file", file);
|
|
}
|
|
|
|
// ... infine INVIA file zip che li contiene...
|
|
//var fileUploadResp = client.Post(fileUploadReq);
|
|
var fileUploadResp = await client.PostAsync<UploadResult>(fileUploadReq);
|
|
|
|
// sposto folder in area archivio...
|
|
string destFolder = Path.Combine(archFolder, $"{DateTime.Now:yyyyMMdd_HHmmss}");
|
|
Directory.Move(dataFolder, destFolder);
|
|
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logError($"Eccezione in fase gestione REST services{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected static void logInfo(string message)
|
|
{
|
|
lg.Info(message);
|
|
Console.WriteLine(message);
|
|
}
|
|
protected static void logError(string message)
|
|
{
|
|
lg.Error(message);
|
|
Console.WriteLine($"!!! {message}");
|
|
}
|
|
}
|
|
} |