private void SetupWatcher() { ReleaseWatcher(); string taskPath = null; if (Filter.Wildcard == null) { taskPath = Path.Combine(folder, Filter.TaskName); } if (IsV1) { var di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.System)); string dir = di.Parent != null?Path.Combine(di.Parent.FullName, "Tasks") : "Tasks"; v1Watcher = new FileSystemWatcher(dir, "*.job") { NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Attributes }; v1Watcher.Changed += Watcher_DirectoryChanged; v1Watcher.Created += Watcher_DirectoryChanged; v1Watcher.Deleted += Watcher_DirectoryChanged; v1Watcher.Renamed += Watcher_DirectoryChanged; } else { var log = new TaskEventLog(taskPath, Filter.EventIds, Filter.EventLevels, DateTime.Now, TargetServer, UserAccountDomain, UserName, UserPassword); log.Query.ReverseDirection = false; watcher = new EventLogWatcher(log.Query); watcher.EventRecordWritten += Watcher_EventRecordWritten; } }
private void historyBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { try { /*if (!lvwColumnSorter.Group && lvwColumnSorter.SortColumn == 1) * { * e.Result = null; * //((BackgroundWorker)sender).ReportProgress(100, vlog.Count); * } * else*/ { TaskEventLog log = CreateLogInstance(); List <ListViewItem> list = new List <ListViewItem>(); long i = 0, max = MaxQueryCount == -1 ? log.Count : MaxQueryCount; foreach (var te in log) { if (historyBackgroundWorker.CancellationPending) { e.Cancel = true; break; } if (++i > max) { break; } list.Add(BuildItem(te)); } e.Result = list; //((BackgroundWorker)sender).ReportProgress(100, log.Count); } } catch (Exception ex) { e.Result = ex; } }
/// <summary> /// Initializes a new instance of the <see cref="EventViewerDialog"/> class. /// </summary> /// <param name="taskEvent">The <see cref="TaskEvent"/> to show initially.</param> /// <param name="log">The <see cref="TaskEventLog"/> for the task.</param> public EventViewerDialog(TaskEvent taskEvent = null, TaskEventLog log = null) { InitializeComponent(); if (taskEvent != null) { Initialize(taskEvent, log); } }
/// <summary> /// Initializes the dialog with the specified task event. /// </summary> /// <param name="taskEvent">The <see cref="TaskEvent"/> to show initially.</param> /// <param name="log">The <see cref="TaskEventLog"/> for the task.</param> public void Initialize(TaskEvent taskEvent, TaskEventLog log = null) { if (taskEvent == null) { throw new ArgumentNullException("taskEvent"); } if (log != null) { eventEnum = log.GetEnumerator() as TaskEventEnumerator; eventEnum.Seek(CurrentEvent.EventRecord.Bookmark); } else { eventEnum = null; } CurrentEvent = taskEvent; }
private void historyBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { try { TaskEventLog log = CreateLogInstance(); if (!lvwColumnSorter.Group && lvwColumnSorter.SortColumn == 1) { e.Result = null; } else { List <TaskEvent> eList = new List <TaskEvent>(log); List <ListViewItem> list = eList.ConvertAll <ListViewItem>(delegate(TaskEvent te) { return(BuildItem(te)); }); list.Sort(lvwColumnSorter); e.Result = list; } ((BackgroundWorker)sender).ReportProgress(100, log.Count); } catch (Exception ex) { e.Result = ex; } }
/// <summary> /// Initializes a new instance of the <see cref="CorrelatedTaskEventLog"/> class that looks at all task events from a specified time. /// </summary> /// <param name="startTime">The start time.</param> /// <param name="taskName">Name of the task.</param> /// <param name="machineName">Name of the machine (optional).</param> public CorrelatedTaskEventLog(DateTime startTime, string taskName = null, string machineName = null) { taskLog = new TaskEventLog(startTime, taskName, machineName); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { query.Dispose(); log = null; }
internal CorrelatedTaskEventEnumerator(TaskEventLog log) { this.log = log; query = log.OrderBy(ev => ev).GroupBy(ev => ev.ActivityId.GetValueOrDefault(Guid.Empty), ev => ev).GetEnumerator(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { this.query.Dispose(); this.log = null; }