You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
5.9 KiB
263 lines
5.9 KiB
using EC.UsingEventAggregator;
|
|
using EC.Utils;
|
|
using ECMonitor.Code.SysemNotifyIcon;
|
|
using Prism.Events;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
|
|
//using System.Drawing;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
|
|
namespace ECMonitor
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private IRegionManager _regionManager;
|
|
private IEventAggregator _ea;
|
|
|
|
public MainWindow(IRegionManager regionManager, IEventAggregator ea)
|
|
{
|
|
_regionManager = regionManager;
|
|
_ea = ea;
|
|
this.ResizeMode = ResizeMode.CanMinimize;
|
|
|
|
InitializeComponent();
|
|
|
|
//var paletteHelper = new PaletteHelper();
|
|
//var theme = paletteHelper.GetTheme();
|
|
//theme.SetBaseTheme(Theme.Dark);
|
|
//paletteHelper.SetTheme(theme);
|
|
|
|
//系统托盘
|
|
SystemTrayParameter pars = new SystemTrayParameter("zgx.ico", "守护中", "", 0, notifyIcon_MouseDoubleClick);
|
|
this.notifyIcon = WPFSystemTray.SetSystemTray(pars, GetList());
|
|
|
|
_ea.GetEvent<ShowMessageSentEvent>().Subscribe(MessageReceived);
|
|
FLogger.SubLog += SubShowMessage;
|
|
FLogger.SubLog += SaveLog;
|
|
}
|
|
|
|
#region PageEvent
|
|
|
|
/// <summary>
|
|
/// 引发窗口关闭前响应,可阻止系统关闭
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
{
|
|
if (!EXIT_APP)
|
|
{
|
|
e.Cancel = true;
|
|
this.ShowInTaskbar = false;
|
|
HideWindow();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 窗口关闭前响应,不可阻止系统关闭
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
protected override void OnClosed(EventArgs e)
|
|
{
|
|
base.OnClosed(e);
|
|
//关闭系统托盘
|
|
notifyIcon.Dispose();
|
|
}
|
|
|
|
#endregion PageEvent
|
|
|
|
#region 系统托盘
|
|
|
|
private bool EXIT_APP = false;
|
|
private System.Windows.Forms.NotifyIcon notifyIcon;
|
|
|
|
//托盘右键菜单集合
|
|
private List<SystemTrayMenu> GetList()
|
|
{
|
|
List<SystemTrayMenu> ls = new List<SystemTrayMenu>();
|
|
ls.Add(new SystemTrayMenu() { Txt = "打开主面板", Icon = "", Click = mainWin_Click });
|
|
ls.Add(new SystemTrayMenu() { Txt = "退出", Icon = "/img/exit.png", Click = Exit_Click });
|
|
return ls;
|
|
}
|
|
|
|
//双击事件
|
|
private void notifyIcon_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
|
|
{
|
|
ShowWindow();
|
|
}
|
|
|
|
#region 托盘右键菜单
|
|
|
|
//打开主面板
|
|
private void mainWin_Click(object sender, EventArgs e)
|
|
{
|
|
ShowWindow();
|
|
}
|
|
|
|
//退出
|
|
private void Exit_Click(object sender, EventArgs e)
|
|
{
|
|
EXIT_APP = true;
|
|
|
|
this.Close();
|
|
//System.Windows.Forms.Application.ExitThread();
|
|
Environment.Exit(0);
|
|
// System.Windows.Application.Current.Shutdown();
|
|
}
|
|
|
|
public void ShowWindow()
|
|
{
|
|
this.Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
if (this.WindowState == WindowState.Minimized)
|
|
{
|
|
this.WindowState = WindowState.Normal;
|
|
}
|
|
this.ShowInTaskbar = true;
|
|
this.Show();
|
|
this.Activate();
|
|
}));
|
|
}
|
|
|
|
private void HideWindow()
|
|
{
|
|
//this.WindowState = WindowState.Minimized;
|
|
|
|
this.Hide();
|
|
this.notifyIcon.ShowBalloonTip(3000, "", "程序在后台运行中,双击图标打开", System.Windows.Forms.ToolTipIcon.None); //弹出气泡提示
|
|
}
|
|
|
|
#endregion 托盘右键菜单
|
|
|
|
#endregion 系统托盘
|
|
|
|
#region 系统按钮
|
|
|
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
// Exit_Click(sender, e);
|
|
}
|
|
|
|
private void SetFormSize()
|
|
{
|
|
double x1 = SystemParameters.PrimaryScreenWidth;//得到屏幕整体宽度
|
|
double y1 = SystemParameters.PrimaryScreenHeight;//得到屏幕整体高度
|
|
double xy = x1 + y1;
|
|
x1 = x1 * 0.9;
|
|
y1 = y1 * 0.9;
|
|
this.Width = x1;
|
|
this.Height = y1;
|
|
}
|
|
|
|
private void btnMax_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (this.WindowState == WindowState.Maximized)
|
|
{
|
|
this.WindowState = WindowState.Normal;
|
|
}
|
|
else
|
|
{
|
|
this.WindowState = WindowState.Maximized;
|
|
}
|
|
}
|
|
|
|
private void btnMin_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.WindowState = WindowState.Minimized;
|
|
}
|
|
|
|
private void DockPanel_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.LeftButton == MouseButtonState.Pressed)
|
|
{
|
|
this.DragMove();
|
|
}
|
|
}
|
|
|
|
#endregion 系统按钮
|
|
|
|
#region top 按钮颜色
|
|
|
|
private SolidColorBrush barkgroudcolor = new SolidColorBrush(Color.FromRgb(0x4c, 0x8b, 0xb7));
|
|
|
|
private void btnVodieo_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
btnVodieo.Background = barkgroudcolor;
|
|
btnSet.Background = Brushes.Transparent;
|
|
}
|
|
|
|
private void btnSet_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
btnVodieo.Background = Brushes.Transparent;
|
|
btnSet.Background = barkgroudcolor;
|
|
}
|
|
|
|
#endregion top 按钮颜色
|
|
|
|
#region 统一底部 弹窗提示
|
|
|
|
public void MessageReceived(LogModel log)
|
|
{
|
|
MainSnackbar.MessageQueue?.Enqueue(log.message);
|
|
}
|
|
|
|
//public async Task<object> MessageTips(string message)
|
|
//{
|
|
// var sampleMessageDialog = new SampleMessageDialog
|
|
// {
|
|
// Message = { Text = message }
|
|
// };
|
|
// return await DialogHost.Show(sampleMessageDialog, "RootDialog");
|
|
//}
|
|
|
|
#endregion 统一底部 弹窗提示
|
|
|
|
#region 公共 基础函数
|
|
|
|
private int linenumber = 0;
|
|
|
|
private void SubShowMessage(MyLogger log)
|
|
{
|
|
if (log.Level >= (LoggerLevel)0)
|
|
{
|
|
linenumber++;
|
|
this.Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
if (linenumber > 500)
|
|
{
|
|
//richText.Document.Blocks.Clear();
|
|
}
|
|
// richText.AppendText(log.Message + '\n');
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void SaveLog(MyLogger log)
|
|
{
|
|
switch (log.Level)
|
|
{
|
|
case LoggerLevel.Debug:
|
|
LogFactory.GetLogger().Debug(log.Message);
|
|
break;
|
|
|
|
case LoggerLevel.Info:
|
|
LogFactory.GetLogger().Info(log.Message);
|
|
break;
|
|
|
|
case LoggerLevel.Error:
|
|
LogFactory.GetLogger().Error(log.Message);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion 公共 基础函数
|
|
}
|
|
}
|