| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Threading;
- using TeamAAS.Logging;
- namespace TeamAAS.Dialogs.Dialogs
- {
- /// <summary>
- /// 日志条目详情窗(由实时日志控件 LogView 双击弹出):
- /// 显示 类别 / 时间 / 来源(公共=[source],插件=[流程][任务])/ 插件详细度 / 完整内容,支持一键复制。
- /// </summary>
- public partial class LogDetailWindow
- {
- private readonly LogEntry _entry;
- public LogDetailWindow(LogEntry entry)
- {
- InitializeComponent();
- UiScaler.Attach(this); // 分辨率/DPI 自适应
- _entry = entry;
- Populate();
- }
- private void Populate()
- {
- var e = _entry;
- if (e == null)
- {
- MessageText.Text = "";
- return;
- }
- Title = "日志详情 - " + e.CategoryText;
- CategoryText.Text = e.CategoryText;
- CategoryBadge.Background = CategoryBrush(e.Category);
- TimeText.Text = e.Time.ToString("yyyy-MM-dd HH:mm:ss.fff");
- // 来源:公共日志显示 [ProductManager] 之类,插件显示 [流程][任务]
- SourceValue.Text = string.IsNullOrWhiteSpace(e.OriginText) ? "—" : e.OriginText;
- if (e.IsPlugin)
- {
- FlowRow.Visibility = Visibility.Visible;
- FlowValue.Text = e.Flow + " / " + e.Task;
- LevelRow.Visibility = Visibility.Visible;
- LevelValue.Text = e.Level + " 级(" + (e.Tier == 2 ? "常规" : "详细") + " · " + e.TierText + ")";
- }
- else
- {
- FlowRow.Visibility = Visibility.Collapsed;
- LevelRow.Visibility = Visibility.Collapsed;
- }
- MessageText.Text = e.Message;
- }
- private static Brush CategoryBrush(LogLevel category)
- {
- string hex;
- switch (category)
- {
- case LogLevel.Warning: hex = "#FF9800"; break;
- case LogLevel.Error: hex = "#F44336"; break;
- default: hex = "#2D6CDF"; break;
- }
- var brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hex));
- brush.Freeze();
- return brush;
- }
- private string BuildFullText()
- {
- var e = _entry;
- if (e == null) return "";
- var sb = new StringBuilder();
- sb.Append("[类别] ").Append(e.CategoryText).AppendLine();
- sb.Append("[时间] ").Append(e.Time.ToString("yyyy-MM-dd HH:mm:ss.fff")).AppendLine();
- sb.Append("[来源] ").Append(string.IsNullOrWhiteSpace(e.OriginText) ? "—" : e.OriginText).AppendLine();
- if (e.IsPlugin)
- {
- sb.Append("[流程/任务] ").Append(e.Flow).Append(" / ").Append(e.Task).AppendLine();
- sb.Append("[详细度] ").Append(e.Level).Append(" 级 / ").Append(e.TierText).AppendLine();
- }
- sb.Append("[内容]").AppendLine();
- sb.Append(e.Message);
- return sb.ToString();
- }
- private void BtnCopyMessage_Click(object sender, RoutedEventArgs e)
- => Copy(_entry?.Message, BtnCopyMessage, "复制内容");
- private void BtnCopyAll_Click(object sender, RoutedEventArgs e)
- => Copy(BuildFullText(), BtnCopyAll, "复制全部");
- private static void Copy(string text, Button button, string restoreLabel)
- {
- if (string.IsNullOrEmpty(text)) return;
- try
- {
- Clipboard.SetText(text);
- button.Content = "已复制";
- var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1.5) };
- timer.Tick += (s, args) => { button.Content = restoreLabel; timer.Stop(); };
- timer.Start();
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("[LogDetailWindow] copy failed: " + ex.Message);
- }
- }
- private void BtnClose_Click(object sender, RoutedEventArgs e) => Close();
- }
- }
|