Browse Source

Update code format

SenGao 1 day ago
parent
commit
cf990519ed

+ 40 - 44
EEMSUIClient/App.xaml.cs

@@ -1,54 +1,50 @@
 using EEMSUIClient.Services;
 using EEMSUIClient.Views;
 using Hardcodet.Wpf.TaskbarNotification;
-using System.Configuration;
-using System.Data;
 using System.Windows;
 
-namespace EEMSUIClient
+namespace EEMSUIClient;
+
+/// <summary>
+/// Interaction logic for App.xaml
+/// </summary>
+public partial class App : PrismApplication
 {
-    /// <summary>
-    /// Interaction logic for App.xaml
-    /// </summary>
-    public partial class App : PrismApplication
+    protected override Window CreateShell()
+    {
+        return Container.Resolve<MainWindow>();
+    }
+
+    protected override void RegisterTypes(IContainerRegistry containerRegistry)
+    {
+        containerRegistry.RegisterSingleton<ITrayControl, TrayController>();
+    }
+
+    protected override void OnInitialized()
     {
-        protected override Window CreateShell()
-        {
-            return Container.Resolve<MainWindow>();
-        }
-
-        protected override void RegisterTypes(IContainerRegistry containerRegistry)
-        {
-            containerRegistry.RegisterSingleton<ITrayControl, TrayController>();
-        }
-
-        protected override void OnInitialized()
-        {
-            base.OnInitialized();
-
-            Container.Resolve<ITrayControl>().Tray = (TaskbarIcon)App.Current.FindResource("TrayIcon");
-            Container.Resolve<ITrayControl>().ShowBalloonTip();
-        }
-
-        private void TrayIcon_TrayMouseDoubleClick(object sender, RoutedEventArgs e)
-        {
-            Container.Resolve<ITrayControl>().ShowMainWindow();
-        }
-
-        private void ShowMenu_Click(object sender, RoutedEventArgs e)
-        {
-            Container.Resolve<ITrayControl>().ShowMainWindow();
-        }
-
-        private void ExitMenu_Click(object sender, RoutedEventArgs e)
-        {
-            Container.Resolve<ITrayControl>().Exit();
-        }
-
-        private void OnExit(object sender, ExitEventArgs e)
-        {
-            Container.Resolve<ITrayControl>().Dispose();
-        }
+        base.OnInitialized();
+
+        Container.Resolve<ITrayControl>().Tray = (TaskbarIcon)App.Current.FindResource("TrayIcon");
+        Container.Resolve<ITrayControl>().ShowBalloonTip();
     }
 
+    private void TrayIcon_TrayMouseDoubleClick(object sender, RoutedEventArgs e)
+    {
+        Container.Resolve<ITrayControl>().ShowMainWindow();
+    }
+
+    private void ShowMenu_Click(object sender, RoutedEventArgs e)
+    {
+        Container.Resolve<ITrayControl>().ShowMainWindow();
+    }
+
+    private void ExitMenu_Click(object sender, RoutedEventArgs e)
+    {
+        Container.Resolve<ITrayControl>().Exit();
+    }
+
+    private void OnExit(object sender, ExitEventArgs e)
+    {
+        Container.Resolve<ITrayControl>().Dispose();
+    }
 }

+ 9 - 15
EEMSUIClient/Services/ITrayControl.cs

@@ -1,19 +1,13 @@
 using Hardcodet.Wpf.TaskbarNotification;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
-namespace EEMSUIClient.Services
+namespace EEMSUIClient.Services;
+
+public interface ITrayControl : IDisposable
 {
-    public interface ITrayControl : IDisposable
-    {
-        TaskbarIcon? Tray { set; }
-        bool IsExiting { get; }
-        void HideToTray();
-        void ShowMainWindow();
-        void Exit();
-        void ShowBalloonTip();
-    }
+    TaskbarIcon? Tray { set; }
+    bool IsExiting { get; }
+    void HideToTray();
+    void ShowMainWindow();
+    void Exit();
+    void ShowBalloonTip();
 }

+ 65 - 66
EEMSUIClient/Services/TrayController.cs

@@ -2,92 +2,91 @@
 using Hardcodet.Wpf.TaskbarNotification;
 using System.Windows;
 
