添加 MX-PD-盘古 项目文件
将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
using MainShell.Log;
|
||||
using MwFramework.AlarmManager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace MainShell.Alarm
|
||||
{
|
||||
public class AlarmOperate : IAlarmSend, IAlarmResponse<string>
|
||||
{
|
||||
private const string AlarmSourceName = "AlarmOperate";
|
||||
|
||||
private readonly IAlarmManager _alarmManager;
|
||||
|
||||
public AlarmOperate(IAlarmManager alarmManager)
|
||||
{
|
||||
_alarmManager = alarmManager ?? throw new ArgumentNullException(nameof(alarmManager));
|
||||
_alarmManager.CloseBuzzer += () =>
|
||||
{
|
||||
LogManager.LogAlarmEvent(AlarmSourceName, "CloseBuzzer");
|
||||
};
|
||||
_alarmManager.RestBuzzer += () =>
|
||||
{
|
||||
|
||||
};
|
||||
_alarmManager.ClearPLCAlarm += () =>
|
||||
{
|
||||
List<long> unresolvedAlarmIds = _alarmManager.UnresolvedAlarms == null
|
||||
? new List<long>()
|
||||
: _alarmManager.UnresolvedAlarms.Distinct().ToList();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
foreach (long alarmId in unresolvedAlarmIds)
|
||||
{
|
||||
_alarmManager.HandleAlarmSolved(alarmId);
|
||||
}
|
||||
|
||||
LogManager.LogAlarmEvent(
|
||||
AlarmSourceName,
|
||||
string.Format("ClearPLCAlarm resolved {0} alarms", unresolvedAlarmIds.Count));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.LogAlarmError(AlarmSourceName, "ClearPLCAlarm", ex);
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public string Code { private get; set; }
|
||||
|
||||
public void Alert(int alarmID)
|
||||
{
|
||||
Task alertTask = AlertAsync(alarmID);
|
||||
|
||||
if (Application.Current != null &&
|
||||
Application.Current.Dispatcher != null &&
|
||||
Application.Current.Dispatcher.CheckAccess())
|
||||
{
|
||||
alertTask.ContinueWith(task =>
|
||||
{
|
||||
AggregateException ignored = task.Exception;
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
return;
|
||||
}
|
||||
|
||||
alertTask.GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public void Alert(int alarmID, string source, string action, string detail = null)
|
||||
{
|
||||
Task alertTask = AlertAsync(alarmID, source, action, detail);
|
||||
|
||||
if (Application.Current != null &&
|
||||
Application.Current.Dispatcher != null &&
|
||||
Application.Current.Dispatcher.CheckAccess())
|
||||
{
|
||||
alertTask.ContinueWith(task =>
|
||||
{
|
||||
AggregateException ignored = task.Exception;
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
return;
|
||||
}
|
||||
|
||||
alertTask.GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task AlertAsync(int alarmID)
|
||||
{
|
||||
await AlertInternalAsync(alarmID, AlarmSourceName, "AlertAsync requested").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task AlertAsync(int alarmID, string source, string action, string detail = null)
|
||||
{
|
||||
string alarmSource = string.IsNullOrWhiteSpace(source) ? AlarmSourceName : source;
|
||||
string triggerAction = BuildTriggerAction(action, detail);
|
||||
|
||||
await AlertInternalAsync(alarmID, alarmSource, triggerAction).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task AlertInternalAsync(int alarmID, string source, string action)
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.LogAlarmEvent(source, action, alarmID);
|
||||
await _alarmManager.HandleAlarmAsync(alarmID, this, this).ConfigureAwait(false);
|
||||
LogManager.LogAlarmEvent(source, "HandleAlarmAsync completed", alarmID);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.LogAlarmError(source, "HandleAlarmAsync", ex, alarmID);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildTriggerAction(string action, string detail)
|
||||
{
|
||||
string normalizedAction = string.IsNullOrWhiteSpace(action) ? "AlertAsync requested" : action;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(detail))
|
||||
{
|
||||
return normalizedAction;
|
||||
}
|
||||
|
||||
return string.Format("{0}. Detail={1}", normalizedAction, detail);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using MainShell.Alarm.ViewModel;
|
||||
using MwFramework.AlarmManager;
|
||||
using Stylet;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MainShell.Alarm
|
||||
{
|
||||
[AlarmID(begin:10000, end:20011)]
|
||||
public class UserAlarmProduce : AbstractAlarmAsyncProcedure
|
||||
{
|
||||
private readonly IAlarmManager _alarmManager;
|
||||
private readonly IWindowManager _windowManager;
|
||||
|
||||
public UserAlarmProduce(IAlarmManager alarmManager, IWindowManager windowManager)
|
||||
{
|
||||
_alarmManager = alarmManager;
|
||||
_windowManager = windowManager;
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(IAlarmSend inContext = null, IAlarmResponse outContext = null)
|
||||
{
|
||||
var dialogViewModel = new AlarmDialogViewModel
|
||||
{
|
||||
AlarmInfo = AlarmInfo
|
||||
};
|
||||
var resetRequested = false;
|
||||
await Execute.OnUIThreadAsync(() =>
|
||||
{
|
||||
resetRequested = _windowManager.ShowDialog(dialogViewModel) == true;
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
if (resetRequested)
|
||||
{
|
||||
_alarmManager.ClearPLCAlarm?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<Window x:Class="MainShell.Alarm.View.AlarmDialogView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:MainShell.Alarm.View"
|
||||
mc:Ignorable="d"
|
||||
SizeToContent="Height"
|
||||
ResizeMode="CanResizeWithGrip"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
Title="报警提示 (Alarm)" Width="650" MinWidth="500" MaxHeight="800">
|
||||
<Window.Resources>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource LeftGroupStyle}"/>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 顶部横幅 -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 内容区域 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 按钮区域 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 顶部横幅区域 -->
|
||||
<Border Grid.Row="0" Background="#FFF5E5" BorderBrush="#FFCC80" BorderThickness="0,0,0,1" Padding="15,10">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="⚠" Foreground="#E65100" FontSize="22" FontWeight="Bold" Margin="0,0,10,0" VerticalAlignment="Center"/>
|
||||
<TextBlock Text="系统发生报警,请及时处理" Foreground="#D84315" FontSize="16" FontWeight="Bold" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 内容区域 -->
|
||||
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" Margin="15,10,15,15">
|
||||
<StackPanel>
|
||||
<!-- 报警ID和类型 -->
|
||||
<GroupBox Header="基本信息" Margin="0,0,0,10">
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="10"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="报警 ID:" Style="{StaticResource LabelStyle}" Grid.Row="0" Grid.Column="0" VerticalAlignment="Top"/>
|
||||
<TextBlock Text="{Binding AlarmInfo.AlarmID}" Style="{StaticResource ValueStyle}" FontWeight="Bold" Grid.Row="0" Grid.Column="1" TextWrapping="Wrap"/>
|
||||
|
||||
<TextBlock Text="报警类型:" Style="{StaticResource LabelStyle}" Grid.Row="2" Grid.Column="0" VerticalAlignment="Top"/>
|
||||
<TextBlock Text="{Binding AlarmInfo.AlarmType}" Style="{StaticResource ValueStyle}" Foreground="#D84315" FontWeight="SemiBold" Grid.Row="2" Grid.Column="1" TextWrapping="Wrap"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 报警消息 -->
|
||||
<GroupBox Header="报警消息" Margin="0,0,0,10">
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="10"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="中文消息:" Style="{StaticResource LabelStyle}" Grid.Row="0" Grid.Column="0" VerticalAlignment="Top"/>
|
||||
<TextBlock Text="{Binding AlarmInfo.AlarmMessage}" Style="{StaticResource ValueStyle}" Grid.Row="0" Grid.Column="1" TextWrapping="Wrap" LineHeight="20"/>
|
||||
|
||||
<TextBlock Text="英文消息:" Style="{StaticResource LabelStyle}" Grid.Row="2" Grid.Column="0" VerticalAlignment="Top"/>
|
||||
<TextBlock Text="{Binding AlarmInfo.AlarmMessageEN}" Style="{StaticResource ValueStyle}" Grid.Row="2" Grid.Column="1" TextWrapping="Wrap" Foreground="#555555" LineHeight="20"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 报警原因 -->
|
||||
<GroupBox Header="报警原因" Margin="0,0,0,10">
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="原因描述:" Style="{StaticResource LabelStyle}" Grid.Row="0" Grid.Column="0" VerticalAlignment="Top"/>
|
||||
<TextBlock Text="{Binding AlarmInfo.AlarmReason}" Style="{StaticResource ValueStyle}" Grid.Row="0" Grid.Column="1" TextWrapping="Wrap" LineHeight="20"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 解决方案 -->
|
||||
<GroupBox Header="解决方案" Margin="0,0,0,10">
|
||||
<Border Background="#F9FBE7" BorderBrush="#CDDC39" BorderThickness="1" CornerRadius="4" Padding="10">
|
||||
<TextBlock Text="{Binding AlarmInfo.AlarmSolution}" Style="{StaticResource ValueStyle}" TextWrapping="Wrap" Foreground="#33691E" LineHeight="20"/>
|
||||
</Border>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 触发时间 -->
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,5,0">
|
||||
<TextBlock Text="触发时间:" Style="{StaticResource LabelStyle}" Foreground="#888888" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding AlarmInfo.TriggerTime, StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}" Style="{StaticResource ValueStyle}" Foreground="#888888" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- 底部按钮区域 -->
|
||||
<Border Grid.Row="2" BorderBrush="#E0E0E0" BorderThickness="0,1,0,0" Padding="10,8" Background="#F8F8F8">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Content="复位报警" Style="{StaticResource CloseButtonStyle}" Width="100" Height="32" Margin="0,0,10,0" Command="{Binding ResetCommand}" Cursor="Hand"/>
|
||||
<Button Content="关闭" Style="{StaticResource CloseButtonStyle}" Width="100" Height="32" Command="{Binding CloseCommand}" Cursor="Hand"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace MainShell.Alarm.View
|
||||
{
|
||||
/// <summary>
|
||||
/// AlarmDialog.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class AlarmDialogView : Window
|
||||
{
|
||||
public AlarmDialogView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using MainShell.Models;
|
||||
using MaxwellFramework.Core.Common.Command;
|
||||
using MwFramework.AlarmManager;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace MainShell.Alarm.ViewModel
|
||||
{
|
||||
public class AlarmDialogViewModel : BaseScreen
|
||||
{
|
||||
public ICommand ResetCommand { get; }
|
||||
public ICommand CloseCommand { get; }
|
||||
|
||||
public AlarmDialogViewModel()
|
||||
{
|
||||
DisplayName = "报警详情";
|
||||
ResetCommand = new DelegateCommand(obj => Reset());
|
||||
CloseCommand = new DelegateCommand(obj => Close());
|
||||
}
|
||||
|
||||
private AlarmInfo _alarmInfo;
|
||||
public AlarmInfo AlarmInfo
|
||||
{
|
||||
get => _alarmInfo;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _alarmInfo, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void Close()
|
||||
{
|
||||
RequestClose(false);
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
RequestClose(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user