Add project files.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<UserControl x:Class="SafeBagDE70.Admin.AdminConfigurationUC"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SafeBagDE70.Admin"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Background="LightGray" VerticalAlignment="Top">
|
||||
<Button
|
||||
Content="THIẾT LẬP BỘ ĐẾM"
|
||||
x:Name="btnResetCounter"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="btnResetCounter_Click"/>
|
||||
<Button
|
||||
Content="MỞ NGĂN PHỤ"
|
||||
x:Name="btnOpenEscrow"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="btnOpenEscrow_Click"/>
|
||||
<Button
|
||||
Content="LẤY TRẠNG THÁI MÁY"
|
||||
x:Name="btnGetCDMState"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="btnGetCDMState_Click"/>
|
||||
<hc:HighlightTextBlock x:Name="lblCounterStatus" FontSize="20" FontWeight="Bold" TextWrapping="Wrap" Foreground="Green" Text=""/>
|
||||
<hc:HighlightTextBlock x:Name="lblDeviceStatus" FontSize="14" TextWrapping="Wrap" Foreground="Red" Text=""/>
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,99 @@
|
||||
using DE70_CMDv2;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SafeBagDE70.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AdminConfigurationUC.xaml
|
||||
/// </summary>
|
||||
public partial class AdminConfigurationUC : UserControl
|
||||
{
|
||||
public AdminConfigurationUC()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void btnResetCounter_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AppData.cCmdRsp != null)
|
||||
{
|
||||
Log.Information("[ADMIN] reset counter");
|
||||
CCmdRsp cCmdRsp = AppData.cCmdRsp;
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_UNLOCK);
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
//Event fix
|
||||
var recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] == recvData.dat[16])
|
||||
{
|
||||
cCmdRsp.SendLock();
|
||||
}
|
||||
else
|
||||
{
|
||||
cCmdRsp.SendEventFix(recvData.dat[16]);
|
||||
cCmdRsp.SendLock();
|
||||
}
|
||||
|
||||
var currentMode = cCmdRsp.GetLockParam().mode;
|
||||
cCmdRsp.GetLockParam().mode = Mode.MODE_COLLECTION;
|
||||
cCmdRsp.SendLock();
|
||||
Thread.Sleep(10000);
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] != recvData.dat[16])
|
||||
{
|
||||
Log.Information("[ADMIN] reset counter success");
|
||||
lblCounterStatus.Text = "TRẠNG THÁI: KHỞI TẠO BỘ ĐẾM THÀNH CÔNG";
|
||||
((MainWindow)Application.Current.MainWindow).ShowWelcomeScreen();
|
||||
Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(2);
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
lblCounterStatus.Text = "";
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information("[ADMIN] reset counter fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnOpenEscrow_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Log.Information("[ADMIN] Do Check");
|
||||
var mainWindow = ((MainWindow)Application.Current.MainWindow);
|
||||
if (mainWindow!=null)
|
||||
mainWindow.DoCheck();
|
||||
}
|
||||
|
||||
private void btnGetCDMState_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var state = AppData.GetCDMState();
|
||||
lblDeviceStatus.Text = state.GetFullStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<UserControl x:Class="SafeBagDE70.Admin.AdminLoginUC"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SafeBagDE70.Admin"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="1024" d:DesignWidth="1280">
|
||||
<Grid>
|
||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<TextBlock Text="Admin Login" FontSize="20" HorizontalAlignment="Center"/>
|
||||
<TextBox x:Name="UsernameTextBox" Width="200" Margin="10" />
|
||||
<PasswordBox x:Name="PasswordBox" Width="200" Margin="10" />
|
||||
<Button Content="Login" Width="200" Margin="10" Click="LoginButton_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SafeBagDE70.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AdminLoginUC.xaml
|
||||
/// </summary>
|
||||
public partial class AdminLoginUC : UserControl
|
||||
{
|
||||
public AdminLoginUC()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LoginButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string username = UsernameTextBox.Text;
|
||||
string password = PasswordBox.Password;
|
||||
|
||||
// Simple authentication logic
|
||||
if (username == "admin" && password == "password") // Replace with actual logic
|
||||
{
|
||||
// Load Settings UserControl
|
||||
var mainWindow = (MainWindow)Window.GetWindow(this);
|
||||
//mainWindow.LoadUserControl(new SettingsUserControl());
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Invalid username or password.", "Login Failed", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<UserControl x:Class="SafeBagDE70.Admin.AdminMainUC"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SafeBagDE70.Admin"
|
||||
d:DesignHeight="1024" d:DesignWidth="1280"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<!-- Define Rows and Columns -->
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="50"/>
|
||||
<!-- Top Bar -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- Main Content Area -->
|
||||
<RowDefinition Height="30"/>
|
||||
<!-- Footer -->
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<!-- Sidebar -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- Main Content Area -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Top Bar -->
|
||||
<StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal" Background="Gray" Height="50">
|
||||
<TextBlock Text="Admin Panel" VerticalAlignment="Center" Margin="10" Foreground="White" FontSize="20"/>
|
||||
<Button Content="Log Out"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,10,0"
|
||||
Click="LogoutButton_Click"
|
||||
Background="Red"
|
||||
Foreground="White" Width="100"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Background="LightGray" VerticalAlignment="Top">
|
||||
<Button
|
||||
Content="Dashboard"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="DashboardButton_Click"/>
|
||||
<Button
|
||||
Content="User Management"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="UserManagementButton_Click"/>
|
||||
<Button
|
||||
Content="Settings"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="SettingsButton_Click"/>
|
||||
<Button
|
||||
Content="Reports"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Padding="10"
|
||||
Click="ReportsButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Main Content Area -->
|
||||
<ContentControl Grid.Row="1" Grid.Column="1" x:Name="MainContentControl" Margin="10"/>
|
||||
|
||||
<!-- Footer -->
|
||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal" Background="Gray" Height="30">
|
||||
<TextBlock Text="Admin Panel - Version 1.0" VerticalAlignment="Center" Margin="10" Foreground="White"/>
|
||||
<TextBlock Text="Status: Connected" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,10,0" Foreground="Green"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SafeBagDE70.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AdminSettingsUC.xaml
|
||||
/// </summary>
|
||||
public partial class AdminMainUC : UserControl
|
||||
{
|
||||
public AdminMainUC()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LogoutButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void UserManagementButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void DashboardButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void SettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ReportsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="SafeBagDE70.Admin.AdminSettingsUC"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SafeBagDE70.Admin"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SafeBagDE70.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AdminSettingsUC.xaml
|
||||
/// </summary>
|
||||
public partial class AdminSettingsUC : UserControl
|
||||
{
|
||||
public AdminSettingsUC()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<hc:Window x:Class="SafeBagDE70.Admin.AdminWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SafeBagDE70.Admin"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
mc:Ignorable="d"
|
||||
ShowInTaskbar="False"
|
||||
ShowNonClientArea="False"
|
||||
Title="AdminWindow" Height="1024" Width="1280">
|
||||
<Grid>
|
||||
<!-- Define Rows and Columns -->
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="50"/>
|
||||
<!-- Top Bar -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- Main Content Area -->
|
||||
<RowDefinition Height="50"/>
|
||||
<!-- Footer -->
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<!-- Sidebar -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- Main Content Area -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Top Bar -->
|
||||
<StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal" Background="LightGray" Height="50">
|
||||
<TextBlock Text="Admin Panel" VerticalAlignment="Center" Margin="10" Foreground="White" FontSize="20"/>
|
||||
<Button Content="Log Out"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,10,0"
|
||||
Click="LogoutButton_Click"
|
||||
Background="Red"
|
||||
Foreground="White" Width="100"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Background="LightGray" VerticalAlignment="Top">
|
||||
<Button
|
||||
Content="Sự kiện"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="DashboardButton_Click"/>
|
||||
<Button
|
||||
Content="Quản lý vận hành"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="UserManagementButton_Click"/>
|
||||
<Button
|
||||
Content="Thiết lập"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="SettingsButton_Click"/>
|
||||
<Button
|
||||
Content="Cấu hình"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Padding="10"
|
||||
Click="ConfigurationButton_Click"/>
|
||||
<Button
|
||||
Content="Tắt app"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Padding="10"
|
||||
Click="btnShutdownApp_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Main Content Area -->
|
||||
<ContentControl Grid.Row="1" Grid.Column="1" x:Name="MainContentControl" Margin="10"/>
|
||||
|
||||
<!-- Footer -->
|
||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal" Background="LightGray">
|
||||
<TextBlock Text="Admin Panel" VerticalAlignment="Center" Margin="10" Foreground="White" FontSize="14"/>
|
||||
<TextBlock x:Name="lblStatus" Text="{Binding CDMStatus}" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,10,0" Foreground="Red" FontSize="14"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</hc:Window>
|
||||
@@ -0,0 +1,79 @@
|
||||
using HandyControl.Tools.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SafeBagDE70.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AdminWindow.xaml
|
||||
/// </summary>
|
||||
public partial class AdminWindow : HandyControl.Controls.Window
|
||||
{
|
||||
LogViewerUC loguc;
|
||||
AdminConfigurationUC configuration;
|
||||
public AdminWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
loguc= new LogViewerUC();
|
||||
configuration = new AdminConfigurationUC();
|
||||
this.MainContentControl.Content = loguc;
|
||||
this.Loaded += AdminWindow_Loaded;
|
||||
}
|
||||
|
||||
private void AdminWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
lblStatus.DataContext = AppData.CDMSTATE;
|
||||
}
|
||||
|
||||
private void LogoutButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void UserManagementButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void DashboardButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.MainContentControl.Content = loguc;
|
||||
}
|
||||
|
||||
private void SettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ReportsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ConfigurationButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.MainContentControl.Content = configuration;
|
||||
}
|
||||
|
||||
private void btnShutdownApp_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var bResult = MessageBox.Show("LƯU Ý, THAO TÁC NÀY SẼ LÀM MẤT TẤT CẢ DỮ LIỆU ĐANG THAO TÁC. " +
|
||||
"CHỈ THỰC HIỆN KHI KHÔNG CÓ NGƯỜI DÙNG ĐANG THAO TÁC TRÊN MÁY","CẢNH BÁO",MessageBoxButton.OKCancel);
|
||||
if (bResult == MessageBoxResult.OK)
|
||||
{
|
||||
System.Windows.Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<UserControl x:Class="SafeBagDE70.Admin.LogViewerUC"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SafeBagDE70.Admin"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<StackPanel>
|
||||
<TextBlock Text="Realtime Logs" FontSize="20" Margin="10"/>
|
||||
<ListView x:Name="LogListView" Height="500" Margin="10"/>
|
||||
<Button Content="Log Information" Width="200" Margin="10" Click="LogInfoButton_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,71 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SafeBagDE70.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LogViewerUC.xaml
|
||||
/// </summary>
|
||||
public partial class LogViewerUC : UserControl
|
||||
{
|
||||
private ObservableCollection<string> _logItems = new ObservableCollection<string>();
|
||||
|
||||
public LogViewerUC()
|
||||
{
|
||||
InitializeComponent();
|
||||
LogListView.ItemsSource = AppData.logCollection;
|
||||
AppData.logListView = LogListView;
|
||||
}
|
||||
|
||||
private void LogInfoButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Log.Information("This is an informational log message");
|
||||
}
|
||||
}
|
||||
public class RealTimeLogSink : ILogEventSink
|
||||
{
|
||||
private readonly IFormatProvider _formatProvider;
|
||||
|
||||
public RealTimeLogSink( IFormatProvider formatProvider = null)
|
||||
{
|
||||
_formatProvider = formatProvider;
|
||||
}
|
||||
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
var message = logEvent.RenderMessage(_formatProvider);
|
||||
var logLevel = logEvent.Level.ToString();
|
||||
var timestampedMessage = $"[{logEvent.Timestamp:HH:mm:ss}] [{logLevel}]{message}";
|
||||
|
||||
// Ensure the message is added on the UI thread
|
||||
App.Current.Dispatcher.Invoke(() => {
|
||||
AppData.logCollection.Add(timestampedMessage);
|
||||
if (AppData.logCollection.Count > AppData.MaxLogCount)
|
||||
{
|
||||
AppData.logCollection.RemoveAt(0); // Remove the oldest event
|
||||
}
|
||||
if (AppData.logListView != null && AppData.logListView.Items.Count > 0)
|
||||
{
|
||||
AppData.logListView.ScrollIntoView(AppData.logListView.Items[AppData.logListView.Items.Count - 1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user