-namespace EEMSUIClient.Services
+namespace EEMSUIClient.Services;
+
+public sealed class TrayController : ITrayControl
 {
-    public sealed class TrayController : ITrayControl
-    {
-        private TaskbarIcon? _tray;
+    private TaskbarIcon? _tray;
 
-        private bool disposedValue;
+    private bool disposedValue;
 
-        public TaskbarIcon? Tray
+    public TaskbarIcon? Tray
+    {
+        set
         {
-            set
-            {
-                ObjectDisposedException.ThrowIf(disposedValue, nameof(_tray));
-                _tray = value;
-            }
+            ObjectDisposedException.ThrowIf(disposedValue, nameof(_tray));
+            _tray = value;
         }
+    }
 
-        public bool IsExiting { get; private set; }
+    public bool IsExiting { get; private set; }
 
-        public void HideToTray()
-        {
-            var mainWindow = (MainWindow)Application.Current.MainWindow;
-            mainWindow.ShowInTaskbar = false;
-            mainWindow.Hide();
-        }
+    public void HideToTray()
+    {
+        var mainWindow = (MainWindow)Application.Current.MainWindow;
+        mainWindow.ShowInTaskbar = false;
+        mainWindow.Hide();
+    }
 
-        public void ShowMainWindow()
+    public void ShowMainWindow()
+    {
+        var mainWindow = (MainWindow)Application.Current.MainWindow;
+        if (!mainWindow.IsVisible)
         {
-            var mainWindow = (MainWindow)Application.Current.MainWindow;
-            if (!mainWindow.IsVisible)
-            {
-                mainWindow.Show();
-            }
-            mainWindow.WindowState = WindowState.Normal;
-            mainWindow.ShowInTaskbar = true;
-            mainWindow.Activate();
-            mainWindow.Topmost = true;
-            mainWindow.Topmost = false;
-            mainWindow.Focus();
+            mainWindow.Show();
         }
+        mainWindow.WindowState = WindowState.Normal;
+        mainWindow.ShowInTaskbar = true;
+        mainWindow.Activate();
+        mainWindow.Topmost = true;
+        mainWindow.Topmost = false;
+        mainWindow.Focus();
+    }
 
-        public void Exit()
-        {
-            IsExiting = true;
-            Application.Current.MainWindow?.Close();
-            Application.Current.Shutdown();
-        }
+    public void Exit()
+    {
+        IsExiting = true;
+        Application.Current.MainWindow?.Close();
+        Application.Current.Shutdown();
+    }
 
-        public void ShowBalloonTip()
-        {
-            _tray?.ShowBalloonTip("EEMS Client", "服务正在后台运行...", BalloonIcon.Info);
-        }
+    public void ShowBalloonTip()
+    {
+        _tray?.ShowBalloonTip("EEMS Client", "服务正在后台运行...", BalloonIcon.Info);
+    }
 
-        private void Dispose(bool disposing)
+    private void Dispose(bool disposing)
+    {
+        if (!disposedValue)
         {
-            if (!disposedValue)
+            if (disposing)
             {
-                if (disposing)
+                // TODO: dispose managed state (managed objects)
+                if (_tray != null)
                 {
-                    // TODO: dispose managed state (managed objects)
-                    if (_tray != null)
-                    {
-                        _tray.Visibility = Visibility.Hidden;
-                        _tray.Dispose();
-                        _tray = null;
-                    }
+                    _tray.Visibility = Visibility.Hidden;
+                    _tray.Dispose();
+                    _tray = null;
                 }
-
-                // TODO: free unmanaged resources (unmanaged objects) and override finalizer
-                // TODO: set large fields to null
-                disposedValue = true;
             }
+
+            // TODO: free unmanaged resources (unmanaged objects) and override finalizer
+            // TODO: set large fields to null
+            disposedValue = true;
         }
+    }
 
-        // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
-        // ~TrayController()
-        // {
-        //     // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
-        //     Dispose(disposing: false);
-        // }
+    // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
+    // ~TrayController()
+    // {
+    //     // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+    //     Dispose(disposing: false);
+    // }
 
-        public void Dispose()
-        {
-            // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
-            Dispose(disposing: true);
-            GC.SuppressFinalize(this);
-        }
+    public void Dispose()
+    {
+        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+        Dispose(disposing: true);
+        GC.SuppressFinalize(this);
     }
 }

+ 4 - 12
EEMSUIClient/ViewModels/MainWindowViewModel.cs

@@ -1,19 +1,11 @@
 using CommunityToolkit.Mvvm.ComponentModel;
-using CommunityToolkit.Mvvm.Input;
-using EEMSUIClient.Services;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
-namespace EEMSUIClient.ViewModels
+namespace EEMSUIClient.ViewModels;
+
+public partial class MainWindowViewModel : ObservableObject
 {
-    public partial class MainWindowViewModel : ObservableObject
+    public MainWindowViewModel()
     {
-        public MainWindowViewModel()
-        {
 
-        }
     }
 }

+ 18 - 19
EEMSUIClient/Views/MainWindow.xaml.cs

@@ -1,30 +1,29 @@
 using EEMSUIClient.Services;
 using System.Windows;
 
-namespace EEMSUIClient.Views
+namespace EEMSUIClient.Views;
+
+/// <summary>
+/// Interaction logic for MainWindow.xaml
+/// </summary>
+public partial class MainWindow : Window
 {
-    /// <summary>
-    /// Interaction logic for MainWindow.xaml
-    /// </summary>
-    public partial class MainWindow : Window
-    {
-        private readonly ITrayControl _trayController;
+    private readonly ITrayControl _trayController;
 
-        public MainWindow(ITrayControl trayController)
-        {
-            InitializeComponent();
+    public MainWindow(ITrayControl trayController)
+    {
+        InitializeComponent();
 
-            _trayController = trayController;
-            this.Closing += MainWindow_Closing;
-        }
+        _trayController = trayController;
+        this.Closing += MainWindow_Closing;
+    }
 
-        private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
+    private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
+    {
+        if (!_trayController.IsExiting)
         {
-            if(!_trayController.IsExiting)
-            {
-                e.Cancel = true;
-                _trayController.HideToTray();
-            }
+            e.Cancel = true;
+            _trayController.HideToTray();
         }
     }
 }