Commit 43f5a9e5 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 中午12点自动重启客户端。临时解决客户端占内存2G问题

parent a3159a6a
......@@ -14,7 +14,7 @@
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="30" />
<Setter Property="FontFamily" Value="Microsoft Sans Serif" />
<Setter Property="FontFamily" Value="{StaticResource FontFamily.Field}" />
<Setter Property="TextAlignment" Value="Right" />
</Style>
......
<UserControl x:Class="FLY.Thick.Base.UI.CustomSection.UcSectionReboot"
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:FLY.Thick.Base.UI.CustomSection"
mc:Ignorable="d" >
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Converter/Converters.xaml"/>
</ResourceDictionary.MergedDictionaries>
<local:UcSectionRebootVm x:Key="viewModel"/>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Orientation="Horizontal" >
<Border Style="{StaticResource Styles.ParamSection.Border}">
<TextBlock Text="{StaticResource str.PgCustomSections.Reboot}" />
</Border>
<StackPanel d:DataContext="{StaticResource viewModel}">
<StackPanel Orientation="Horizontal">
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable.Row2}" Text="{StaticResource str.PgCustomSections.AutoRebootAt12}" />
<ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" HorizontalAlignment="Left" IsChecked="{Binding IsAutoReboot}" />
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="{StaticResource str.PgCustomSections.BootTime}" />
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="{Binding BootTimeMin}" />
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="{StaticResource str.PgCustomSections.Min}"/>
</StackPanel>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable.Row2}" Text="测试:立即重启" />
<ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" HorizontalAlignment="Left" IsChecked="{Binding IsReBootAtOnce}" />
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</UserControl>
using CommunityToolkit.Mvvm.Input;
using FLY.AppHelper;
using FLY.Thick.Base.UI.OnInit;
using Misc;
using MultiLayout.UiModule;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Unity;
namespace FLY.Thick.Base.UI.CustomSection
{
/// <summary>
/// UcSectionOsk.xaml 的交互逻辑
/// </summary>
public partial class UcSectionReboot : UserControl
{
UcSectionRebootVm viewModel;
public UcSectionReboot()
{
InitializeComponent();
}
[InjectionMethod]
public void Init(ParamDictionary paramDictionary,[Dependency("reboot")]IOnInit onInitReboot)
{
viewModel = new UcSectionRebootVm();
viewModel.Init(paramDictionary, (OnInitReboot)onInitReboot);
this.DataContext = viewModel;
}
}
public class UcSectionRebootVm : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// 自动重启电脑
/// </summary>
public bool IsAutoReboot { get; set; }
/// <summary>
/// 开机时间
/// </summary>
public int BootTimeMin { get; set; }
public bool IsReBootAtOnce { get; set; }
ParamDictionary paramDictionary;
OnInitReboot onInitReboot;
public UcSectionRebootVm()
{
}
public void Init(ParamDictionary paramDictionary, OnInitReboot onInitReboot)
{
this.paramDictionary = paramDictionary;
this.onInitReboot = onInitReboot;
IsAutoReboot = paramDictionary.GetValue(ParamDistItemKeys.AutoReboot, false);
BootTimeMin = onInitReboot.BootTimeMin;
IsReBootAtOnce = onInitReboot.IsReBootAtOnce;
this.PropertyChanged += UcSectionRebootVm_PropertyChanged;
onInitReboot.PropertyChanged += OnInitReboot_PropertyChanged;
}
private void OnInitReboot_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(onInitReboot.BootTimeMin))
{
BootTimeMin = onInitReboot.BootTimeMin;
}
}
private void UcSectionRebootVm_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(IsAutoReboot))
{
paramDictionary.SetValue(ParamDistItemKeys.AutoReboot, IsAutoReboot);
}
else if (e.PropertyName == nameof(IsReBootAtOnce)) {
onInitReboot.IsReBootAtOnce = IsReBootAtOnce;
}
}
}
}
......@@ -102,6 +102,9 @@
<Compile Include="CustomMenu\UpdateMenu.cs" />
<Compile Include="CustomMenu\WarningMenu.cs" />
<Compile Include="CustomMenu\PwMenu.cs" />
<Compile Include="CustomSection\UcSectionReboot.xaml.cs">
<DependentUpon>UcSectionReboot.xaml</DependentUpon>
</Compile>
<Compile Include="CustomSection\UcSectionLanguage.xaml.cs">
<DependentUpon>UcSectionLanguage.xaml</DependentUpon>
</Compile>
......@@ -124,6 +127,7 @@
<Compile Include="IErrNoTranslator.cs" />
<Compile Include="OnInit\OnInitAutoScan.cs" />
<Compile Include="OnInit\OnInitControllerState.cs" />
<Compile Include="OnInit\OnInitReboot.cs" />
<Compile Include="OnInit\OnInitWarnings.cs" />
<Compile Include="OnInit\OnInitError.cs" />
<Compile Include="OnInit\OnInitOSK.cs" />
......@@ -249,6 +253,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="CustomSection\UcSectionReboot.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="CustomSection\UcSectionLanguage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......
using MultiLayout.UiModule;
using Misc;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Unity;
using System.ComponentModel;
using FObjBase;
namespace FLY.Thick.Base.UI.OnInit
{
/// <summary>
/// 虚拟键盘
/// </summary>
public class OnInitReboot : IOnInit,INotifyPropertyChanged
{
ParamDictionary paramDictionary;
public OnInitReboot(ParamDictionary paramDictionary,int lv=1)
{
this.paramDictionary = paramDictionary;
Level = lv;
}
public int Level { get; }
/// <summary>
/// 自动重启电脑
/// </summary>
public bool IsAutoReboot { get; protected set; }
/// <summary>
/// 开机时间
/// </summary>
public int BootTimeMin { get; protected set; }
public bool IsReBootAtOnce { get; set; }
bool isRebooting = false;
public event PropertyChangedEventHandler PropertyChanged;
public void OnInit()
{
IsAutoReboot = paramDictionary.GetValue(ParamDistItemKeys.AutoReboot, false);
paramDictionary.ValueChanged += ParamDictionary_ValueChanged;
PollModule.Current.Poll_Config(OnPoll, TimeSpan.FromMinutes(1));
}
private void ParamDictionary_ValueChanged(object sender, ParamDictionaryValueChangedEventArgs e)
{
if (e.Key == ParamDistItemKeys.AutoReboot)
{
IsAutoReboot = paramDictionary.GetValue(ParamDistItemKeys.AutoReboot, false);
}
}
/// <summary>
/// 1min 调用一次
/// </summary>
void OnPoll()
{
BootTimeMin++;
if (IsAutoReboot)
{
if (IsReBootAtOnce && BootTimeMin > 1)
{
reboot();
}
else if (BootTimeMin > 60 * 12)
{
//12小时后, 到了中午12点,重启软件
if (DateTime.Now.Hour == 12)
{
reboot();
}
}
}
}
void reboot()
{
if (!isRebooting)
{
isRebooting = true;
//重启软件
FLY.AppHelper.AppJustOne.Restart();
}
}
}
}
......@@ -16,5 +16,6 @@ namespace FLY.Thick.Base.UI
public const string WindowSize = "WindowSize";
public const string SkipWarningUnityNames = "SkipWarningUnityNames";
public const string XStep = "XStep";
public const string AutoReboot = "AutoReboot";
}
}
......@@ -6,7 +6,7 @@
<!--字符串换行 换行符 &#10; -->
<system:String x:Key="str.PgCustomSections.Title">客户端设置</system:String>
<system:String x:Key="str.PgCustomSections.AutoChangedPage" xml:space="preserve">自动&#13;页面切换</system:String>
<system:String x:Key="str.PgCustomSections.AutoChangedPage" xml:space="preserve">自动&#10;页面切换</system:String>
<system:String x:Key="str.PgCustomSections.State" >状态</system:String>
<system:String x:Key="str.PgCustomSections.Page" >页面</system:String>
<system:String x:Key="str.PgCustomSections.AlarmTip" >报警提示</system:String>
......@@ -18,7 +18,7 @@
<system:String x:Key="str.PgCustomSections.OSK" >虚拟键盘</system:String>
<system:String x:Key="str.PgCustomSections.SupportMouse" >支持鼠标</system:String>
<system:String x:Key="str.PgCustomSections.ScanGraph" xml:space="preserve" >图表&#13;总体设置</system:String>
<system:String x:Key="str.PgCustomSections.ScanGraph" xml:space="preserve" >图表&#10;总体设置</system:String>
<system:String x:Key="str.PgCustomSections.XStep" >X轴间隔</system:String>
<system:String x:Key="str.PgCustomSections.SelectMusicFile" >打开音乐文件</system:String>
......@@ -26,4 +26,9 @@
<system:String x:Key="str.PgCustomSections.Language">语言</system:String>
<system:String x:Key="str.PgCustomSections.Apply">应用</system:String>
<system:String x:Key="str.PgCustomSections.Reboot" xml:space="preserve">自动&#10;重启</system:String>
<system:String x:Key="str.PgCustomSections.AutoRebootAt12" xml:space="preserve">中午12点自动&#10;重启客户端</system:String>
<system:String x:Key="str.PgCustomSections.BootTime">启动时间</system:String>
<system:String x:Key="str.PgCustomSections.Min">分钟</system:String>
</ResourceDictionary>
\ No newline at end of file
......@@ -6,7 +6,7 @@
<!--字符串换行 换行符 &#10; -->
<system:String x:Key="str.PgCustomSections.Title">Client App Setting</system:String>
<system:String x:Key="str.PgCustomSections.AutoChangedPage" xml:space="preserve">Auto &#13;Page</system:String>
<system:String x:Key="str.PgCustomSections.AutoChangedPage" xml:space="preserve">Auto&#10;Page</system:String>
<system:String x:Key="str.PgCustomSections.State" >State</system:String>
<system:String x:Key="str.PgCustomSections.Page" >Page</system:String>
<system:String x:Key="str.PgCustomSections.AlarmTip" >Alarm Tip</system:String>
......@@ -25,4 +25,9 @@
<system:String x:Key="str.PgCustomSections.Language">Language</system:String>
<system:String x:Key="str.PgCustomSections.Apply">Apply</system:String>
<system:String x:Key="str.PgCustomSections.Reboot" xml:space="preserve">Auto&#10;Reboot</system:String>
<system:String x:Key="str.PgCustomSections.AutoRebootAt12" xml:space="preserve">The App reboots&#10;automatically at PM 12:00 </system:String>
<system:String x:Key="str.PgCustomSections.BootTime">Boot Time</system:String>
<system:String x:Key="str.PgCustomSections.Min">Mins</system:String>
</ResourceDictionary>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment