Monitor.cs
18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//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
// /// <summary>
// /// Ütemezések lehetséges állapotai.
// /// </summary>
// public enum ScheduleStates : byte
// {
// /// <summary>
// /// Az ütemezés végrehajtás előtt van, végrehajtásra várakozik.
// /// </summary>
// Active = 0,
// /// <summary>
// /// Az ütemezés a végrehajtás után, ha a végrehajtás sikeresen ért véget.
// /// </summary>
// Success = 1,
// /// <summary>
// /// Az ütemezés végrehajtás után, ha a végrehajtás hibával ért véget.
// /// </summary>
// Failed = 2,
// }
// #endregion Enums
// #region Privates
// private Timer m_timer;
// private iSchedulerXMLProcessor m_xmlp;
// #endregion Privates
// #region Constructor
// /// <summary>
// /// iSchedulerMonitor időzítés figyelő osztály.
// /// </summary>
// /// <param name="scheduleMonitorXmlPath">iScheduler.xml elérési helye a névvel együtt a plugin futtató környezetében.</param>
// /// <param name="scheduleXmlPath">ScheduleExecute akció által használt iScheduler.xml elérési helye a névvel együtt
// /// <param name="pluginReference">Az indító plugin példányra mutató referencia
// /// a távoli gépen. Ha egy gépen fut, akkor nem kötelező.</param>
// 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
// /// <summary>
// /// Időzített események megkeresése, és végrehajtása.
// /// </summary>
// /// <param name="signalTime"></param>
// 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
// // /// <summary>
// // /// Ütemezések lehetséges állapotai.
// // /// </summary>
// // public enum ScheduleStates : byte
// // {
// // /// <summary>
// // /// Az ütemezés végrehajtás előtt van, végrehajtásra várakozik.
// // /// </summary>
// // Active = 0,
// // /// <summary>
// // /// Az ütemezés a végrehajtás után, ha a végrehajtás sikeresen ért véget.
// // /// </summary>
// // Success = 1,
// // /// <summary>
// // /// Az ütemezés végrehajtás után, ha a végrehajtás hibával ért véget.
// // /// </summary>
// // Failed = 2,
// // }
// // #endregion Enums
// // #region Privates
// // private Timer m_timer;
// // private iSchedulerXMLProcessor m_xmlp;
// // private MonitorPlugin _pluginReference = null;
// // #endregion Privates
// // #region Constructor
// // /// <summary>
// // /// iSchedulerMonitor időzítés figyelő osztály.
// // /// </summary>
// // /// <param name="scheduleMonitorXmlPath">iScheduler.xml elérési helye a névvel együtt a plugin futtató környezetében.</param>
// // /// <param name="scheduleXmlPath">ScheduleExecute akció által használt iScheduler.xml elérési helye a névvel együtt
// // /// <param name="pluginReference">Az indító plugin példányra mutató referencia
// // /// a távoli gépen. Ha egy gépen fut, akkor nem kötelező.</param>
// // 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<string, string>
// // {
// // { "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
// // /// <summary>
// // /// Időzített események megkeresése, és végrehajtása.
// // /// </summary>
// // /// <param name="signalTime"></param>
// // private void Examination(DateTime signalTime)
// // {
// // try
// // {
// // var logData = new Dictionary<string, string>()
// // {
// // { "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
// //}
//}