Pārlūkot izejas kodu

Merge branch 'Master_TIN02_develop' of http://git.jetplasma-oa.com/Jet/Minics into Master_TIN02_develop

Zixuan 4 nedēļas atpakaļ
vecāks
revīzija
79c4f008a3

+ 1 - 3
Tools/AlarmInfoServerSim/App.xaml.cs

@@ -16,10 +16,8 @@ namespace AlarmInfoServerSim
         {
             //Services
             containerRegistry.RegisterSingleton<ISharedConfig, SharedConfig>();
-            containerRegistry.RegisterSingleton<ISendInfoSevice, SendInfoSevice>();
+            containerRegistry.RegisterSingleton<ISendInfoService, SendInfoService>();
 
-            //Views
-            containerRegistry.Register<StatusBar>();
         }
     }
 

+ 3 - 2
Tools/AlarmInfoServerSim/Services/ISendInfoSevice.cs

@@ -2,10 +2,11 @@
 
 namespace AlarmInfoServerSim.Services
 {
-    public interface ISendInfoSevice
+    public interface ISendInfoService
     {
-        bool HasConnection { get; }
         bool Open();
         bool Send(byte tag, ST_ALARM alarm);
+
+        event EventHandler<bool>? ConnectionChanged;
     }
 }

+ 36 - 3
Tools/AlarmInfoServerSim/Services/SendInfoSevice.cs

@@ -9,14 +9,15 @@ using UniversalNetFrame451.IO;
 
 namespace AlarmInfoServerSim.Services
 {
-    public class SendInfoSevice : ISendInfoSevice, ITlvProvider
+    public class SendInfoService : ISendInfoService, ITlvProvider, IDisposable
     {
         private readonly ISharedConfig _sharedConfig;
         private readonly ITlvCommunicatorServer _server;
 
         private bool _isConnected = false;
+        private bool disposedValue;
 
-        public SendInfoSevice(ISharedConfig sharedConfig) 
+        public SendInfoService(ISharedConfig sharedConfig) 
         {
             _sharedConfig= sharedConfig;
 
@@ -24,7 +25,7 @@ namespace AlarmInfoServerSim.Services
             _server.Initialize(this);
         }
 
-        public bool HasConnection => _isConnected;
+        public event EventHandler<bool>? ConnectionChanged;
 
         public bool Open()
         {
@@ -47,11 +48,13 @@ namespace AlarmInfoServerSim.Services
         public void Connected(TcpConnection connection)
         {
             _isConnected = true;
+            ConnectionChanged?.Invoke(null, _isConnected);
         }
 
         public void Disconnected(TcpConnection connection)
         {
             _isConnected = false;
+            ConnectionChanged?.Invoke(null, _isConnected);
         }
 
         public void Received(TlvData data)
@@ -63,5 +66,35 @@ namespace AlarmInfoServerSim.Services
         {
             throw new NotImplementedException();
         }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                    // TODO: 释放托管状态(托管对象)
+                    _server.Dispose();
+                }
+
+                // TODO: 释放未托管的资源(未托管的对象)并重写终结器
+                // TODO: 将大型字段设置为 null
+                disposedValue = true;
+            }
+        }
+
+        // // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器
+        // ~SendInfoService()
+        // {
+        //     // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
+        //     Dispose(disposing: false);
+        // }
+
+        public void Dispose()
+        {
+            // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
+            Dispose(disposing: true);
+            GC.SuppressFinalize(this);
+        }
     }
 }

+ 5 - 2
Tools/AlarmInfoServerSim/ViewModels/MainWindowViewModel.cs

@@ -1,10 +1,13 @@
-namespace AlarmInfoServerSim.ViewModels
+using AlarmInfoServerSim.Views;
+using Prism.Ioc;
+
+namespace AlarmInfoServerSim.ViewModels
 {
     public class MainWindowViewModel
     {
         public MainWindowViewModel()
         {
-
+            
         }
     }
 }

+ 20 - 10
Tools/AlarmInfoServerSim/ViewModels/StatusBarViewModel.cs

@@ -1,26 +1,36 @@
-using CommunityToolkit.Mvvm.ComponentModel;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using AlarmInfoServerSim.Services;
+using CommunityToolkit.Mvvm.ComponentModel;
 
 namespace AlarmInfoServerSim.ViewModels
 {
     public partial class StatusBarViewModel : ObservableObject
     {
+        private readonly ISharedConfig _sharedConfig;
+        private readonly ISendInfoService _sendInfoService;
+
         [ObservableProperty]
-        private string _status = "Disconnected";
+        private string _status;
 
         [ObservableProperty]
-        private string _ipAddress = "0.0.0.0";
+        private string _ipAddress;
 
         [ObservableProperty]
-        private string _port = "0";
+        private ushort _port;
 
-        public StatusBarViewModel() 
+        public StatusBarViewModel(ISharedConfig sharedConfig, ISendInfoService sendInfoService)
         {
+            _sharedConfig = sharedConfig;
+            _status = "Unknown";
+            _ipAddress = _sharedConfig.BasicInfo?.RTServerAddress ?? "Unknown";
+            _port = _sharedConfig.BasicInfo?.RTServerPort ?? 0;
+
+            _sendInfoService = sendInfoService;
+            _sendInfoService.ConnectionChanged += OnConnectionChanged;
+        }
 
+        private void OnConnectionChanged(object? sender, bool e)
+        {
+            Status = e ? "Connected" : "Disconnected";
         }
     }
 }

