fix: handle login window shutdown

master
tayttt 3 days ago
parent cfc1638d85
commit 6d5a72b849

@ -28,19 +28,54 @@ namespace Txgy.EWS.Client.Common.Helpers
//添加Visual //添加Visual
public void AddVisual(Visual visual) public void AddVisual(Visual visual)
{ {
visuals.Add(visual); InvokeOnDispatcher(() =>
{
Application.Current.Dispatcher.Invoke(() => base.AddVisualChild(visual)); if (visual == null)
Application.Current.Dispatcher.Invoke(() => base.AddLogicalChild(visual)); {
return;
}
visuals.Add(visual);
base.AddVisualChild(visual);
base.AddLogicalChild(visual);
});
} }
//删除Visual //删除Visual
public void RemoveVisual(Visual visual) public void RemoveVisual(Visual visual)
{ {
visuals.Remove(visual); InvokeOnDispatcher(() =>
{
if (visual == null)
{
return;
}
if (!visuals.Remove(visual))
{
return;
}
base.RemoveVisualChild(visual);
base.RemoveLogicalChild(visual);
});
}
private void InvokeOnDispatcher(Action action)
{
var dispatcher = Dispatcher;
if (dispatcher == null || dispatcher.HasShutdownStarted || dispatcher.HasShutdownFinished)
{
return;
}
if (dispatcher.CheckAccess())
{
action();
return;
}
Application.Current.Dispatcher.Invoke(()=>base.RemoveVisualChild(visual)); dispatcher.Invoke(action);
Application.Current.Dispatcher.Invoke(() => base.RemoveLogicalChild(visual));
} }
//命中测试 //命中测试

