public void RefreshSystemLog() { SystemLogs.Clear(); foreach (LogModel.SystemLog log in LogDb.Table <LogModel.SystemLog>()) { log.Time = log.Time.ToLocalTime(); SystemLogs.Add(log); } SystemLogsSelectedIndex = SystemLogs.Count - 1; }
public void RefreshBuildLog() { // I don't know why, but LogStats.Clear throws thread exception even though EnableCollectionSynchronization is used. // Reproduce: Remove Dispatcher.Invoke, and run CodeBox three times in a row (without closing LogWindow). // TODO: This is a quick dirty fix. Apply better patch later. Application.Current?.Dispatcher.Invoke(() => { LogStats.Clear(); VariableLogs.Clear(); // Populate SelectBuildEntries LogModel.BuildInfo[] buildEntries = LogDb.Table <LogModel.BuildInfo>() .OrderByDescending(x => x.StartTime) .ToArray(); BuildEntries = new ObservableCollection <LogModel.BuildInfo>(buildEntries); }); SelectedBuildIndex = 0; // Print summary SelectedScriptIndex = 0; }
public void RefreshScripts(int?buildId, bool showLastScript) { // Without dispatcher, ScriptEntries.Clear sets SelectedScriptIndex to -1 too late. Application.Current?.Dispatcher.Invoke(() => { ScriptEntries.Clear(); if (buildId == null) { // Clear SelectedScriptIndex = -1; } else { // Populate SelectScriptEntries ScriptEntries.Add(new Tuple <string, int, int>("Total Summary", -1, (int)buildId)); LogModel.Script[] scripts = LogDb.Table <LogModel.Script>() .Where(x => x.BuildId == buildId && 0 < x.Order) .OrderBy(x => x.Order) .ToArray(); foreach (LogModel.Script sc in scripts) { ScriptEntries.Add(new Tuple <string, int, int>($"[{sc.Order}/{scripts.Length}] {sc.Name} ({sc.TreePath})", sc.Id, (int)buildId)); } if (showLastScript) { SelectedScriptIndex = ScriptEntries.Count - 1; // Display Last Script } else { SelectedScriptIndex = 0; // Summary is always index 0 } } }); }
/// <summary> /// Update build logs /// </summary> public void RefreshBuildLog(int scriptIdx) { if (scriptIdx != -1 && 0 < _scriptEntries.Count) { int scriptId = _scriptEntries[scriptIdx].Item2; int buildId = _scriptEntries[scriptIdx].Item3; if (scriptId == -1) { // Total Summary // BuildLog _allBuildLogs = new List <LogModel.BuildLog>(); foreach (LogState state in new LogState[] { LogState.Error, LogState.Warning }) { var bLogs = LogDb.Table <LogModel.BuildLog>().Where(x => x.BuildId == buildId && x.State == state); _allBuildLogs.AddRange(bLogs); } if (_allBuildLogs.Count == 0) { _allBuildLogs.Add(new LogModel.BuildLog { BuildId = buildId, State = LogState.Info, Message = "No Error or Warning", Time = DateTime.MinValue, }); } BuildLogs = new ObservableCollection <LogModel.BuildLog>(_allBuildLogs); // Variables var varLogs = LogDb.Table <LogModel.Variable>() .Where(x => x.BuildId == buildId && x.Type != VarsType.Local) .OrderBy(x => x.Type) .ThenBy(x => x.Key); VariableLogs = new ObservableCollection <LogModel.Variable>(varLogs); // Statistics List <Tuple <LogState, int> > fullStat = new List <Tuple <LogState, int> >(); var existStates = ((LogState[])Enum.GetValues(typeof(LogState))).Where(x => x != LogState.None && x != LogState.CriticalError); foreach (LogState state in existStates) { int count = LogDb .Table <LogModel.BuildLog>() .Count(x => x.BuildId == buildId && x.State == state); fullStat.Add(new Tuple <LogState, int>(state, count)); } LogStats = new ObservableCollection <Tuple <LogState, int> >(fullStat); } else { // Per Script // BuildLog var builds = LogDb.Table <LogModel.BuildLog>() .Where(x => x.BuildId == buildId && x.ScriptId == scriptId); if (!BuildLogShowComments) { builds = builds.Where(x => (x.Flags & LogModel.BuildLogFlag.Comment) != LogModel.BuildLogFlag.Comment); } if (!BuildLogShowMacros) { builds = builds.Where(x => (x.Flags & LogModel.BuildLogFlag.Macro) != LogModel.BuildLogFlag.Macro); } _allBuildLogs = new List <LogModel.BuildLog>(builds); BuildLogs = new ObservableCollection <LogModel.BuildLog>(_allBuildLogs); // Variables List <LogModel.Variable> varLogs = new List <LogModel.Variable>(); varLogs.AddRange(LogDb.Table <LogModel.Variable>() .Where(x => x.BuildId == buildId && x.Type != VarsType.Local) .OrderBy(x => x.Type) .ThenBy(x => x.Key)); varLogs.AddRange(LogDb.Table <LogModel.Variable>() .Where(x => x.BuildId == buildId && x.ScriptId == scriptId && x.Type == VarsType.Local) .OrderBy(x => x.Key)); VariableLogs = new ObservableCollection <LogModel.Variable>(varLogs); // Statistics List <Tuple <LogState, int> > fullStat = new List <Tuple <LogState, int> >(); var existStates = ((LogState[])Enum.GetValues(typeof(LogState))).Where(x => x != LogState.None && x != LogState.CriticalError); foreach (LogState state in existStates) { int count = LogDb .Table <LogModel.BuildLog>() .Count(x => x.BuildId == buildId && x.ScriptId == scriptId && x.State == state); fullStat.Add(new Tuple <LogState, int>(state, count)); } LogStats = new ObservableCollection <Tuple <LogState, int> >(fullStat); } } else { BuildLogs = new ObservableCollection <LogModel.BuildLog>(); } }