136 lines
5.5 KiB
C#
136 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.ServiceProcess;
|
|
using System.Text;
|
|
using SteamWare;
|
|
using C2P_Data;
|
|
|
|
namespace C2P_CronJob
|
|
{
|
|
public partial class C2P_service : ServiceBase
|
|
{
|
|
public C2P_service()
|
|
{
|
|
InitializeComponent();
|
|
eventLog1 = new System.Diagnostics.EventLog();
|
|
if (!System.Diagnostics.EventLog.SourceExists("C2P_Source"))
|
|
{
|
|
System.Diagnostics.EventLog.CreateEventSource("C2P_Source", "C2P_CronjobLog");
|
|
}
|
|
eventLog1.Source = "C2P_Source";
|
|
eventLog1.Log = "C2P_CronjobLog";
|
|
}
|
|
|
|
protected override void OnStart(string[] args)
|
|
{
|
|
eventLog1.WriteEntry("C2P_Cronjob: servizio in OnStart");
|
|
// Set up a timer to trigger every minute.
|
|
System.Timers.Timer timer = new System.Timers.Timer();
|
|
timer.Interval = memLayer.ML.confReadInt("timerShortSec")*1000;
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
|
|
timer.Start();
|
|
}
|
|
|
|
protected override void OnStop()
|
|
{
|
|
eventLog1.WriteEntry("C2P_Cronjob: servizio in OnStop");
|
|
}
|
|
protected override void OnContinue()
|
|
{
|
|
eventLog1.WriteEntry("C2P_Cronjob: servizio in OnContinue.");
|
|
}
|
|
public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
|
|
{
|
|
// verifico se ci sia una richiesta di procesisng quotidiana (o meno) e nel caso NON ci fosse la inserisco
|
|
if (!checkDailyReq)
|
|
{
|
|
creaRichiesteImport();
|
|
eventLog1.WriteEntry("Inserite richieste import quotidiane", EventLogEntryType.Information);
|
|
}
|
|
// verifico se ci siano nuove righe da processare...
|
|
if (checkPendingTicketReq)
|
|
{
|
|
eventLog1.WriteEntry("Trovate richieste pendenti, inizio processing...", EventLogEntryType.Information);
|
|
processTicketlist();
|
|
eventLog1.WriteEntry("Completato processing richieste pendenti", EventLogEntryType.Information);
|
|
}
|
|
// se richiesto registro timer short...
|
|
if (memLayer.ML.confReadInt("_logLevel") > 6) eventLog1.WriteEntry("Verifiche timer", EventLogEntryType.Information);
|
|
}
|
|
/// <summary>
|
|
/// verifica se ci siano o meno delle richeiste quotidiane di import già registrate
|
|
/// </summary>
|
|
protected bool checkDailyReq
|
|
{
|
|
get
|
|
{
|
|
bool answ = true;
|
|
// controllo se non sia già oltre l'ora "critica", altrimenti restituisce "ok" comunque... (x non continuare a creare altri record dalle 22 in poi)
|
|
if (DateTime.Now < DateTime.Now.Date.AddHours(memLayer.ML.confReadInt("importStartHour")))
|
|
{
|
|
try
|
|
{
|
|
// in questo caso cerco se ci siano pending all'ora configurata x avvio + 5 minuti
|
|
DateTime oraRif = DateTime.Now.Date.AddHours(memLayer.ML.confReadInt("importStartHour")).AddMinutes(5);
|
|
answ = (DtProxy.man.taImpTL.getPending(oraRif).Count > 0);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// verifica se ci siano richieste inevase e non scadute in tabella TicketList
|
|
/// </summary>
|
|
protected bool checkPendingTicketReq
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = (DtProxy.man.taImpTL.getPending(DateTime.Now).Count > 0);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// chiama le procedure per il processing della ticket list
|
|
/// </summary>
|
|
protected void processTicketlist()
|
|
{
|
|
DtProxy.man.taImpTL.processQueue(memLayer.ML.confReadInt("maxTimeProcessOld"));
|
|
}
|
|
/// <summary>
|
|
/// inserisce le richieste quotidiane per processare import
|
|
/// </summary>
|
|
protected void creaRichiesteImport()
|
|
{
|
|
DateTime oraStart = DateTime.Now.Date.AddHours(memLayer.ML.confReadInt("importStartHour"));
|
|
// inserisco le richieste x la data odierna, ora da web.config, spostate di 1 min tra i vari step
|
|
DS_Utility.Import_TicketListRow riga;
|
|
try
|
|
{
|
|
// primo step
|
|
string param = string.Format(memLayer.ML.confReadString("step01_par"), "0");
|
|
riga = (DS_Utility.Import_TicketListRow)DtProxy.man.taImpTL.InsertQuery(memLayer.ML.confReadString("step01_stp"), param, oraStart)[0];
|
|
// secondo step
|
|
param = string.Format(memLayer.ML.confReadString("step02_par"), riga.NumTicket);
|
|
riga = (DS_Utility.Import_TicketListRow)DtProxy.man.taImpTL.InsertQuery(memLayer.ML.confReadString("step02_stp"), param, oraStart.AddMinutes(1))[0];
|
|
// terzo step!
|
|
param = string.Format(memLayer.ML.confReadString("step03_par"), riga.NumTicket);
|
|
riga = (DS_Utility.Import_TicketListRow)DtProxy.man.taImpTL.InsertQuery(memLayer.ML.confReadString("step03_stp"), param, oraStart.AddMinutes(2))[0];
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
}
|
|
}
|