@ -611,7 +611,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
//InitEventList(); //InitEventList();
this._ea.GetEvent<UpdateEventFrequencyEvent>().Subscribe(u => this._ea.GetEvent<UpdateEventFrequencyEvent>().Subscribe(u =>
{ {
Application.Current.Dispatcher.Invoke(new System.Action(() => InvokeOnDispatcher(() =>
{ {
ListEventFre.Add(new ObservableValue(u)); ListEventFre.Add(new ObservableValue(u));
EventFrequencyCount = u; EventFrequencyCount = u;
@ -621,12 +621,12 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
} }
EventFreLabels.Add(DateTime.Now.ToString("HH:mm")); EventFreLabels.Add(DateTime.Now.ToString("HH:mm"));
EventFreMaxY = (int)(ListEventFre.Max(le => le.Value) + 4); EventFreMaxY = (int)(ListEventFre.Max(le => le.Value) + 4);
})); });
}); });
//最后预警事件 //最后预警事件
this._ea.GetEvent<UpdateLastAlarmEvent>().Subscribe(u => this._ea.GetEvent<UpdateLastAlarmEvent>().Subscribe(u =>
{ {
Application.Current.Dispatcher.Invoke(new System.Action(() => InvokeOnDispatcher(() =>
{ {
LastAlarmEventEnergy = u.Energy; LastAlarmEventEnergy = u.Energy;
ListEnergy.Add(new ObservableValue(u.Energy)); ListEnergy.Add(new ObservableValue(u.Energy));
@ -639,7 +639,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
//int domainFreq = rnd.Next(15, 60); //int domainFreq = rnd.Next(15, 60);
//LastAlarmEventDominFreq = domainFreq; //LastAlarmEventDominFreq = domainFreq;
//ListDominantFreq.Add(new ObservableValue(domainFreq)); //ListDominantFreq.Add(new ObservableValue(domainFreq));
})); });
}); });
//事件主频 //事件主频
this._ea.GetEvent<UpdateEventDominFreqMessage>().Subscribe(u => this._ea.GetEvent<UpdateEventDominFreqMessage>().Subscribe(u =>
@ -664,7 +664,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
//从接收事件列表中删除超过指定时间范围的数据 //从接收事件列表中删除超过指定时间范围的数据
var timeoutReceivedEvents = ReceviedEvents.Where(re => var timeoutReceivedEvents = ReceviedEvents.Where(re =>
(DateTime.Now - DateTime.Parse(re.EventTime)).TotalHours >= GlobalConfig.DataLookbackHours).ToArray(); (DateTime.Now - DateTime.Parse(re.EventTime)).TotalHours >= GlobalConfig.DataLookbackHours).ToArray();
_dispatcher.Invoke(new System.Action(() => InvokeOnDispatcher(() =>
{ {
if (timeoutReceivedEvents.Length > 0) if (timeoutReceivedEvents.Length > 0)
{ {
@ -674,12 +674,12 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
ReceviedEvents.Remove(dg); ReceviedEvents.Remove(dg);
} }
} }
})); });
} }
_dispatcher.Invoke(new System.Action(() => InvokeOnDispatcher(() =>
{ {
ReceviedEvents.Insert(0, gier); ReceviedEvents.Insert(0, gier);
})); });
//ReceivedEvents = new ObservableCollection<GridItemEventResult>(); //ReceivedEvents = new ObservableCollection<GridItemEventResult>();
//AlarmEvents = new ObservableCollection<GridItemEventResult>(); //AlarmEvents = new ObservableCollection<GridItemEventResult>();
@ -692,7 +692,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
{ {
var timeoutAlarmEvents = AlarmEvents.Where(re => var timeoutAlarmEvents = AlarmEvents.Where(re =>
(DateTime.Now - DateTime.Parse(re.EventTime)).TotalHours >= GlobalConfig.DataLookbackHours).ToArray(); (DateTime.Now - DateTime.Parse(re.EventTime)).TotalHours >= GlobalConfig.DataLookbackHours).ToArray();
_dispatcher.Invoke(new System.Action(() => InvokeOnDispatcher(() =>
{ {
if (timeoutAlarmEvents.Length > 0) if (timeoutAlarmEvents.Length > 0)
{ {
@ -702,18 +702,34 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
AlarmEvents.Remove(dg); AlarmEvents.Remove(dg);
} }
} }
})); });
} }
_dispatcher.Invoke(new System.Action(() => InvokeOnDispatcher(() =>
{ {
AlarmEvents.Insert(0, gier); AlarmEvents.Insert(0, gier);
})); });
//ReceivedEvents = new ObservableCollection<GridItemEventResult>(); //ReceivedEvents = new ObservableCollection<GridItemEventResult>();
//AlarmEvents = new ObservableCollection<GridItemEventResult>(); //AlarmEvents = new ObservableCollection<GridItemEventResult>();
}); });
} }
private void InvokeOnDispatcher(System.Action action)
{
if (action == null || _dispatcher == null || _dispatcher.HasShutdownStarted || _dispatcher.HasShutdownFinished)
{
return;
}
if (_dispatcher.CheckAccess())
{
action();
return;
}
_dispatcher.Invoke(action);
}
private void ClearWarningData() private void ClearWarningData()
{ {
AlarmEvents.Clear(); AlarmEvents.Clear();

@ -32,6 +32,8 @@ namespace Txgy.EWS.Client.Start
/// </summary> /// </summary>
public partial class App : PrismApplication public partial class App : PrismApplication
{ {
private bool _loginSucceeded;
public App() public App()
{ {
// 日志Log4Net初始化 // 日志Log4Net初始化
@ -62,13 +64,25 @@ namespace Txgy.EWS.Client.Start
{ {
var config = BusinessConfigManager.Current; var config = BusinessConfigManager.Current;
GlobalConfig.InitializeRuntimeSettings(config.Runtime); GlobalConfig.InitializeRuntimeSettings(config.Runtime);
GlobalConfig.ReadConfig();
//Debug.WriteLine(GlobalConfig.LoadDataTimeLenMins); //Debug.WriteLine(GlobalConfig.LoadDataTimeLenMins);
//Debug.WriteLine(GlobalConfig.DataCacheTimeLenMins); //Debug.WriteLine(GlobalConfig.DataCacheTimeLenMins);
_loginSucceeded = Container.Resolve<LoginView>().ShowDialog() == true;
if (!_loginSucceeded)
{
Shutdown();
return null;
}
return Container.Resolve<MainWindow>(); return Container.Resolve<MainWindow>();
} }
protected override void InitializeShell(Window shell) protected override void InitializeShell(Window shell)
{ {
GlobalConfig.ReadConfig(); if (!_loginSucceeded || shell == null)
{
return;
}
//if (GlobalData.IsDesign) //if (GlobalData.IsDesign)
//{ //{
// base.InitializeShell(shell); // base.InitializeShell(shell);
@ -76,17 +90,8 @@ namespace Txgy.EWS.Client.Start
//else //else
{ {
//GlobalConfig.ReadConfig(); //GlobalConfig.ReadConfig();
// 通信容器来获取对象 可以进行相关对象的注入 //CommonLogHelper.Debug("====Start=====>");
if (Container.Resolve<LoginView>().ShowDialog() == false) base.InitializeShell(shell);
{
//GlobalConfig.ReadConfig();
Application.Current?.Shutdown();
}
else
{
//CommonLogHelper.Debug("====Start=====>");
base.InitializeShell(shell);
}
} }
} }
protected override void RegisterTypes(IContainerRegistry containerRegistry) protected override void RegisterTypes(IContainerRegistry containerRegistry)

@ -45,7 +45,7 @@ namespace Txgy.EWS.Client.Start.Views
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
this.Close(); this.DialogResult = false;
} }
} }
} }

Loading…
Cancel
Save