//using Newtonsoft.Json; //using System; //using System.Linq; //using System.Text; //using System.Timers; //using System.Data.SqlClient; //using System.Xml.Linq; //using System.Collections.Generic; //using Vrh.Logger; //using Vrh.iScheduler; //namespace iSchedulerMonitorXXXX //{ // public class Monitor : IDisposable // { // #region Enums // /// // /// Ütemezések lehetséges állapotai. // /// // public enum ScheduleStates : byte // { // /// // /// Az ütemezés végrehajtás előtt van, végrehajtásra várakozik. // /// // Active = 0, // /// // /// Az ütemezés a végrehajtás után, ha a végrehajtás sikeresen ért véget. // /// // Success = 1, // /// // /// Az ütemezés végrehajtás után, ha a végrehajtás hibával ért véget. // /// // Failed = 2, // } // #endregion Enums // #region Privates // private Timer m_timer; // private iSchedulerXMLProcessor m_xmlp; // #endregion Privates // #region Constructor // /// // /// iSchedulerMonitor időzítés figyelő osztály. // /// // /// iScheduler.xml elérési helye a névvel együtt a plugin futtató környezetében. // /// ScheduleExecute akció által használt iScheduler.xml elérési helye a névvel együtt // /// Az indító plugin példányra mutató referencia // /// a távoli gépen. Ha egy gépen fut, akkor nem kötelező. // public Monitor(string scheduleMonitorXmlPath, string scheduleXmlPath) // { // //try // //{ // m_xmlp = new iSchedulerXMLProcessor(scheduleMonitorXmlPath, scheduleXmlPath); // m_timer = new Timer(m_xmlp.CheckInterval * 1000); // !!! Ez itt a jó sor !!! // // m_timer = new Timer(20000); // !!! Ez meg itt a debug !!! // m_timer.Elapsed += OnExamination; // var le = new DCLogEntry(LogLevel.Debug, nameof(Monitor) + " constructor. Preparation ready."); // le.AddDataField("iSchedulerMonitor xml path", scheduleMonitorXmlPath); // le.AddDataField("iScheduler xml path", scheduleXmlPath); // le.AddDataField("Scheduled object type", m_xmlp.ObjectType); // le.AddDataField("Group Id", m_xmlp.GroupId); // le.AddDataField("Check interval", m_xmlp.CheckInterval.ToString()); // le.Write(); // //} // //catch (Exception ex) // //{ // // var message = String.Join(",", WebCommon.ErrorListBuilder(ex)); // // MyLog("PREPARATION ERROR. " + message); // // throw new ApplicationException("PREPARATION ERROR. ", ex); // //} // } // #endregion Constructor // public void Start() // { // new DCLogEntry(LogLevel.Information, "iSchedulerMonitor started.").Write(); // m_timer.Start(); // } // public void Stop() // { // m_timer.Stop(); // new DCLogEntry(LogLevel.Information, "iSchedulerMonitor stopped.").Write(); // } // #region Private methods // private void OnExamination(object sender, ElapsedEventArgs e) // { // m_timer.Stop(); // Examination(e.SignalTime); // m_timer.Start(); // } // #region Examination // /// // /// Időzített események megkeresése, és végrehajtása. // /// // /// // private void Examination(DateTime signalTime) // { // var le = new DCLogEntry(LogLevel.Debug, nameof(Examination)); // try // { // using (SqlConnection cnn = new SqlConnection(m_xmlp.DatabaseConnectionString)) // { // cnn.Open(); // le.AddDataField("Database connection opened", $"Connection string: {m_xmlp.DatabaseConnectionString}"); // string scmd = string.Concat( // " select *", // " from iScheduler.Schedules s", // " inner join iScheduler.ScheduleObjects so on s.ScheduleObjectId = so.Id", // " where s.[State] = 0 and s.OperationTime < @signalTime", // " and so.ObjectType = @objectType and so.ObjectGroupId = @groupId"); // using (SqlCommand cmd = new SqlCommand(scmd, cnn)) // { // cmd.Parameters.Add(new SqlParameter("signalTime", signalTime)); // cmd.Parameters.Add(new SqlParameter("objectType", m_xmlp.ObjectType)); // cmd.Parameters.Add(new SqlParameter("groupId", m_xmlp.GroupId)); // SqlDataReader rdr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); // if (rdr.HasRows) // { // int ixID = rdr.GetOrdinal("Id"); // //string basefolder = AppDomain.CurrentDomain.BaseDirectory; // //basefolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // //basefolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); // string basefolder = System.IO.Directory.GetCurrentDirectory(); // ScheduleExecute se = new ScheduleExecute(m_xmlp.ScheduleXmlPath, basefolder); // int ScheduledJobCounter = 0; // while (rdr.Read()) // { // ScheduledJobCounter++; // int id = rdr.GetInt32(ixID); // DateTime jobstartedat = DateTime.Now; // le.AddDataField($"Scheduled job #{ScheduledJobCounter} started", $"id={id}"); // se.Run(id); // le.AddDataField($"Scheduled job #{ScheduledJobCounter} finished at", (DateTime.Now).Subtract(jobstartedat).ToString(@"hh\:mm\:ss")); // le.AddSuccessResult("Scheduled job execution SUCCESS"); // }//while (rdr.Read()) // }//if (rdr.HasRows) // else { le.AddSuccessResult($"No scheduled job found!"); } // } // } // } // catch (Exception ex) // { // le.SetLogLevel(LogLevel.Error); // le.AddExceptionResult(ex); // } // finally { le.Write(); } // } // #endregion Examination // #endregion Private methods // #region IDisposable Support // private bool disposedValue = false; // To detect redundant calls // protected virtual void Dispose(bool disposing) // { // if (!disposedValue) // { // if (disposing) // { // // TODO: dispose managed state (managed objects). // } // // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // // TODO: set large fields to null. // disposedValue = true; // } // } // // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. // // ~iScheduler() { // // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. // // Dispose(false); // // } // // This code added to correctly implement the disposable pattern. // public void Dispose() // { // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. // Dispose(true); // // TODO: uncomment the following line if the finalizer is overridden above. // // GC.SuppressFinalize(this); // } // #endregion // } // //internal class Monitor : IDisposable // //{ // // #region Enums // // /// // // /// Ütemezések lehetséges állapotai. // // /// // // public enum ScheduleStates : byte // // { // // /// // // /// Az ütemezés végrehajtás előtt van, végrehajtásra várakozik. // // /// // // Active = 0, // // /// // // /// Az ütemezés a végrehajtás után, ha a végrehajtás sikeresen ért véget. // // /// // // Success = 1, // // /// // // /// Az ütemezés végrehajtás után, ha a végrehajtás hibával ért véget. // // /// // // Failed = 2, // // } // // #endregion Enums // // #region Privates // // private Timer m_timer; // // private iSchedulerXMLProcessor m_xmlp; // // private MonitorPlugin _pluginReference = null; // // #endregion Privates // // #region Constructor // // /// // // /// iSchedulerMonitor időzítés figyelő osztály. // // /// // // /// iScheduler.xml elérési helye a névvel együtt a plugin futtató környezetében. // // /// ScheduleExecute akció által használt iScheduler.xml elérési helye a névvel együtt // // /// Az indító plugin példányra mutató referencia // // /// a távoli gépen. Ha egy gépen fut, akkor nem kötelező. // // public Monitor(string scheduleMonitorXmlPath, string scheduleXmlPath, MonitorPlugin pluginReference) // // { // // //try // // //{ // // _pluginReference = pluginReference; // // m_xmlp = new iSchedulerXMLProcessor(scheduleMonitorXmlPath, scheduleXmlPath); // // m_timer = new Timer(m_xmlp.CheckInterval * 1000); // !!! Ez itt a jó sor !!! // // // m_timer = new Timer(20000); // !!! Ez meg itt a debug !!! // // m_timer.Elapsed += OnExamination; // // var logData = new Dictionary // // { // // { "iSchedulerMonitor xml path", scheduleMonitorXmlPath }, // // { "iScheduler xml path", scheduleXmlPath }, // // { "Scheduled object type", m_xmlp.ObjectType }, // // { "Group Id", m_xmlp.GroupId }, // // { "Check interval", m_xmlp.CheckInterval.ToString() } // // }; // // _pluginReference.LogThis("Preparation ready.", logData, null, LogLevel.Debug, this.GetType()); // // //} // // //catch (Exception ex) // // //{ // // // var message = String.Join(",", WebCommon.ErrorListBuilder(ex)); // // // MyLog("PREPARATION ERROR. " + message); // // // throw new ApplicationException("PREPARATION ERROR. ", ex); // // //} // // } // // #endregion Constructor // // public void Start() // // { // // _pluginReference.LogThis("iSchedulerMonitor started.", null, null, LogLevel.Information, this.GetType()); // // m_timer.Start(); // // } // // public void Stop() // // { // // m_timer.Stop(); // // _pluginReference.LogThis("iSchedulerMonitor stopped.", null, null, LogLevel.Information, this.GetType()); // // } // // #region Private methods // // private void OnExamination(object sender, ElapsedEventArgs e) // // { // // m_timer.Stop(); // // Examination(e.SignalTime); // // m_timer.Start(); // // } // // #region Examination // // /// // // /// Időzített események megkeresése, és végrehajtása. // // /// // // /// // // private void Examination(DateTime signalTime) // // { // // try // // { // // var logData = new Dictionary() // // { // // { "Start time", $"{signalTime:HH:mm:ss}"} // // }; // // _pluginReference.LogThis($"Examination cycle started.", logData, null, LogLevel.Verbose, this.GetType()); // // using (SqlConnection cnn = new SqlConnection(m_xmlp.DatabaseConnectionString)) // // { // // cnn.Open(); // // logData.Add("Database connection string", m_xmlp.DatabaseConnectionString); // // _pluginReference.LogThis($"Database connection opened.", logData, null, LogLevel.Verbose, this.GetType()); // // string scmd = string.Concat( // // " select *", // // " from iScheduler.Schedules s", // // " inner join iScheduler.ScheduleObjects so on s.ScheduleObjectId = so.Id", // // " where s.[State] = 0 and s.OperationTime < @signalTime", // // " and so.ObjectType = @objectType and so.ObjectGroupId = @groupId"); // // using (SqlCommand cmd = new SqlCommand(scmd, cnn)) // // { // // cmd.Parameters.Add(new SqlParameter("signalTime", signalTime)); // // cmd.Parameters.Add(new SqlParameter("objectType", m_xmlp.ObjectType)); // // cmd.Parameters.Add(new SqlParameter("groupId", m_xmlp.GroupId)); // // SqlDataReader rdr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); // // if (rdr.HasRows) // // { // // _pluginReference.LogThis($"Scheduled job found!", logData, null, LogLevel.Verbose, this.GetType()); // // int ixID = rdr.GetOrdinal("Id"); // // //string basefolder = AppDomain.CurrentDomain.BaseDirectory; // // //basefolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // // //basefolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); // // string basefolder = System.IO.Directory.GetCurrentDirectory(); // // ScheduleExecute se = new ScheduleExecute(m_xmlp.ScheduleXmlPath,basefolder); // // int ScheduledJobCounter = 0; // // while (rdr.Read()) // // { // // ScheduledJobCounter++; // // int id = rdr.GetInt32(ixID); // // DateTime jobstartedat = DateTime.Now; // // logData.Add($"{ScheduledJobCounter}. scheduled job Id", id.ToString()); // // _pluginReference.LogThis($"Scheduled job execution started (job index in cycle: #{ScheduledJobCounter.ToString()})!", logData, null, LogLevel.Verbose, this.GetType()); // // se.Run(id); // // DateTime jobfinishedat = DateTime.Now; // // string jobexecutiontime = jobfinishedat.Subtract(jobstartedat).ToString(@"hh\:mm\:ss"); // // _pluginReference.LogThis($"Scheduled job execution finished (execution time: {jobexecutiontime} !", logData, null, LogLevel.Verbose, this.GetType()); // // }//while (rdr.Read()) // // }//if (rdr.HasRows) // // else // // { // // _pluginReference.LogThis($"No scheduled job found!", logData, null, LogLevel.Verbose, this.GetType()); // // } // // } // // } // // } // // catch (Exception ex) // // { // // _pluginReference.LogThis($"Exception in scheduled job execution.", null, ex, LogLevel.Error, this.GetType()); // // } // // } // // #endregion Examination // // #endregion Private methods // // #region IDisposable Support // // private bool disposedValue = false; // To detect redundant calls // // protected virtual void Dispose(bool disposing) // // { // // if (!disposedValue) // // { // // if (disposing) // // { // // // TODO: dispose managed state (managed objects). // // } // // // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // // // TODO: set large fields to null. // // disposedValue = true; // // } // // } // // // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. // // // ~iScheduler() { // // // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. // // // Dispose(false); // // // } // // // This code added to correctly implement the disposable pattern. // // public void Dispose() // // { // // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. // // Dispose(true); // // // TODO: uncomment the following line if the finalizer is overridden above. // // // GC.SuppressFinalize(this); // // } // // #endregion // //} //}