Commit e3bab2c1 by liulongfei

1. 添加LabelValue 控件

2. 添加应用程序停止消息
parent 74205d8b
......@@ -9,6 +9,7 @@
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/NavigationControl/NavigationControl.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/NumberBox/NumberBox.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/ColorPickButton/ColorPickButton.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/LabelValue/LabelValue.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
......@@ -138,6 +138,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Widgets\LabelValue\LabelValue.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Widgets\NavigationControl\NavigationControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......@@ -229,6 +233,7 @@
<Compile Include="Widgets\ColorPickButton\ColorPickButton.cs" />
<Compile Include="Widgets\DebugBorder\DebugBorder.cs" />
<Compile Include="Widgets\DragWindowBar\DragWindowBar.cs" />
<Compile Include="Widgets\LabelValue\LabelValue.cs" />
<Compile Include="Widgets\NavigationControl\NavigationConfig.cs" />
<Compile Include="Widgets\NavigationControl\NavigationControl.cs" />
<Compile Include="Widgets\NavigationControl\NavigationItemControl.cs" />
......
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 VIZ.Framework.Common
{
/// <summary>
/// 标签和值
/// </summary>
public class LabelValue : Control
{
static LabelValue()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(LabelValue), new FrameworkPropertyMetadata(typeof(LabelValue)));
}
#region LabelWidth -- 标签宽度
/// <summary>
/// 标签宽度
/// </summary>
public double LabelWidth
{
get { return (double)GetValue(LabelWidthProperty); }
set { SetValue(LabelWidthProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for LabelWidth. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty LabelWidthProperty =
DependencyProperty.Register("LabelWidth", typeof(double), typeof(LabelValue), new PropertyMetadata(120d));
#endregion
#region Label -- 标签
/// <summary>
/// 标签
/// </summary>
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for Label. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty LabelProperty =
DependencyProperty.Register("Label", typeof(string), typeof(LabelValue), new PropertyMetadata(null));
#endregion
#region Text -- 文本
/// <summary>
/// 文本
/// </summary>
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(LabelValue), new PropertyMetadata(null));
#endregion
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VIZ.Framework.Common">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/VIZ.Framework.Common.Resource;component/Style/TextBox/TextBox_None.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="local:LabelValue">
<Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LabelValue">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Foreground="#aa000000"
Text="{TemplateBinding Label}" Width="{TemplateBinding LabelWidth}"></TextBlock>
<TextBox Grid.Column="1" AcceptsReturn="False" IsReadOnly="True" TextWrapping="NoWrap"
Text="{TemplateBinding Text}" VerticalContentAlignment="Center" Style="{StaticResource TextBox_None}"></TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
\ No newline at end of file
......@@ -20,5 +20,10 @@ namespace VIZ.Framework.Connection
/// TCP连接
/// </summary>
public static TcpConnection TcpConnection { get; set; }
/// <summary>
/// 串口连接
/// </summary>
public static SerialPortConnection SerialPortConnection { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 位长特性
/// </summary>
public class ConnBitLengthAttribute : Attribute
{
/// <summary>
/// 位长特性
/// </summary>
/// <param name="length">位长</param>
public ConnBitLengthAttribute(int length)
{
this.Length = length;
}
/// <summary>
/// 位长度
/// 1 Byte = 8bit
/// 1
/// </summary>
public int Length { get; set; }
}
}
......@@ -35,5 +35,10 @@ namespace VIZ.Framework.Connection
/// 串口名称
/// </summary>
public string PortName { get; internal set; }
/// <summary>
/// 处理器
/// </summary>
public IConnPackageProvider Provider { get; internal set; }
}
}
......@@ -17,14 +17,64 @@ namespace VIZ.Framework.Connection
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(SerialPortConnection));
/// <summary>
/// 终结点管理器集合
/// </summary>
private Dictionary<string, SerialPortEndpointManager> endpointManagers = new Dictionary<string, SerialPortEndpointManager>();
/// <summary>
/// 获取TCP终结点管理器
/// </summary>
/// <param name="key">终结点管理器键</param>
/// <returns>终结点管理器</returns>
public SerialPortEndpointManager GetEndpointManager(string key)
{
this.endpointManagers.TryGetValue(key, out SerialPortEndpointManager manager);
return manager;
}
/// <summary>
/// 添加TCP终结点管理器
/// </summary>
/// <param name="manager">终结点管理器</param>
public void AddEndpointManager(SerialPortEndpointManager manager)
{
manager.SerialPortConnection = this;
lock (this.endpointManagers)
{
this.endpointManagers.Add(manager.Key, manager);
}
}
/// <summary>
/// 移除UDP终结点管理器
/// </summary>
/// <param name="key">终结点管理器键</param>
public void RemoveEndpointManager(string key)
{
lock (this.endpointManagers)
{
if (this.endpointManagers.ContainsKey(key))
{
this.endpointManagers.Remove(key);
}
}
}
/// <summary>
/// 销毁
/// </summary>
public void Dispose()
{
lock (this.endpointManagers)
{
foreach (SerialPortEndpointManager manager in this.endpointManagers.Values)
{
manager.Dispose();
}
this.endpointManagers.Clear();
}
}
}
}
......@@ -11,7 +11,7 @@ namespace VIZ.Framework.Connection
/// <summary>
/// 串口终结点管理器
/// </summary>
public class SerialPortEndpointManager
public class SerialPortEndpointManager : IDisposable
{
/// <summary>
/// 日志
......@@ -55,6 +55,11 @@ namespace VIZ.Framework.Connection
public IConnPackageProvider PackageProvider { get; set; }
/// <summary>
/// 串口连接
/// </summary>
public SerialPortConnection SerialPortConnection { get; internal set; }
/// <summary>
/// 打开串口
/// </summary>
public void Open()
......@@ -72,6 +77,16 @@ namespace VIZ.Framework.Connection
}
/// <summary>
/// 销毁
/// </summary>
public void Dispose()
{
this.SerialPort?.Close();
this.SerialPort?.Dispose();
this.SerialPort = null;
}
/// <summary>
/// 接收数据触发
/// </summary>
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
......
......@@ -77,9 +77,10 @@ namespace VIZ.Framework.Connection
msg.RemotePort = package.RemotePort;
msg.LocalIP = package.LocalIP;
msg.LocalPort = package.LocalPort;
msg.PortName = package.PortName;
msg.Provider = this;
msg.Command = commands[i];
try
{
ApplicationDomain.MessageManager.Send(msg);
......
......@@ -86,6 +86,8 @@ namespace VIZ.Framework.Connection
msg.LocalPort = package.LocalPort;
msg.RemoteIP = package.RemoteIP;
msg.RemotePort = package.RemotePort;
msg.PortName = package.PortName;
msg.Provider = this;
msg.Buffer = this.buffer_cache;
try
......
......@@ -55,6 +55,8 @@ namespace VIZ.Framework.Connection
msg.LocalPort = package.LocalPort;
msg.RemoteIP = package.RemoteIP;
msg.RemotePort = package.RemotePort;
msg.PortName = package.PortName;
msg.Provider = this;
msg.Json = json;
try
......
......@@ -68,6 +68,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConnectionManager.cs" />
<Compile Include="Core\ConnBitLengthAttribute.cs" />
<Compile Include="Core\ConnInfoBase.cs" />
<Compile Include="Core\ConnMessageBase.cs" />
<Compile Include="Core\ConnPackageInfo.cs" />
......
......@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using log4net;
using VIZ.Framework.Domain;
namespace VIZ.Framework.Module
{
......@@ -138,6 +139,17 @@ namespace VIZ.Framework.Module
if (!IsSetup)
return;
try
{
// 发送应用程序关闭消息
AppShutDownMessage msg = new AppShutDownMessage();
ApplicationDomain.MessageManager.Send(msg);
}
catch (Exception ex)
{
log.Error(ex);
}
Stopwatch stopwatch = Stopwatch.StartNew();
AppSetupContext context = new AppSetupContext();
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Module
{
/// <summary>
/// 应用程序关闭消息
/// </summary>
public class AppShutDownMessage
{
}
}
......@@ -97,6 +97,7 @@
<Compile Include="Setup\AppSetupBase.cs" />
<Compile Include="Setup\AppSetupContext.cs" />
<Compile Include="Setup\IAppSetup.cs" />
<Compile Include="Setup\Message\AppShutDownMessage.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_CatchUnhandledException.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_Navigation3D.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_Loop.cs" />
......
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