+ 12 - 0
Tools/AlarmInfoServerSim/Views/LogBar.xaml

@@ -0,0 +1,12 @@
+<UserControl x:Class="AlarmInfoServerSim.Views.LogBar"
+             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:AlarmInfoServerSim.Views"
+             xmlns:prism="http://prismlibrary.com/"
+             prism:ViewModelLocator.AutoWireViewModel="True"
+             Height="200" Width="600"
+             mc:Ignorable="d">
+    <Grid Background="#FFCECECE" Margin="5,5,5,0"/>
+</UserControl>

+ 28 - 0
Tools/AlarmInfoServerSim/Views/LogBar.xaml.cs

@@ -0,0 +1,28 @@
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace AlarmInfoServerSim.Views
+{
+    /// <summary>
+    /// LogBar.xaml 的交互逻辑
+    /// </summary>
+    public partial class LogBar : UserControl
+    {
+        public LogBar()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 6 - 4
Tools/AlarmInfoServerSim/Views/MainWindow.xaml

@@ -6,14 +6,16 @@
         xmlns:local="clr-namespace:AlarmInfoServerSim.Views"
         xmlns:prism="http://prismlibrary.com/"
         prism:ViewModelLocator.AutoWireViewModel="True"
-        mc:Ignorable="d"
-        Title="MainWindow" Height="450" Width="600">
+        Title="MainWindow" Height="600" Width="600" ResizeMode="CanMinimize"
+        mc:Ignorable="d">
     <Grid>
         <Grid.RowDefinitions>
+            <RowDefinition Height="50"/>
             <RowDefinition Height="*"/>
             <RowDefinition Height="200"/>
         </Grid.RowDefinitions>
-        <local:StatusBar Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top"></local:StatusBar>
-        
+        <local:StatusBar Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+        <local:WorkArea Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+        <local:LogBar Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" />
     </Grid>
 </Window>

+ 1 - 0
Tools/AlarmInfoServerSim/Views/MainWindow.xaml.cs

@@ -1,4 +1,5 @@
 using AlarmInfoServerSim.Services;
+using Prism.Navigation.Regions;
 using System.Text;
 using System.Windows;
 using System.Windows.Controls;

+ 8 - 8
Tools/AlarmInfoServerSim/Views/StatusBar.xaml

@@ -6,25 +6,25 @@
              xmlns:local="clr-namespace:AlarmInfoServerSim.Views"
              xmlns:prism="http://prismlibrary.com/"
              prism:ViewModelLocator.AutoWireViewModel="True"
-             Width="600" Height="40" 
+             Width="600" Height="45" 
              mc:Ignorable="d">
-    <Grid Background="#FFCECECE">
+    <Grid Background="#FFCECECE" Margin="5,0,5,0">
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="*"/>
             <ColumnDefinition Width="200"/>
             <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
         <StackPanel Grid.Column="0" Orientation="Horizontal">
-            <Label>Status:</Label>
-            <TextBox Text="{Binding Status}"></TextBox>
+            <Label VerticalAlignment="Center" HorizontalAlignment="Center">Status: </Label>
+            <Label Content="{Binding Status}" HorizontalAlignment="Center" VerticalAlignment="Center"></Label>
         </StackPanel>
         <StackPanel Grid.Column="1" Orientation="Horizontal">
-            <Label>IP:</Label>
-            <TextBox Text="{Binding IpAddress}"></TextBox>
+            <Label HorizontalAlignment="Center" VerticalAlignment="Center">IP:</Label>
+            <Label Content="{Binding IpAddress}" HorizontalAlignment="Center" VerticalAlignment="Center"></Label>
         </StackPanel>
         <StackPanel Grid.Column="2" Orientation="Horizontal">
-            <Label>Port:</Label>
-            <TextBox Text="{Binding Port}"></TextBox>
+            <Label HorizontalAlignment="Center" VerticalAlignment="Center">Port:</Label>
+            <Label Content="{Binding Port}" HorizontalAlignment="Center" VerticalAlignment="Center"></Label>
         </StackPanel>
 
     </Grid>

+ 21 - 0
Tools/AlarmInfoServerSim/Views/WorkArea.xaml

@@ -0,0 +1,21 @@
+<UserControl x:Class="AlarmInfoServerSim.Views.WorkArea"
+             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:AlarmInfoServerSim.Views"
+             xmlns:prism="http://prismlibrary.com/"
+             prism:ViewModelLocator.AutoWireViewModel="True"
+             Width="600" Height="350"
+             mc:Ignorable="d">
+    <Grid Background="#FFCECECE" Margin="5,0,5,0">
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="300" />
+            <ColumnDefinition Width="*"/>
+        </Grid.ColumnDefinitions>
+        <StackPanel Grid.Column="0" Orientation="Vertical">
+            
+        </StackPanel>
+        <Button Grid.Column="1" Content="Send" Margin="70,50,70,260"/>
+    </Grid>
+</UserControl>

+ 28 - 0
Tools/AlarmInfoServerSim/Views/WorkArea.xaml.cs

@@ -0,0 +1,28 @@
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace AlarmInfoServerSim.Views
+{
+    /// <summary>
+    /// WorkArea.xaml 的交互逻辑
+    /// </summary>
+    public partial class WorkArea : UserControl
+    {
+        public WorkArea()
+        {
+            InitializeComponent();
+        }
+    }
+}