init
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
using DTS.Common.Base;
|
||||
namespace DTS.Common.Interface
|
||||
{
|
||||
public interface INavigationView : IBaseView { }
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
//https://stackoverflow.com/questions/35324285/how-to-create-masked-textbox-like-windows-ip-address-fields
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
|
||||
namespace DTS.Common.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for IPTextBox.xaml
|
||||
/// </summary>
|
||||
public partial class IPTextBox : UserControl
|
||||
{
|
||||
private static readonly List<Key> DigitKeys = new List<Key> { Key.D0, Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8, Key.D9,
|
||||
//FB 43400 added NumPad 0-9 to the valid digit keys beside the main keyboard 0-9
|
||||
Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3, Key.NumPad4, Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9 };
|
||||
private static readonly List<Key> MoveForwardKeys = new List<Key> { Key.Right };
|
||||
private static readonly List<Key> MoveBackwardKeys = new List<Key> { Key.Left };
|
||||
private static readonly List<Key> OtherAllowedKeys = new List<Key> { Key.Tab, Key.Delete };
|
||||
|
||||
private readonly List<TextBox> _segments = new List<TextBox>();
|
||||
|
||||
private bool _suppressAddressUpdate = false;
|
||||
|
||||
public IPTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
_segments.Add(FirstSegment);
|
||||
_segments.Add(SecondSegment);
|
||||
_segments.Add(ThirdSegment);
|
||||
_segments.Add(LastSegment);
|
||||
}
|
||||
|
||||
//FB 43400 added Clear method to reset the segments
|
||||
public void Clear()
|
||||
{
|
||||
FirstSegment.Text = string.Empty;
|
||||
SecondSegment.Text = string.Empty;
|
||||
ThirdSegment.Text = string.Empty;
|
||||
LastSegment.Text = string.Empty;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AddressProperty = DependencyProperty.Register(
|
||||
"Address", typeof(string), typeof(IPTextBox), new FrameworkPropertyMetadata(default(string), AddressChanged)
|
||||
{
|
||||
BindsTwoWayByDefault = true
|
||||
});
|
||||
|
||||
private static void AddressChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ipTextBox = dependencyObject as IPTextBox;
|
||||
var text = e.NewValue as string;
|
||||
|
||||
if (text != null && ipTextBox != null)
|
||||
{
|
||||
ipTextBox._suppressAddressUpdate = true;
|
||||
var i = 0;
|
||||
foreach (var segment in text.Split('.'))
|
||||
{
|
||||
ipTextBox._segments[i].Text = segment;
|
||||
i++;
|
||||
}
|
||||
ipTextBox._suppressAddressUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
public string Address
|
||||
{
|
||||
get { return (string)GetValue(AddressProperty); }
|
||||
set { SetValue(AddressProperty, value); }
|
||||
}
|
||||
|
||||
private void UIElement_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (DigitKeys.Contains(e.Key))
|
||||
{
|
||||
e.Handled = ShouldCancelDigitKeyPress();
|
||||
HandleDigitPress();
|
||||
}
|
||||
else if (MoveBackwardKeys.Contains(e.Key))
|
||||
{
|
||||
e.Handled = ShouldCancelBackwardKeyPress();
|
||||
HandleBackwardKeyPress();
|
||||
}
|
||||
else if (MoveForwardKeys.Contains(e.Key))
|
||||
{
|
||||
e.Handled = ShouldCancelForwardKeyPress();
|
||||
HandleForwardKeyPress();
|
||||
}
|
||||
else if (e.Key == Key.Back)
|
||||
{
|
||||
HandleBackspaceKeyPress();
|
||||
}
|
||||
//FB 43400 added Decimal beside OemPeriod to valid keys
|
||||
else if (e.Key == Key.OemPeriod || e.Key == Key.Decimal)
|
||||
{
|
||||
e.Handled = true;
|
||||
HandlePeriodKeyPress();
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Handled = !AreOtherAllowedKeysPressed(e);
|
||||
}
|
||||
}
|
||||
|
||||
private bool AreOtherAllowedKeysPressed(KeyEventArgs e)
|
||||
{
|
||||
return e.Key == Key.C && ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0) ||
|
||||
e.Key == Key.V && ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0) ||
|
||||
e.Key == Key.A && ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0) ||
|
||||
e.Key == Key.X && ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0) ||
|
||||
OtherAllowedKeys.Contains(e.Key);
|
||||
}
|
||||
|
||||
private void HandleDigitPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
|
||||
if (currentTextBox != null && currentTextBox.Text.Length == 3 &&
|
||||
currentTextBox.CaretIndex == 3 && currentTextBox.SelectedText.Length == 0)
|
||||
{
|
||||
MoveFocusToNextSegment(currentTextBox);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldCancelDigitKeyPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
return currentTextBox != null &&
|
||||
currentTextBox.Text.Length == 3 &&
|
||||
currentTextBox.CaretIndex == 3 &&
|
||||
currentTextBox.SelectedText.Length == 0;
|
||||
}
|
||||
|
||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (!_suppressAddressUpdate)
|
||||
{
|
||||
Address = string.Format("{0}.{1}.{2}.{3}", FirstSegment.Text, SecondSegment.Text, ThirdSegment.Text, LastSegment.Text);
|
||||
}
|
||||
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
|
||||
if (currentTextBox != null && currentTextBox.Text.Length == 3 && currentTextBox.CaretIndex == 3)
|
||||
{
|
||||
MoveFocusToNextSegment(currentTextBox);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldCancelBackwardKeyPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
return currentTextBox != null && currentTextBox.CaretIndex == 0;
|
||||
}
|
||||
|
||||
private void HandleBackspaceKeyPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
|
||||
if (currentTextBox != null && currentTextBox.CaretIndex == 0 && currentTextBox.SelectedText.Length == 0)
|
||||
{
|
||||
MoveFocusToPreviousSegment(currentTextBox);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleBackwardKeyPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
|
||||
if (currentTextBox != null && currentTextBox.CaretIndex == 0)
|
||||
{
|
||||
MoveFocusToPreviousSegment(currentTextBox);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldCancelForwardKeyPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
return currentTextBox != null && currentTextBox.CaretIndex == 3;
|
||||
}
|
||||
|
||||
private void HandleForwardKeyPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
|
||||
if (currentTextBox != null && currentTextBox.CaretIndex == currentTextBox.Text.Length)
|
||||
{
|
||||
MoveFocusToNextSegment(currentTextBox);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePeriodKeyPress()
|
||||
{
|
||||
var currentTextBox = FocusManager.GetFocusedElement(this) as TextBox;
|
||||
|
||||
if (currentTextBox != null && currentTextBox.Text.Length > 0 && currentTextBox.CaretIndex == currentTextBox.Text.Length)
|
||||
{
|
||||
MoveFocusToNextSegment(currentTextBox);
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveFocusToPreviousSegment(TextBox currentTextBox)
|
||||
{
|
||||
if (!ReferenceEquals(currentTextBox, FirstSegment))
|
||||
{
|
||||
var previousSegmentIndex = _segments.FindIndex(box => ReferenceEquals(box, currentTextBox)) - 1;
|
||||
currentTextBox.SelectionLength = 0;
|
||||
currentTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
|
||||
_segments[previousSegmentIndex].CaretIndex = _segments[previousSegmentIndex].Text.Length;
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveFocusToNextSegment(TextBox currentTextBox)
|
||||
{
|
||||
if (!ReferenceEquals(currentTextBox, LastSegment))
|
||||
{
|
||||
currentTextBox.SelectionLength = 0;
|
||||
currentTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
|
||||
}
|
||||
}
|
||||
|
||||
private void DataObject_OnPasting(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
|
||||
if (!isText)
|
||||
{
|
||||
e.CancelCommand();
|
||||
return;
|
||||
}
|
||||
|
||||
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
|
||||
|
||||
int num;
|
||||
|
||||
if (!int.TryParse(text, out num))
|
||||
{
|
||||
e.CancelCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using DTS.Common.Base;
|
||||
// ReSharper disable CheckNamespace
|
||||
namespace DTS.Common.Interface
|
||||
{
|
||||
public interface ITestSummaryListView : IBaseView { }
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<UserControl x:Class="DTS.Common.Controls.CommonStatusRibbon"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignHeight="80" d:DesignWidth="1366" x:Name="commonStatusRibbon">
|
||||
<Grid>
|
||||
<Grid HorizontalAlignment="Stretch" Visibility="Visible" DataContext="{Binding ElementName=commonStatusRibbon}">
|
||||
<Grid.Background>
|
||||
<SolidColorBrush Color="{Binding AggregateStatusColor, FallbackValue=Yellow}" />
|
||||
</Grid.Background>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Column="0">
|
||||
<Rectangle Fill="{DynamicResource Brush_StatusRibbonErrorBackgroundDark}" Visibility="{Binding AlertVisibility, FallbackValue=Hidden}" />
|
||||
<Grid Background="{DynamicResource Brush_StatusRibbonErrorBackgroundLight}" Visibility="{Binding AlertVisibility, FallbackValue=Visible}">
|
||||
<Grid.Style>
|
||||
<Style TargetType="{x:Type Grid}">
|
||||
<Style.Resources>
|
||||
<Storyboard x:Key="flashAnimation" >
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.2" To="1" AutoReverse="True" Duration="0:0:0.3" RepeatBehavior="Forever" />
|
||||
</Storyboard>
|
||||
</Style.Resources>
|
||||
<Style.Triggers>
|
||||
<EventTrigger RoutedEvent="Window.Loaded">
|
||||
<BeginStoryboard Name="flash" Storyboard="{StaticResource flashAnimation}" />
|
||||
</EventTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Grid.Style>
|
||||
</Grid>
|
||||
<TextBlock FontFamily="Segoe UI" FontSize="11"
|
||||
Foreground="{Binding TextColor}" Text="{Binding AggregateStatusText, FallbackValue=Connecting}" Margin="0" Width="200"/>
|
||||
</Grid>
|
||||
|
||||
<ProgressBar Grid.Column="1" Margin="0" HorizontalContentAlignment="Stretch" Visibility="{Binding ProgressBarVisibility}" Value="{Binding ProgressBarValue,FallbackValue=30}"/>
|
||||
</Grid>
|
||||
<Grid MinHeight="80" HorizontalAlignment="Stretch" Visibility="Collapsed" DataContext="{Binding ElementName=commonStatusRibbon}">
|
||||
<Grid.Background>
|
||||
<SolidColorBrush Color="{Binding AggregateStatusColor, FallbackValue=Yellow}" />
|
||||
</Grid.Background>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle
|
||||
Fill="{DynamicResource Brush_StatusRibbonErrorBackgroundDark}"
|
||||
Grid.Row="0" Grid.RowSpan="2"
|
||||
Visibility="{Binding AlertVisibility, FallbackValue=Hidden}"
|
||||
/>
|
||||
<Grid
|
||||
Background="{DynamicResource Brush_StatusRibbonErrorBackgroundLight}"
|
||||
Grid.Row="0" Grid.RowSpan="2"
|
||||
Visibility="{Binding AlertVisibility, FallbackValue=Visible}">
|
||||
<Grid.Style>
|
||||
<Style TargetType="{x:Type Grid}">
|
||||
<Style.Resources>
|
||||
<Storyboard x:Key="flashAnimation" >
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.2" To="1" AutoReverse="True" Duration="0:0:0.3" RepeatBehavior="Forever" />
|
||||
</Storyboard>
|
||||
</Style.Resources>
|
||||
<Style.Triggers>
|
||||
<EventTrigger RoutedEvent="Window.Loaded">
|
||||
<BeginStoryboard Name="flash" Storyboard="{StaticResource flashAnimation}" />
|
||||
</EventTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Grid.Style>
|
||||
</Grid>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{Binding TextColor}"
|
||||
Text="{Binding AggregateStatusText, FallbackValue=Connecting}"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0"
|
||||
x:Name="lblAggregateStatusText"
|
||||
/>
|
||||
<ProgressBar
|
||||
Margin="0"
|
||||
Grid.Row="1"
|
||||
Height="40"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Visibility="{Binding ProgressBarVisibility}"
|
||||
Value="{Binding ProgressBarValue,FallbackValue=30}"
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace DTS.Common.Utils
|
||||
{
|
||||
// Converts integral types to bytes but wraps the conversions so that
|
||||
// outgoing they are converted to network order and incoming they are
|
||||
// converted to host order.
|
||||
public class ByteConvertor
|
||||
{
|
||||
public static void Convert(byte[] input, int offset, out byte value)
|
||||
{
|
||||
// Nothing to do for single bytes
|
||||
value = input[offset];
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out ushort value)
|
||||
{
|
||||
value = (ushort)(0 |
|
||||
input[offset + 0] << 8 |
|
||||
input[offset + 1] << 0);
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out short value)
|
||||
{
|
||||
value = (short)(0 |
|
||||
input[offset + 0] << 8 |
|
||||
input[offset + 1] << 0);
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out uint value)
|
||||
{
|
||||
value = 0 |
|
||||
(uint)input[offset + 0] << 24 |
|
||||
(uint)input[offset + 1] << 16 |
|
||||
(uint)input[offset + 2] << 8 |
|
||||
(uint)input[offset + 3] << 0;
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out int value)
|
||||
{
|
||||
value =
|
||||
input[offset + 0] << 24 |
|
||||
input[offset + 1] << 16 |
|
||||
input[offset + 2] << 8 |
|
||||
input[offset + 3] << 0;
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out ulong value)
|
||||
{
|
||||
value = 0 |
|
||||
(ulong)input[offset + 0] << 56 |
|
||||
(ulong)input[offset + 1] << 48 |
|
||||
(ulong)input[offset + 2] << 40 |
|
||||
(ulong)input[offset + 3] << 32 |
|
||||
(ulong)input[offset + 4] << 24 |
|
||||
(ulong)input[offset + 5] << 16 |
|
||||
(ulong)input[offset + 6] << 8 |
|
||||
(ulong)input[offset + 7] << 0;
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out long value)
|
||||
{
|
||||
value = 0 |
|
||||
(long)input[offset + 0] << 56 |
|
||||
(long)input[offset + 1] << 48 |
|
||||
(long)input[offset + 2] << 40 |
|
||||
(long)input[offset + 3] << 32 |
|
||||
(long)input[offset + 4] << 24 |
|
||||
(long)input[offset + 5] << 16 |
|
||||
(long)input[offset + 6] << 8 |
|
||||
(long)input[offset + 7] << 0;
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out float value)
|
||||
{
|
||||
value = BitConverter.ToSingle(input, offset);
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out double value)
|
||||
{
|
||||
value = BitConverter.ToDouble(input, offset);
|
||||
}
|
||||
|
||||
public static void Convert(byte[] input, int offset, out string value)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
for (var i = offset; i < input.Length && input[i] != 0; i++)
|
||||
{
|
||||
sb.Append((char)input[i]);
|
||||
}
|
||||
value = sb.ToString();
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(string input)
|
||||
{
|
||||
var c = input.ToCharArray();
|
||||
var rv = new byte[c.Length + 1];
|
||||
for (var i = 0; i < c.Length; i++) rv[i] = (byte)c[i];
|
||||
rv[c.Length] = 0;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(byte input)
|
||||
{
|
||||
var rv = new byte[1];
|
||||
rv[0] = input;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(ushort input)
|
||||
{
|
||||
var rv = new byte[2];
|
||||
rv[0] = (byte)((input >> 8) & 0xFF);
|
||||
rv[1] = (byte)((input >> 0) & 0xFF);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(short input)
|
||||
{
|
||||
var rv = new byte[2];
|
||||
rv[0] = (byte)((input >> 8) & 0xFF);
|
||||
rv[1] = (byte)((input >> 0) & 0xFF);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(uint input)
|
||||
{
|
||||
var rv = new byte[4];
|
||||
rv[0] = (byte)((input >> 24) & 0xFF);
|
||||
rv[1] = (byte)((input >> 16) & 0xFF);
|
||||
rv[2] = (byte)((input >> 8) & 0xFF);
|
||||
rv[3] = (byte)((input >> 0) & 0xFF);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(int input)
|
||||
{
|
||||
var rv = new byte[4];
|
||||
rv[0] = (byte)((input >> 24) & 0xFF);
|
||||
rv[1] = (byte)((input >> 16) & 0xFF);
|
||||
rv[2] = (byte)((input >> 8) & 0xFF);
|
||||
rv[3] = (byte)((input >> 0) & 0xFF);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(ulong input)
|
||||
{
|
||||
var rv = new byte[8];
|
||||
rv[0] = (byte)((input >> 56) & 0xFF);
|
||||
rv[1] = (byte)((input >> 48) & 0xFF);
|
||||
rv[2] = (byte)((input >> 40) & 0xFF);
|
||||
rv[3] = (byte)((input >> 32) & 0xFF);
|
||||
rv[4] = (byte)((input >> 24) & 0xFF);
|
||||
rv[5] = (byte)((input >> 16) & 0xFF);
|
||||
rv[6] = (byte)((input >> 8) & 0xFF);
|
||||
rv[7] = (byte)((input >> 0) & 0xFF);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(float input)
|
||||
{
|
||||
return BitConverter.GetBytes(input);
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(double input)
|
||||
{
|
||||
return BitConverter.GetBytes(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user