Files
MoonPro.net/MP-IO/inputIOB.aspx.cs
T
2016-11-11 18:13:50 +01:00

114 lines
4.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SteamWare;
using MapoDb;
using System.Globalization;
namespace MP_IO
{
public partial class inputIOB : System.Web.UI.Page
{
/// <summary>
/// caricamento pagina
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
// legge i get x processare la seriale
string idxMacchina = "";
string valore = "";
string dtEve = "";
string dtCurr = "";
string contatore = "";
string answ = "";
DateTime dataOraEvento = DateTime.Now;
try
{
idxMacchina = Request.QueryString["idxMacchina"];
valore = Request.QueryString["valore"];
dtEve = Request.QueryString["dtEve"]; // formato yyyymmddHHMMSSnnn ovvero da anno a millisecondi
dtCurr = Request.QueryString["dtCurr"]; // formato yyyymmddHHMMSSnnn ovvero da anno a millisecondi
contatore = Request.QueryString["cnt"];
if (contatore == "" || contatore == null) contatore = "0";
if (memLayer.ML.CRI("_logLevel") > 6)
{
logger.lg.scriviLog(string.Format("Valori letti:{0}idxMacchina: {1}{0}valore: {2}{0}dtEve: {3}{0}dtCurr: {4}{0}cnt: {5}", Environment.NewLine, idxMacchina, valore, dtEve, dtCurr, contatore), tipoLog.INFO);
}
}
catch
{ }
// controllo: se ho valori dt x evento e orario DIVERSI per acquisitore IOB calcolo dataOraEvento corretto
if (dtEve != dtCurr)
{
Int64 delta = 0;
try
{
delta = Convert.ToInt64(dtCurr) - Convert.ToInt64(dtEve);
// se meno di 60'000 ms ...
if (delta < 59999)
{
dataOraEvento = dataOraEvento.AddMilliseconds(-delta);
}
else
{
// in questo caso elimino i MS dalle stringhe e converto i datetime....
CultureInfo provider = CultureInfo.InvariantCulture;
string format = "yyyyMMddHHmmssfff";
DateTime dtEvento = DateTime.ParseExact(dtEve, format, provider);
DateTime dtCorrente = DateTime.ParseExact(dtCurr, format, provider);
Int64 tiks = dtCorrente.Ticks - dtEvento.Ticks;
dataOraEvento = dataOraEvento.AddTicks(-tiks);
}
}
catch(Exception exc)
{
logger.lg.scriviLog(string.Format("Errore calcolo ms evento/ora corrente da device remoto:{0}dtEve: {1}{0}dtCurr: {2}{0}{3}", Environment.NewLine, dtEve, dtCurr, exc), tipoLog.EXCEPTION);
}
}
//
if (idxMacchina != null && valore != null)
{
if (idxMacchina != "" && valore != "")
{
try
{
// ora processo e salvo il valore del microstato...
MapoDb.MapoDb.obj.checkMicroStato(idxMacchina, valore, dataOraEvento, contatore);
answ = "OK"; // registro in risposta che è andato tutto bene...
}
catch (Exception exc)
{
if (memLayer.ML.confReadInt("_logLevel") > 5)
{
string errore = string.Format("Errore: {0}{1}", Environment.NewLine, exc);
logger.lg.scriviLog(errore, tipoLog.EXCEPTION);
answ = errore;
}
}
}
else
{
string errore = "Errore: parametri macchina/valore vuoti";
logger.lg.scriviLog(errore, tipoLog.ERROR);
answ = errore;
}
}
else
{
string errore = "Errore: mancano parametri macchina/valore";
logger.lg.scriviLog(errore, tipoLog.ERROR);
answ = errore;
}
// ripulisco pagina restituita e tolgo html (solo codice ok/NO)
Response.Clear();
Response.Write(answ);
Context.Response.End();
}
}
}