using CommunityToolkit.Mvvm.ComponentModel; using log4net; using Microsoft.IdentityModel.Logging; using Polly; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using Admin.Core.Tasks; using Aucma.Core.SheetMetal.Business; using Aucma.Core.SheetMetal.Models; namespace Aucma.Core.SheetMetal.ViewModels { public class LogPageViewModel : ObservableObject { private static readonly log4net.ILog log = LogManager.GetLogger(typeof(LogPageViewModel)); private ObservableCollection listItems = new ObservableCollection(); public LogPageViewModel() { SheetMetalPlanTaskHandle.RefreshExecInfoEvent += PrintMessageToListBox; } /// /// LisBox数据模板 /// private IEnumerable logInfoListBox; public IEnumerable LogInfoListBox { get => logInfoListBox; set => SetProperty(ref logInfoListBox, value); } /// /// listBox绑定日志 /// /// /// Red or White private void PrintMessageToListBox(string message, string color) { try { System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { string content = $"{DateTime.Now.ToString("HH:mm:ss")}==>{message}"; ListBoxDataView view = new ListBoxDataView { Content = content, Color = color }; //listItems.Add(view); listItems.Insert(0, view); LogInfoListBox = listItems; })); } catch (Exception ex) { log.Error("日志数据绑定异常", ex); } } public ObservableCollection Items { get; set; } } }