public void Execute(IJobExecutionContext context) { try { // 1. 获取Task 基本信息及 Task 配置的其他参数,任务启动时会读取配置文件节点的值传递过来 TaskModel task = QuartzHelper.GetTaskDetail(context); // 2. 记录Task 运行状态数据库 DbLogHelper.WriteRunInfo(task.TaskName + " 开始", task.TaskID.ToString(), ""); // 3. 开始执行相关任务 LogHelper.WriteLog(task.TaskName + ",当前系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Thread.Sleep(9000); // 4. 记录Task 运行状态数据库 DbLogHelper.WriteRunInfo(task.TaskName + " 结束", task.TaskID.ToString(), "成功执行"); } catch (Exception ex) { JobExecutionException e2 = new JobExecutionException(ex); // 记录异常到数据库和 log 文件中。 DbLogHelper.WriteErrorInfo(ex); //true 是立即重新执行任务 e2.RefireImmediately = true; } }
public static async Task <int> UpdateDbWithNewLogEvents(DateTime trgDate, A0DbModel db) //todo: remove the dupes into central space { int rowsAddedSaved = 0; try { var t1 = trgDate; var t2 = trgDate.AddDays(.99999); await Task.Run(() => EvLogHelper.GetAllUpDnEvents(t1, t2)).ContinueWith(_ => { try { var dailyEvents = _.Result; if (dailyEvents.Count < 1) { Debug.WriteLine($"==>{trgDate:MMM-dd, ddd}: No events registered for the day."); } else { rowsAddedSaved = DbLogHelper.FindNewEventsToSaveToDb(_.Result, Environment.MachineName, $"Db.EvLog.Explr {trgDate}", db); } } catch (Exception ex) { ex.Log(); rowsAddedSaved = -5; } }, TaskScheduler.FromCurrentSynchronizationContext()); } catch (Exception ex) { ex.Log(); rowsAddedSaved = -1; } return(rowsAddedSaved); }
/// <summary> /// 执行指定任务 /// </summary> /// <param name="context"></param> /// <param name="action"></param> public void ExecuteJob(IJobExecutionContext context, Action action) { try { // 1. 获取Task 基本信息及 Task 配置的其他参数,任务启动时会读取配置文件节点的值传递过来 Job task = QuartzHelper.GetTaskDetail(context); // 2. 记录Task 运行状态数据库 DbLogHelper.WriteRunInfo(task.JobName + " 开始", task.JobID.ToString(), ""); // 3. 开始执行相关任务 PerformanceTracer.Invoke(action, task.JobName);//监控并执行任务 // 4. 记录Task 运行状态数据库 DbLogHelper.WriteRunInfo(task.JobName + " 结束", task.JobID.ToString(), "成功执行"); } catch (Exception ex) { JobExecutionException e2 = new JobExecutionException(ex); //true 是立即重新执行任务 e2.RefireImmediately = true; // 记录异常到数据库和 log 文件中。 DbLogHelper.WriteErrorInfo(ex); } }
public void Set_up_transaction_parameters() { DbLogHelper.SetupParametersForTriggerLogging( "test", "localhost"); Assert.That(session.CreateSQLQuery("select @InUser;").UniqueResult <string>(), Is.EqualTo("test")); Assert.That(session.CreateSQLQuery("select @InHost;").UniqueResult <string>(), Is.EqualTo("localhost")); }
public void ResetUin(uint id, string reason) { var user = DbSession.Load <User>(id); DbLogHelper.SetupParametersForTriggerLogging(new { ResetIdCause = reason }); AuditRecord.ReseteUin(user, reason).Save(); user.ResetUin(); Notify("УИН сброшен"); RedirectToReferrer(); }
public void Set_up_transaction_parameters_from_ananymous_object() { DbLogHelper.SetupParametersForTriggerLogging(new { InUser = "******", InHost = "localhost" }); Assert.That(session.CreateSQLQuery("select @InUser;").UniqueResult <string>(), Is.EqualTo("test")); Assert.That(session.CreateSQLQuery("select @InHost;").UniqueResult <string>(), Is.EqualTo("localhost")); }
async void onLoaded(object s, RoutedEventArgs e) { vizroot.IsEnabled = false; try { tbInfo.Text = $"Loading ... "; tbCurVer.Text = $"{VerHelper.CurVerStr(".NET 5.0")}"; var itemsSrc = await DbLogHelper.AllPCsAsync(); tbInfo.Text = $"Loading {itemsSrc.Count} PCs... "; var _localdb = OneDrive.Folder($@"{DbLogHelper._dbSubP}LocalDb({Environment.MachineName}).mdf"); FileAttributeHelper.RmvAttribute(_localdb, FileAttributes.ReadOnly); var _db = A0DbModel.GetLclFl(_localdb); await _db.PcLogics.LoadAsync(); await _db.EvOfInts.LoadAsync(); //foreach (PcLogic item in ((List<PcLogic>)pcLogicDataGridRO.ItemsSource).Where(r => !r.MachineName.Equals(Environment.MachineName, StringComparison.OrdinalIgnoreCase))) _db.PcLogics.Local.Add(item); ((CollectionViewSource)(FindResource("pcLogicViewSource"))).Source = _db.PcLogics.Local; ((CollectionViewSource)(FindResource("evOfIntViewSource"))).Source = _db.EvOfInts.Local; tbInfo.Text = $"{_db.PcLogics.Local.Count} PCs with {_db.EvOfInts.Local.Count} events."; pcLogicDataGridRO.ItemsSource = itemsSrc; foreach (var item in itemsSrc) { if (item.MachineName.Equals(Environment.MachineName, StringComparison.OrdinalIgnoreCase)) { pcLogicDataGridRO.SelectedItem = item; } } pcLogicDataGridRO.Focus(); } catch (Exception ex) { ex.Pop();; } finally { vizroot.IsEnabled = true; } }
}); //addArcDtl(hgt, left, width); void drawUpDnLine(DateTime trgDate, string pc, string rgb) { var pcClr = new SolidColorBrush((Color)ColorConverter.ConvertFromString(rgb)); var ts = new TimeSplit(); //..Trace.Write($">>>-\tdrawUpDnLine(): {trgDate:d} ->> {pc,-16} \t"); tbSummary.Text = "$@#"; try { _ah = canvasBar.ActualHeight; _aw = canvasBar.ActualWidth; var timeA = trgDate; var timeB = trgDate.AddDays(.9999999); var isHere = Environment.MachineName.Equals(pc, StringComparison.OrdinalIgnoreCase); SortedList <DateTime, int> eois; if (isHere) { var localEvLog = EvLogHelper.GetAllUpDnEvents(timeA, timeB); var dbaseEvLog = DbLogHelper.GetAllUpDnEvents(timeA, timeB, pc); eois = localEvLog.Count > dbaseEvLog.Count ? localEvLog : dbaseEvLog; // Jan 2020: whoever has more events wins! } else { eois = DbLogHelper.GetAllUpDnEvents(timeA, timeB, pc); } if (trgDate == DateTime.Today && isHere) { eois.Add(DateTime.Now, 2); // == ((int)EvOfIntFlag.ScreenSaverrUp) } if (eois.Count < 1) { tbSummary.Text = $"{trgDate,16:ddd, MMM dd yyyy} no activities logged on this date."; } else { var eoi0 = eois.FirstOrDefault(); var prevEoiF = eoi0.Value == (int)EvOfIntFlag.ScreenSaverrDn ? EvOfIntFlag.ScreenSaverrUp : eoi0.Value == (int)EvOfIntFlag.BootAndWakeUps ? EvOfIntFlag.ShutAndSleepDn : EvOfIntFlag.Day1stAmbiguos; foreach (var eoi in eois) { addWkTimeSegment(timeA, eoi.Key, prevEoiF, (EvOfIntFlag)eoi.Value, pcClr, ref ts); timeA = eoi.Key; prevEoiF = (EvOfIntFlag)eoi.Value; } var lastScvrUp = (eois.Any(r => r.Value == (int)EvOfIntFlag.ScreenSaverrUp || r.Value == (int)EvOfIntFlag.ShutAndSleepDn) ? eois.Where(r => r.Value == (int)EvOfIntFlag.ScreenSaverrUp || r.Value == (int)EvOfIntFlag.ShutAndSleepDn).Last() : eois.Last()).Key; var finalEvent = eois.Last().Key; ts.TotalDaysUp = (lastScvrUp < finalEvent ? lastScvrUp : finalEvent) - eois.First().Key; tbSummary.Text = $"{trgDate,16:ddd, MMM dd yyyy} {ts.TotalDaysUp,5:h\\:mm} ({ts.WorkedFor:h\\:mm}) "; } tbSummary.Foreground = (trgDate.DayOfWeek == DayOfWeek.Saturday || trgDate.DayOfWeek == DayOfWeek.Sunday) ? cWEd : cWDd; gridvroot.Background = (trgDate.DayOfWeek == DayOfWeek.Saturday || trgDate.DayOfWeek == DayOfWeek.Sunday) ? cPnk : cBlk; } catch (Exception ex) { ex.Pop(); } finally { Trace.WriteLine($" ==> { tbSummary.Text} "); } }