public override async Task ScanEventLogsAsync() { ScanCompleted.Value = false; BlackoutDates.Clear(); var oldest = DateTime.Today - TimeSpan.FromDays(PreferenceService.Preference.MaxDays); DateTime?lastDate = oldest - TimeSpan.FromDays(30); // To easy recognission of oldest date ScannedDate.Value = oldest; AllPowerLogs.Clear(); long maxTimeDiff = PreferenceService.Preference.MaxDays * 86400000L; var queryStr = "<QueryList><Query Id=\"0\" Path=\"System\">" + "<Select Path =\"System\">" + "*[System[Provider[@Name = 'Microsoft-Windows-Kernel-Boot'" + " or @Name = 'Microsoft-Windows-Kernel-General'" + " or @Name = 'Microsoft-Windows-Kernel-Power'" + " or @Name = 'EventLog'] " + " and TimeCreated[timediff(@SystemTime) <= " + $"{maxTimeDiff}" + "]]] </Select></Query></QueryList>"; var query = new EventLogQuery("System", PathType.LogName, queryStr); EventLogReader reader = new EventLogReader(query); EventRecord record = reader.ReadEvent(); while (record != null && !ScanCompleted.Value) { PowerLogEntry pwle = ToPowerLogEntry(record); if (pwle != null) { AllPowerLogs.Add(pwle); if (lastDate != pwle.Timestamp.Date) { UpdateBlackoutDateRange(lastDate, pwle.Timestamp.Date); ScannedDate.Value = lastDate = pwle.Timestamp.Date; await Task.Yield(); } } record = reader.ReadEvent(); } Logger.Debug("AllPowerLogs.Count = {0}", AllPowerLogs.Count); if (AllPowerLogs.Count > 0) { UpdateBlackoutDateRange(lastDate, DateTime.Today + TimeSpan.FromDays(1)); if (!ScanCompleted.Value) // not aborted { ScannedDate.Value = AllPowerLogs[AllPowerLogs.Count - 1].Timestamp.Date; } } else { UpdateBlackoutDateRange(lastDate, DateTime.Today + TimeSpan.FromDays(1)); } BlackoutDateArray = BlackoutDates.ToArray(); ScanCompleted.Value = true; Logger.Debug("Scan completed"); }
protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { if (_calendar != null) { _calendar.DayButtonMouseUp -= Calendar_DayButtonMouseUp; _calendar.DisplayDateChanged -= Calendar_DisplayDateChanged; _calendar.SelectedDatesChanged -= Calendar_SelectedDatesChanged; _calendar.PointerPressed -= Calendar_PointerPressed; _calendar.KeyDown -= Calendar_KeyDown; } _calendar = e.NameScope.Find <Calendar>(ElementCalendar); if (_calendar != null) { _calendar.SelectionMode = CalendarSelectionMode.SingleDate; _calendar.SelectedDate = SelectedDate; SetCalendarDisplayDate(DisplayDate); SetCalendarDisplayDateStart(DisplayDateStart); SetCalendarDisplayDateEnd(DisplayDateEnd); _calendar.DayButtonMouseUp += Calendar_DayButtonMouseUp; _calendar.DisplayDateChanged += Calendar_DisplayDateChanged; _calendar.SelectedDatesChanged += Calendar_SelectedDatesChanged; _calendar.PointerPressed += Calendar_PointerPressed; _calendar.KeyDown += Calendar_KeyDown; //_calendar.SizeChanged += new SizeChangedEventHandler(Calendar_SizeChanged); //_calendar.IsTabStop = true; var currentBlackoutDays = BlackoutDates; BlackoutDates = _calendar.BlackoutDates; if (currentBlackoutDays != null) { foreach (var range in currentBlackoutDays) { BlackoutDates.Add(range); } } } if (_popUp != null) { _popUp.Child = null; _popUp.Closed -= PopUp_Closed; } _popUp = e.NameScope.Find <Popup>(ElementPopup); if (_popUp != null) { _popUp.Closed += PopUp_Closed; if (IsDropDownOpen) { OpenDropDown(); } } if (_dropDownButton != null) { _dropDownButton.Click -= DropDownButton_Click; _buttonPointerPressedSubscription?.Dispose(); } _dropDownButton = e.NameScope.Find <Button>(ElementButton); if (_dropDownButton != null) { _dropDownButton.Click += DropDownButton_Click; _buttonPointerPressedSubscription = _dropDownButton.AddHandler(PointerPressedEvent, DropDownButton_PointerPressed, handledEventsToo: true); } if (_textBox != null) { _textBox.KeyDown -= TextBox_KeyDown; _textBox.GotFocus -= TextBox_GotFocus; _textBoxTextChangedSubscription?.Dispose(); } _textBox = e.NameScope.Find <TextBox>(ElementTextBox); if (!SelectedDate.HasValue) { SetWaterMarkText(); } if (_textBox != null) { _textBox.KeyDown += TextBox_KeyDown; _textBox.GotFocus += TextBox_GotFocus; _textBoxTextChangedSubscription = _textBox.GetObservable(TextBox.TextProperty).Subscribe(txt => TextBox_TextChanged()); if (SelectedDate.HasValue) { _textBox.Text = DateTimeToString(SelectedDate.Value); } else if (!String.IsNullOrEmpty(_defaultText)) { _textBox.Text = _defaultText; SetSelectedDate(); } } base.OnTemplateApplied(e); }