diff --git a/SlnMesnac.Ioc/DependencyConfigurator.cs b/SlnMesnac.Ioc/DependencyConfigurator.cs index 6234bb9..5904b0d 100644 --- a/SlnMesnac.Ioc/DependencyConfigurator.cs +++ b/SlnMesnac.Ioc/DependencyConfigurator.cs @@ -1,5 +1,6 @@ using Autofac; using SlnMesnac.Repository; +using SlnMesnac.Serilog; using System.Reflection; using TouchSocket.Sockets; @@ -63,6 +64,9 @@ namespace SlnMesnac.Ioc //注入代码生成 RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Generate.dll")); + + //注入Serilog日志帮助类 + builder.RegisterType(typeof(SerilogHelper)).SingleInstance(); } diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj index 13b1f23..c218412 100644 --- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -37,8 +37,8 @@ + - diff --git a/SlnMesnac.WPF/ViewModel/Generate/GenerateControlViewModel.cs b/SlnMesnac.WPF/ViewModel/Generate/GenerateControlViewModel.cs index e6e18cc..9a41078 100644 --- a/SlnMesnac.WPF/ViewModel/Generate/GenerateControlViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/Generate/GenerateControlViewModel.cs @@ -1,6 +1,5 @@ -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; -using HslCommunication.LogNet; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; using Microsoft.WindowsAPICodePack.Dialogs; using SlnMesnac.Config; @@ -10,7 +9,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; -using System.IO; using System.Linq; using System.Windows; @@ -38,7 +36,7 @@ using System.Windows; #endregion << 版 本 注 释 >> namespace SlnMesnac.WPF.ViewModel.Generate { - internal class GenerateControlViewModel : ViewModelBase + internal partial class GenerateControlViewModel : ObservableObject { private readonly AppConfig _appConfig; @@ -60,55 +58,40 @@ namespace SlnMesnac.WPF.ViewModel.Generate Options.Add(configId); } - QuerySearchCommand = new RelayCommand(Query); - - CreateCodeCommand = new RelayCommand(CreateCode); } #region 参数定义 private ObservableCollection _options; public ObservableCollection Options { - get { return _options; } - set - { - _options = value; - RaisePropertyChanged(nameof(Options)); - } + get => _options; + set => SetProperty(ref _options, value); } private string _selectedOption; public string SelectedOption { - get { return _selectedOption; } - set - { - _selectedOption = value; - RaisePropertyChanged(nameof(SelectedOption)); - } + get => _selectedOption; + set => SetProperty(ref _selectedOption, value); } private ObservableCollection tablesDataGrid; public ObservableCollection TablesDataGrid { - get { return tablesDataGrid; } - set { tablesDataGrid = value; RaisePropertyChanged(() => TablesDataGrid); } + get => tablesDataGrid; + set => SetProperty(ref tablesDataGrid, value); } #endregion - #region 事件定义 - public RelayCommand QuerySearchCommand { get; set; } - - public RelayCommand CreateCodeCommand { get;set; } - #endregion /// /// 查询事件 /// /// - private void Query(string search) + [RelayCommand] + private void QuerySearch(string search) { var configId = _selectedOption; @@ -129,6 +112,7 @@ namespace SlnMesnac.WPF.ViewModel.Generate } + [RelayCommand] private void CreateCode(string tableName) { var info = tableName; diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index c6f6a2b..e2207a7 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -1,7 +1,7 @@ -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; + +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using SlnMesnac.Serilog; using SlnMesnac.WPF.Page.Generate; using System; @@ -9,7 +9,7 @@ using System.Windows; namespace SlnMesnac.WPF.ViewModel { - public class MainWindowViewModel: ViewModelBase + public partial class MainWindowViewModel: ObservableObject { public readonly SerilogHelper _logger; @@ -23,8 +23,8 @@ namespace SlnMesnac.WPF.ViewModel private int _PlcStatus = 0; public int PlcStatus { - get { return _PlcStatus; } - set { _PlcStatus = value; RaisePropertyChanged(nameof(PlcStatus)); } + get => _PlcStatus; + set => SetProperty(ref _PlcStatus, value); } /// /// 箱壳扫码器状态 @@ -32,8 +32,8 @@ namespace SlnMesnac.WPF.ViewModel private int _ShellScannerStatus = 0; public int ShellScannerStatus { - get { return _ShellScannerStatus; } - set { _ShellScannerStatus = value; RaisePropertyChanged(nameof(ShellScannerStatus)); } + get => _ShellScannerStatus; + set => SetProperty(ref _ShellScannerStatus, value); } /// @@ -42,39 +42,25 @@ namespace SlnMesnac.WPF.ViewModel private int _BoldScannerStatus = 0; public int BoldScannerStatus { - get { return _BoldScannerStatus; } - set { _BoldScannerStatus = value; RaisePropertyChanged(nameof(BoldScannerStatus)); } + get => _BoldScannerStatus; + set => SetProperty(ref _BoldScannerStatus, value); } public System.Windows.Controls.UserControl _content; public System.Windows.Controls.UserControl UserContent { - get { return _content; } - - set - { - _content = value; - RaisePropertyChanged(nameof(UserContent)); - } + get => _content; + set => SetProperty(ref _content, value); } #endregion #region 事件定义 - /// - /// 界面跳转按钮事件 - /// - public RelayCommand ControlOnClickCommand { get; set; } - /// /// 打开系统键盘 /// public RelayCommand OpenSystemKeyboardCommand { get; set; } - /// - /// 窗体控制 - /// - public RelayCommand FormControlCommand { get; set; } #endregion public MainWindowViewModel() @@ -82,8 +68,6 @@ namespace SlnMesnac.WPF.ViewModel _logger = App.ServiceProvider.GetService(); - ControlOnClickCommand = new RelayCommand(obj => ControlOnClick(obj)); - FormControlCommand = new RelayCommand(x => FormControl(x)); } @@ -91,6 +75,7 @@ namespace SlnMesnac.WPF.ViewModel /// 窗体控制 /// /// + [RelayCommand] private void FormControl(object obj) { try @@ -137,6 +122,7 @@ namespace SlnMesnac.WPF.ViewModel /// /// 界面跳转 /// + [RelayCommand] private void ControlOnClick(object obj) { try