477 lines
16 KiB
C#
477 lines
16 KiB
C#
using SteamWare.Scheduler;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using NLog;
|
|
using System.Xml.Linq;
|
|
|
|
namespace TestBench
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Oggetto REDIS
|
|
/// </summary>
|
|
private SteamWare.IO.Redis myRedis;
|
|
|
|
private StackExchange.Redis.ISubscriber subscriber;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
myInitComponent();
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Private Delegates
|
|
|
|
private delegate void SetTextCallback(string text);
|
|
|
|
#endregion Private Delegates
|
|
|
|
#region Private Methods
|
|
|
|
private void actionTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
// processo le varie azioni...
|
|
doLogTest();
|
|
}
|
|
|
|
private void BtnCopyAll_Click(object sender, EventArgs e)
|
|
{
|
|
// effettuo copia con steamware libs...
|
|
string sourceDir = txtSourceDir.Text.Trim();
|
|
string destDir = txtDestDir.Text.Trim();
|
|
if (sourceDir != "" && destDir != "")
|
|
{
|
|
lblOutMessage.Text = "inizio copia...";
|
|
lblOutMessage.Refresh();
|
|
fileMover.DirectoryCopy(sourceDir, destDir, chkRecursive.Checked);
|
|
lblOutMessage.Text = "Copia completata!";
|
|
}
|
|
}
|
|
|
|
private void btnDownload_Click(object sender, EventArgs e)
|
|
{
|
|
var currUpdMan = new UpdateMan(txtUser.Text.Trim(), txtPass.Text.Trim());
|
|
currUpdMan.downloadLatest(txtRemoteUrl.Text.Trim(), "c:\\Temp", "TEST-FILE");
|
|
}
|
|
|
|
private void btnReadUpdMan_Click(object sender, EventArgs e)
|
|
{
|
|
// recupero i dati dall'URL
|
|
var currUpdMan = new UpdateMan(txtUser.Text.Trim(), txtPass.Text.Trim());
|
|
// popolo la label
|
|
var updInfo = currUpdMan.getUpdateInfo(txtRemoteUrl.Text.Trim());
|
|
lblOutUpdMan.Text = $"Vers: {updInfo.CurrentVersion} | URL: {updInfo.DownloadURL}";
|
|
}
|
|
|
|
private void btnResetAppConf_Click(object sender, EventArgs e)
|
|
{
|
|
memLayer.ML.resetAppConf();
|
|
}
|
|
|
|
private void btnResetCdv_Click(object sender, EventArgs e)
|
|
{
|
|
memLayer.ML.resetAppConf();
|
|
}
|
|
|
|
private void btnSend_Click(object sender, EventArgs e)
|
|
{
|
|
// scrivo su coda
|
|
string myKey = "testQueue";
|
|
myRedis.ListPush(myKey, $"{DateTime.Now} | {txtQueueMessage.Text.Trim()}");
|
|
txtQueueMessage.Text = "";
|
|
}
|
|
|
|
private void btnShowCdv_Click(object sender, EventArgs e)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("----- REDIS CDV data -----");
|
|
foreach (var item in memLayer.ML.AppConf)
|
|
{
|
|
sb.AppendLine($"{item.Key}: {item.Value}");
|
|
}
|
|
lblRedCDV.Text = sb.ToString();
|
|
}
|
|
|
|
private void btnStartSched_Click(object sender, EventArgs e)
|
|
{
|
|
// avvia uno scheduler che apre una messagebox secondo programmazione impostata...
|
|
|
|
// For Interval in Minutes
|
|
// This Scheduler will start at 22:00 and call after every 30 Minutes
|
|
// IntervalInSeconds(start_hour, start_minute, minutes)
|
|
|
|
// calcolo istante dal PROSSIMO minuto
|
|
DateTime avvio = DateTime.Now;
|
|
lblStartTimer.Text = $"Avvio timer: {avvio:ddd yyyy-MM-dd HH:mm:ss}";
|
|
avvio = avvio.AddMinutes(1).AddSeconds(-avvio.Second);
|
|
lblNextSched.Text = $"Scadenza timer: {avvio:ddd yyyy-MM-dd HH:mm:ss}";
|
|
|
|
clockTimer.Start();
|
|
|
|
// calcolo periodo in minuti guardando quanto selezionato
|
|
int ore = 0;
|
|
int min = 0;
|
|
int sec = 0;
|
|
int.TryParse(txtOre.Text, out ore);
|
|
int.TryParse(txtMin.Text, out min);
|
|
int.TryParse(txtSec.Text, out sec);
|
|
// calcolo
|
|
double intSecondi = ore * 60 * 60 + min * 60 + sec;
|
|
|
|
TaskSched.IntervalInSeconds(avvio.Hour, avvio.Minute, intSecondi,
|
|
() =>
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
|
|
// Initializes the variables to pass to the MessageBox.Show method.
|
|
string message = $"E' scattato il timer alle ore {DateTime.Now}.";
|
|
string caption = "Timer Elapsed";
|
|
MessageBoxButtons buttons = MessageBoxButtons.OK;
|
|
DialogResult result;
|
|
|
|
//lblNextSched.Text = $"Scadenza timer: {adesso.AddSeconds(intSecondi):ddd yyyy-MM-dd HH:mm:ss}";
|
|
// Displays the MessageBox.
|
|
result = MessageBox.Show(message, caption, buttons);
|
|
});
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
// apro selettore file...
|
|
openFileDialog1.ShowDialog();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
answ = memLayer.ML.getRedisInfoData();
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
lblRedis.Text = answ;
|
|
}
|
|
|
|
private void chkTestLogger_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (chkTestLogger.Checked)
|
|
{
|
|
LogTimer.Interval = 50;
|
|
LogTimer.Start();
|
|
}
|
|
else
|
|
{
|
|
LogTimer.Stop();
|
|
}
|
|
}
|
|
|
|
private void clockTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
lblClock.Text = $"Clock: {adesso:ddd yyyy-MM-dd HH:mm:ss}";
|
|
|
|
updateQueue();
|
|
}
|
|
|
|
private void doLogTest()
|
|
{
|
|
// solo se attivo...
|
|
if (chkTestLogger.Checked)
|
|
{
|
|
logger.lg.scriviLog($"TestLog_{DateTime.Now.Millisecond}");
|
|
// aggiorno
|
|
|
|
logger.lg.getLoggerVetoStats(out int numVeto, out int numCount);
|
|
lblTestLogger.Text = $"Status Redis | numVeto:{numVeto} | numCount: {numCount}";
|
|
}
|
|
}
|
|
|
|
private void LogTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
doLogTest();
|
|
}
|
|
|
|
private void myInitComponent()
|
|
{
|
|
// imposto folders
|
|
txtSourceDir.Text = @"C:\TMP\";
|
|
txtDestDir.Text = @"L:\TMP\";
|
|
|
|
lblHwSwData.Text = SteamWare.HwSwInfo.man(Assembly.GetExecutingAssembly()).librariesVers;
|
|
|
|
// reset conf CDV
|
|
memLayer.ML.resetAppConf();
|
|
|
|
// redis setup
|
|
myRedis = new SteamWare.IO.Redis();
|
|
subscriber = myRedis.RedPubSub;
|
|
// fix redis channel subscription
|
|
subscriber.Subscribe("TestChannel").OnMessage(channelMessage =>
|
|
{
|
|
SetText((string)channelMessage.Message);
|
|
});
|
|
}
|
|
|
|
private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
// prendo i files selezionati --> merge in pdf e indico quanti...
|
|
List<string> elencoFiles = new List<string>();
|
|
foreach (var item in openFileDialog1.FileNames)
|
|
{
|
|
elencoFiles.Add(item);
|
|
}
|
|
int numFiles = 0;
|
|
string outPath = $"{Directory.GetCurrentDirectory()}\\{txtMergedName.Text}";
|
|
try
|
|
{
|
|
numFiles = pdfUtils.mergePdfFiles(txtMergedName.Text, elencoFiles);
|
|
}
|
|
catch
|
|
{ }
|
|
lblNumMerged.Text = $"Effettuato merge di {numFiles} files!";
|
|
}
|
|
|
|
private void SetText(string text)
|
|
{
|
|
// InvokeRequired required compares the thread ID of the
|
|
// calling thread to the thread ID of the creating thread.
|
|
// If these threads are different, it returns true.
|
|
if (this.lblChannelReceive.InvokeRequired)
|
|
{
|
|
SetTextCallback d = new SetTextCallback(SetText);
|
|
this.Invoke(d, new object[] { text });
|
|
}
|
|
else
|
|
{
|
|
this.lblChannelReceive.Text = text;
|
|
}
|
|
}
|
|
|
|
private void txtChannelSend_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
// cerco Enter
|
|
if (e.KeyChar == (char)13)
|
|
{
|
|
// invio
|
|
subscriber.Publish("TestChannel", $"{DateTime.Now} | {txtChannelSend.Text}");
|
|
// reset
|
|
txtChannelSend.Text = "";
|
|
//MessageBox.Show("ENTER has been pressed!");
|
|
}
|
|
//// ESC
|
|
//else if (e.KeyChar == (char)27)
|
|
// this.Close();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorno da lettura coda...
|
|
/// </summary>
|
|
private void updateQueue()
|
|
{
|
|
// leggo da coda
|
|
string myKey = "testQueue";
|
|
if (myRedis.ListLen(myKey) > 0)
|
|
{
|
|
// aggiorno coda
|
|
lblQueueRead.Text = $"{myRedis.ListPop(myKey)}{Environment.NewLine}{lblQueueRead.Text}";
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
protected MessagePipe MPipeChannel = new MessagePipe("testCh");
|
|
|
|
protected bool pubSubEnabled = false;
|
|
|
|
private void btnStartSub_Click(object sender, EventArgs e)
|
|
{
|
|
pubSubEnabled = !pubSubEnabled;
|
|
btnStartSub.Text = pubSubEnabled ? "Stop PubSub" : "Start Sub";
|
|
btnSendMessage.Enabled = pubSubEnabled;
|
|
txtMessaggio.Enabled = pubSubEnabled;
|
|
// sistemo messaggio
|
|
if (pubSubEnabled)
|
|
{
|
|
// avvio un nuovo messaggePipe x il canale richiesto...
|
|
MPipeChannel = new MessagePipe(txtChannelName.Text, false);
|
|
MPipeChannel.EA_NewMessage += MPipeChannel_EA_NewMessage;
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("--------------------------------------");
|
|
sb.AppendLine($" Start PubSub | {DateTime.Now:HH:mm:ss}");
|
|
sb.AppendLine("--------------------------------------");
|
|
logPubSubChannel = sb.ToString();
|
|
}
|
|
else
|
|
{
|
|
logWatchString = "";
|
|
logPubSubChannel = ".... waiting ....";
|
|
MPipeChannel.EA_NewMessage -= MPipeChannel_EA_NewMessage;
|
|
}
|
|
}
|
|
|
|
private void MPipeChannel_EA_NewMessage(object sender, EventArgs e)
|
|
{
|
|
// accodo messaggio...
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine($"{currArgs.newMessage} | RECEIVED: {DateTime.Now:HH:mm:ss.ffffff}");
|
|
logPubSubChannel = sb.ToString();
|
|
}
|
|
|
|
protected string testoMessaggio
|
|
{
|
|
get => $"SEND: {DateTime.Now:HH:mm:ss.ffffff} | {txtMessaggio.Text}";
|
|
}
|
|
|
|
private void btnSendMessage_Click(object sender, EventArgs e)
|
|
{
|
|
MPipeChannel.sendMessage(testoMessaggio);
|
|
}
|
|
|
|
private void txtMessaggio_TextChanged(object sender, EventArgs e)
|
|
{
|
|
MPipeChannel.sendMessage(testoMessaggio);
|
|
}
|
|
|
|
protected int nLine2show = 30;
|
|
|
|
/// <summary>
|
|
/// Effettua un trim della stringa al numero max di linee da mostrare a video
|
|
/// </summary>
|
|
/// <param name="newString"></param>
|
|
/// <returns></returns>
|
|
public string limitLine2show(string newString)
|
|
{
|
|
if (!string.IsNullOrEmpty(newString))
|
|
{
|
|
// se num righe superiore a limite trimmo...
|
|
if (newString.Split('\n').Length > nLine2show)
|
|
{
|
|
//int idx = newString.LastIndexOf('\r');
|
|
int idx = newString.LastIndexOf(Environment.NewLine);
|
|
newString = newString.Substring(0, idx);
|
|
}
|
|
}
|
|
return newString;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stringa corrente di log...
|
|
/// </summary>
|
|
protected string logWatchString { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Logwatcher (in modalità "accodamento in testa" ultimi messaggi...)
|
|
/// </summary>
|
|
public string logPubSubChannel
|
|
{
|
|
get
|
|
{
|
|
return lblChannelLog.Text;
|
|
}
|
|
set
|
|
{
|
|
try
|
|
{
|
|
logWatchString = limitLine2show($"{value}{logWatchString}");
|
|
lblChannelLog.Text = logWatchString;
|
|
lblChannelLog.Refresh();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog($"Errore in esecuzione logWatcher{Environment.NewLine}--> {value}");
|
|
logger.lg.scriviLog($"{exc}");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnTestUserLoad_Click(object sender, EventArgs e)
|
|
{
|
|
// test lettura dati utente
|
|
try
|
|
{
|
|
var rigaUt = user_std.UtSn.rigaUtenteDaMatricola(txtMatr.Text.Trim());
|
|
if (rigaUt != null)
|
|
{
|
|
lblOutTestMatr.Text = $"Test user | CN: {rigaUt.COGNOME} {rigaUt.NOME} | email: {rigaUt.EMAIL}";
|
|
}
|
|
else
|
|
{
|
|
lblOutTestMatr.Text = "Errore!";
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Test user_std fallito{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private bool ParamPresent
|
|
{
|
|
get
|
|
{
|
|
bool serverOk = !string.IsNullOrEmpty(txtSmtpServ.Text) && !string.IsNullOrEmpty(txtServerPort.Text);
|
|
bool userOk = chkSSL.Checked && (!string.IsNullOrEmpty(txtUser.Text) && !string.IsNullOrEmpty(txtEmailPwd.Text));
|
|
bool mailOk = !string.IsNullOrEmpty(txtEmailFrom.Text) && !string.IsNullOrEmpty(txtEmailDest.Text);
|
|
bool messOk = !string.IsNullOrEmpty(txtSubj.Text) && !string.IsNullOrEmpty(txtMessage.Text);
|
|
return serverOk && userOk && mailOk && messOk;
|
|
}
|
|
}
|
|
|
|
private void btnSendEmail_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// se ho tutti i valori, altrimenti mostro messaggio...
|
|
if (!ParamPresent)
|
|
{
|
|
txtEmailTestOut.Text = "Mancano parametri per invio, prego completare";
|
|
}
|
|
else
|
|
{
|
|
gestEmail emailSend = new gestEmail("");
|
|
if (chkSSL.Checked)
|
|
{
|
|
emailSend = new gestEmail(txtSmtpServ.Text, txtEmailUser.Text, txtEmailPwd.Text);
|
|
}
|
|
else
|
|
{
|
|
emailSend = new gestEmail(txtSmtpServ.Text);
|
|
}
|
|
// invio!
|
|
var result = emailSend.mandaEmail(txtEmailFrom.Text, txtEmailDest.Text, txtSubj.Text, txtMessage.Text);
|
|
txtEmailTestOut.Text = $"Inviato messaggio, esito: {result}";
|
|
}
|
|
}
|
|
catch(Exception exc)
|
|
{
|
|
txtEmailTestOut.Text = $"Eccezione in invio:{Environment.NewLine}{exc}";
|
|
}
|
|
}
|
|
|
|
private void tabPage10_Enter(object sender, EventArgs e)
|
|
{
|
|
// imposto setup...
|
|
txtServerPort.Text = memLayer.ML.CRS("_PortSSL");
|
|
chkSSL.Checked = memLayer.ML.CRB("_enableSSL");
|
|
}
|
|
}
|
|
} |