refactor: 将Framework库和RT、UI放在同一个解决方案中。
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Sicentury.Core.AttachedProperties
|
||||
{
|
||||
public static class TextBlockHighlighter
|
||||
{
|
||||
public static string GetSelection(DependencyObject obj)
|
||||
{
|
||||
return (string)obj.GetValue(SelectionProperty);
|
||||
}
|
||||
|
||||
public static void SetSelection(DependencyObject obj, string value)
|
||||
{
|
||||
obj.SetValue(SelectionProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SelectionProperty =
|
||||
DependencyProperty.RegisterAttached("Selection", typeof(string), typeof(TextBlockHighlighter),
|
||||
new PropertyMetadata(new PropertyChangedCallback(SelectText)));
|
||||
|
||||
private static void SelectText(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d == null)
|
||||
return;
|
||||
if (!(d is TextBlock txtBlock))
|
||||
throw new InvalidOperationException("Only valid for TextBlock");
|
||||
|
||||
var text = txtBlock.Text;
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return;
|
||||
|
||||
var highlightText = (string)txtBlock.GetValue(SelectionProperty);
|
||||
if (string.IsNullOrEmpty(highlightText))
|
||||
{
|
||||
txtBlock.Inlines.Clear();
|
||||
txtBlock.Inlines.Add(text);
|
||||
return;
|
||||
}
|
||||
|
||||
var index = text.IndexOf(highlightText, StringComparison.CurrentCultureIgnoreCase);
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
var selectionColor = (Brush)txtBlock.GetValue(HighlightColorProperty);
|
||||
var foreColor = (Brush)txtBlock.GetValue(ForeColorProperty);
|
||||
|
||||
txtBlock.Inlines.Clear();
|
||||
while (true)
|
||||
{
|
||||
txtBlock.Inlines.AddRange(new Inline[]
|
||||
{
|
||||
new Run(text.Substring(0, index)),
|
||||
new Run(text.Substring(index, highlightText.Length))
|
||||
{
|
||||
Background = selectionColor,
|
||||
Foreground = foreColor
|
||||
}
|
||||
});
|
||||
|
||||
text = text.Substring(index + highlightText.Length);
|
||||
index = text.IndexOf(highlightText, StringComparison.CurrentCultureIgnoreCase);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
txtBlock.Inlines.Add(new Run(text));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Brush GetHighlightColor(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(HighlightColorProperty);
|
||||
}
|
||||
|
||||
public static void SetHighlightColor(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(HighlightColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty HighlightColorProperty =
|
||||
DependencyProperty.RegisterAttached("HighlightColor", typeof(Brush), typeof(TextBlockHighlighter),
|
||||
new PropertyMetadata(Brushes.Yellow, new PropertyChangedCallback(SelectText)));
|
||||
|
||||
|
||||
public static Brush GetForeColor(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(ForeColorProperty);
|
||||
}
|
||||
|
||||
public static void SetForeColor(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(ForeColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ForeColorProperty =
|
||||
DependencyProperty.RegisterAttached("ForeColor", typeof(Brush), typeof(TextBlockHighlighter),
|
||||
new PropertyMetadata(Brushes.Black, new PropertyChangedCallback(SelectText)));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Sicentury.Core.AttachedProperties
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Adorner for the watermark
|
||||
/// </summary>
|
||||
internal class WatermarkAdorner : Adorner
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ContentPresenter"/> that holds the watermark
|
||||
/// </summary>
|
||||
private readonly ContentPresenter _contentPresenter;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WatermarkAdorner"/> class
|
||||
/// </summary>
|
||||
/// <param name="adornedElement"><see cref="UIElement"/> to be adorned</param>
|
||||
/// <param name="watermark">The watermark</param>
|
||||
public WatermarkAdorner(UIElement adornedElement, object watermark) :
|
||||
base(adornedElement)
|
||||
{
|
||||
IsHitTestVisible = false;
|
||||
|
||||
_contentPresenter = new ContentPresenter
|
||||
{
|
||||
Content = watermark,
|
||||
Opacity = 0.3,
|
||||
Margin = new Thickness(Control.Margin.Left + Control.Padding.Left,
|
||||
Control.Margin.Top + Control.Padding.Top, 0, 0)
|
||||
};
|
||||
|
||||
if (Control is ItemsControl && !(Control is ComboBox))
|
||||
{
|
||||
_contentPresenter.VerticalAlignment = VerticalAlignment.Center;
|
||||
_contentPresenter.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
}
|
||||
|
||||
// Hide the control adorner when the adorned element is hidden
|
||||
var binding = new Binding("IsVisible")
|
||||
{
|
||||
Source = adornedElement,
|
||||
Converter = new BooleanToVisibilityConverter()
|
||||
};
|
||||
SetBinding(VisibilityProperty, binding);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of children for the <see cref="ContainerVisual"/>.
|
||||
/// </summary>
|
||||
protected override int VisualChildrenCount => 1;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the control that is being adorned
|
||||
/// </summary>
|
||||
private Control Control => (Control)AdornedElement;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Overrides
|
||||
|
||||
/// <summary>
|
||||
/// Returns a specified child <see cref="Visual"/> for the parent <see cref="ContainerVisual"/>.
|
||||
/// </summary>
|
||||
/// <param name="index">A 32-bit signed integer that represents the index value of the child <see cref="Visual"/>. The value of index must be between 0 and <see cref="VisualChildrenCount"/> - 1.</param>
|
||||
/// <returns>The child <see cref="Visual"/>.</returns>
|
||||
protected override Visual GetVisualChild(int index)
|
||||
{
|
||||
return _contentPresenter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implements any custom measuring behavior for the adorner.
|
||||
/// </summary>
|
||||
/// <param name="constraint">A size to constrain the adorner to.</param>
|
||||
/// <returns>A <see cref="Size"/> object representing the amount of layout space needed by the adorner.</returns>
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
// Here's the secret to getting the adorner to cover the whole control
|
||||
_contentPresenter.Measure(Control.RenderSize);
|
||||
return Control.RenderSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When overridden in a derived class, positions child elements and determines a size for a <see cref="FrameworkElement"/> derived class.
|
||||
/// </summary>
|
||||
/// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param>
|
||||
/// <returns>The actual size used.</returns>
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
_contentPresenter.Arrange(new Rect(finalSize));
|
||||
return finalSize;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace Sicentury.Core.AttachedProperties
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that provides the Watermark attached property
|
||||
/// </summary>
|
||||
public static class WatermarkService
|
||||
{
|
||||
/// <summary>
|
||||
/// Watermark Attached Dependency Property
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty WatermarkProperty = DependencyProperty.RegisterAttached(
|
||||
"Watermark",
|
||||
typeof(object),
|
||||
typeof(WatermarkService),
|
||||
new FrameworkPropertyMetadata(null, OnWatermarkChanged));
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of ItemsControls
|
||||
/// </summary>
|
||||
private static readonly Dictionary<object, ItemsControl> ItemsControls
|
||||
= new Dictionary<object, ItemsControl>();
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Watermark property. This dependency property indicates the watermark for the control.
|
||||
/// </summary>
|
||||
/// <param name="d"><see cref="DependencyObject"/> to get the property from</param>
|
||||
/// <returns>The value of the Watermark property</returns>
|
||||
public static object GetWatermark(DependencyObject d)
|
||||
{
|
||||
return d.GetValue(WatermarkProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Watermark property. This dependency property indicates the watermark for the control.
|
||||
/// </summary>
|
||||
/// <param name="d"><see cref="DependencyObject"/> to set the property on</param>
|
||||
/// <param name="value">value of the property</param>
|
||||
public static void SetWatermark(DependencyObject d, object value)
|
||||
{
|
||||
d.SetValue(WatermarkProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles changes to the Watermark property.
|
||||
/// </summary>
|
||||
/// <param name="d"><see cref="DependencyObject"/> that fired the event</param>
|
||||
/// <param name="e">A <see cref="DependencyPropertyChangedEventArgs"/> that contains the event data.</param>
|
||||
private static void OnWatermarkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = (Control)d;
|
||||
control.Loaded += Control_Loaded;
|
||||
|
||||
if (d is ComboBox)
|
||||
{
|
||||
control.GotKeyboardFocus += Control_GotKeyboardFocus;
|
||||
control.LostKeyboardFocus += Control_Loaded;
|
||||
}
|
||||
else if (d is TextBox)
|
||||
{
|
||||
control.GotKeyboardFocus += Control_GotKeyboardFocus;
|
||||
control.LostKeyboardFocus += Control_Loaded;
|
||||
((TextBox)control).TextChanged += Control_GotKeyboardFocus;
|
||||
}
|
||||
|
||||
if (d is ItemsControl o && !(o is ComboBox))
|
||||
{
|
||||
// for Items property
|
||||
o.ItemContainerGenerator.ItemsChanged += ItemsChanged;
|
||||
ItemsControls.Add(o.ItemContainerGenerator, o);
|
||||
|
||||
// for ItemsSource property
|
||||
var prop = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, o.GetType());
|
||||
prop.AddValueChanged(o, ItemsSourceChanged);
|
||||
}
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Handle the GotFocus event on the control
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
|
||||
private static void Control_GotKeyboardFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var c = (Control)sender;
|
||||
if (ShouldShowWatermark(c))
|
||||
{
|
||||
ShowWatermark(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveWatermark(c);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the Loaded and LostFocus event on the control
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
|
||||
private static void Control_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var control = (Control)sender;
|
||||
if (ShouldShowWatermark(control))
|
||||
{
|
||||
ShowWatermark(control);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event handler for the items source changed event
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
|
||||
private static void ItemsSourceChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
var c = (ItemsControl)sender;
|
||||
if (c.ItemsSource != null)
|
||||
{
|
||||
if (ShouldShowWatermark(c))
|
||||
{
|
||||
ShowWatermark(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveWatermark(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWatermark(c);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event handler for the items changed event
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">A <see cref="ItemsChangedEventArgs"/> that contains the event data.</param>
|
||||
private static void ItemsChanged(object sender, ItemsChangedEventArgs e)
|
||||
{
|
||||
ItemsControl control;
|
||||
if (ItemsControls.TryGetValue(sender, out control))
|
||||
{
|
||||
if (ShouldShowWatermark(control))
|
||||
{
|
||||
ShowWatermark(control);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveWatermark(control);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper Methods
|
||||
|
||||
/// <summary>
|
||||
/// Remove the watermark from the specified element
|
||||
/// </summary>
|
||||
/// <param name="control">Element to remove the watermark from</param>
|
||||
private static void RemoveWatermark(UIElement control)
|
||||
{
|
||||
var layer = AdornerLayer.GetAdornerLayer(control);
|
||||
|
||||
// layer could be null if control is no longer in the visual tree
|
||||
if (layer != null)
|
||||
{
|
||||
var adorners = layer.GetAdorners(control);
|
||||
if (adorners == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var adorner in adorners)
|
||||
{
|
||||
if (adorner is WatermarkAdorner)
|
||||
{
|
||||
adorner.Visibility = Visibility.Hidden;
|
||||
layer.Remove(adorner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the watermark on the specified control
|
||||
/// </summary>
|
||||
/// <param name="control">Control to show the watermark on</param>
|
||||
private static void ShowWatermark(Control control)
|
||||
{
|
||||
var layer = AdornerLayer.GetAdornerLayer(control);
|
||||
|
||||
// layer could be null if control is no longer in the visual tree
|
||||
layer?.Add(new WatermarkAdorner(control, GetWatermark(control)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether or not the watermark should be shown on the specified control
|
||||
/// </summary>
|
||||
/// <param name="c"><see cref="Control"/> to test</param>
|
||||
/// <returns>true if the watermark should be shown; false otherwise</returns>
|
||||
private static bool ShouldShowWatermark(Control c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case ComboBox box:
|
||||
return box.Text == string.Empty;
|
||||
|
||||
case TextBoxBase _:
|
||||
return (c as TextBox)?.Text == string.Empty;
|
||||
|
||||
case ItemsControl control:
|
||||
return control.Items.Count == 0;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Sicentury.Core
|
||||
{
|
||||
[Serializable]
|
||||
public abstract class BindableBase : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value))
|
||||
return;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChangedEventHandler eventHandler = this.PropertyChanged;
|
||||
eventHandler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Sicentury.Core.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// The collection is thread-safe.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class DelayedPresentRollingObservableCollection<T> : IEnumerable<T>, INotifyCollectionChanged, INotifyPropertyChanged
|
||||
{
|
||||
#region Variables
|
||||
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
|
||||
private readonly List<T> _list;
|
||||
private readonly List<T> _cache;
|
||||
|
||||
private readonly object _lockList;
|
||||
private readonly object _lockCache;
|
||||
|
||||
private readonly SemaphoreSlim _semListEnumLocker;
|
||||
|
||||
private readonly int _presentDelayMillisec = 200; // the default delay is 200ms
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public DelayedPresentRollingObservableCollection(int capacity)
|
||||
{
|
||||
if (capacity <= 0)
|
||||
throw new ArgumentException("the capacity must be greate then 0.", nameof(capacity));
|
||||
|
||||
_lockList = new object();
|
||||
_lockCache = new object();
|
||||
_semListEnumLocker = new SemaphoreSlim(0, 1);
|
||||
|
||||
Capacity = capacity;
|
||||
|
||||
lock (_lockList)
|
||||
{
|
||||
_list = new List<T>();
|
||||
}
|
||||
|
||||
lock (_lockCache)
|
||||
{
|
||||
_cache = new List<T>();
|
||||
}
|
||||
|
||||
_semListEnumLocker.Release();
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Present();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Trace.WriteLine($"Unable to present the items, {e.Message}");
|
||||
Debugger.Break();
|
||||
}
|
||||
finally
|
||||
{
|
||||
// present the data every 200ms
|
||||
await Task.Delay(_presentDelayMillisec);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public DelayedPresentRollingObservableCollection(int capacity, int presentDelayMillisec) : this(capacity)
|
||||
{
|
||||
_presentDelayMillisec = presentDelayMillisec < 50 ? 50 : presentDelayMillisec;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public int Capacity { get; }
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lockList)
|
||||
{
|
||||
return _list?.Count ?? 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Copy the items from the cache to the presented list and update the UI.
|
||||
/// </summary>
|
||||
private void Present()
|
||||
{
|
||||
var itemsChanged = new List<T>();
|
||||
|
||||
lock (_lockCache)
|
||||
{
|
||||
if (_cache.Count <= 0)
|
||||
return;
|
||||
|
||||
itemsChanged.AddRange(_cache);
|
||||
_cache.Clear();
|
||||
}
|
||||
|
||||
var notifyAction = NotifyCollectionChangedAction.Add;
|
||||
lock (_lockList)
|
||||
{
|
||||
_list.AddRange(itemsChanged);
|
||||
|
||||
if (_list.Count >= Capacity)
|
||||
{
|
||||
var cntToRemain = Capacity / 2;
|
||||
_list.RemoveRange(0, _list.Count - cntToRemain);
|
||||
|
||||
notifyAction = NotifyCollectionChangedAction.Reset;
|
||||
}
|
||||
}
|
||||
|
||||
// raise the collection changed event.
|
||||
SynchronizationContext.SetSynchronizationContext(
|
||||
new DispatcherSynchronizationContext(Application.Current.Dispatcher));
|
||||
|
||||
SynchronizationContext.Current.Post(p1 =>
|
||||
{
|
||||
CollectionChanged?.Invoke(
|
||||
this,
|
||||
new NotifyCollectionChangedEventArgs(notifyAction,
|
||||
notifyAction == NotifyCollectionChangedAction.Add ? itemsChanged : null));
|
||||
}, null);
|
||||
|
||||
SynchronizationContext.Current.Post(p1 =>
|
||||
{
|
||||
OnPropertyChanged(nameof(Count));
|
||||
}, null);
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
Present();
|
||||
|
||||
// raise the collection changed event.
|
||||
SynchronizationContext.SetSynchronizationContext(
|
||||
new DispatcherSynchronizationContext(Application.Current.Dispatcher));
|
||||
|
||||
SynchronizationContext.Current.Post(p1 =>
|
||||
{
|
||||
CollectionChanged?.Invoke(
|
||||
this,
|
||||
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}, null);
|
||||
|
||||
SynchronizationContext.Current.Post(p1 =>
|
||||
{
|
||||
OnPropertyChanged(nameof(Count));
|
||||
}, null);
|
||||
}
|
||||
|
||||
public void Add(T newItem)
|
||||
{
|
||||
lock (_lockCache)
|
||||
{
|
||||
_cache.Add(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(T oldItem)
|
||||
{
|
||||
lock (_lockList)
|
||||
{
|
||||
return _list.Remove(oldItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
lock (_lockList)
|
||||
{
|
||||
_list.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveRange(int index, int count)
|
||||
{
|
||||
lock (_lockList)
|
||||
{
|
||||
_list.RemoveRange(index, count);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
lock (_lockCache)
|
||||
{
|
||||
_cache.Clear();
|
||||
}
|
||||
|
||||
lock (_lockList)
|
||||
{
|
||||
_list.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
lock (_lockList)
|
||||
{
|
||||
_semListEnumLocker.Wait();
|
||||
return new SafeEnumerator<T>(_list.GetEnumerator(), _semListEnumLocker);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
lock (_lockList)
|
||||
{
|
||||
_semListEnumLocker.Wait();
|
||||
return new SafeEnumerator<T>(_list.GetEnumerator(), _semListEnumLocker);
|
||||
}
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= Count)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
lock (_lockList)
|
||||
{
|
||||
return _list[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Sicentury.Core.Collections
|
||||
{
|
||||
public class ObservableQueue<T> : Queue<T>, INotifyCollectionChanged
|
||||
{
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
|
||||
private readonly object _syncRoot = new object();
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ObservableQueue()
|
||||
{
|
||||
LimitSize = 0;
|
||||
}
|
||||
|
||||
public ObservableQueue(int capacity) : base(capacity)
|
||||
{
|
||||
LimitSize = capacity;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public int LimitSize { get; }
|
||||
|
||||
public new virtual void Enqueue(T obj)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
base.Enqueue(obj);
|
||||
|
||||
if (LimitSize > 0 && base.Count > LimitSize)
|
||||
base.Dequeue();
|
||||
|
||||
CollectionChanged?.Invoke(this,
|
||||
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, obj));
|
||||
}
|
||||
}
|
||||
|
||||
public new virtual T Dequeue()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
var obj = base.Dequeue();
|
||||
CollectionChanged?.Invoke(this,
|
||||
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, obj));
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public new virtual void Clear()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
base.Clear();
|
||||
CollectionChanged?.Invoke(this,
|
||||
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sicentury.Core.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ObservableRangeCollection<T> : ObservableCollection<T>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the System.Collections.ObjectModel.ObservableCollection(Of T) class.
|
||||
/// </summary>
|
||||
public ObservableRangeCollection()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the System.Collections.ObjectModel.ObservableCollection(Of T) class that contains elements copied from the specified collection.
|
||||
/// </summary>
|
||||
/// <param name="collection">collection: The collection from which the elements are copied.</param>
|
||||
/// <exception cref="System.ArgumentNullException">The collection parameter cannot be null.</exception>
|
||||
public ObservableRangeCollection(IEnumerable<T> collection)
|
||||
: base(collection)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Adds the elements of the specified collection to the end of the ObservableCollection(Of T).
|
||||
/// </summary>
|
||||
public virtual void AddRange(IEnumerable<T> collection)
|
||||
{
|
||||
if (collection == null) throw new ArgumentNullException(nameof(collection));
|
||||
|
||||
var startIndex = Count;
|
||||
var enumerable = collection.ToList();
|
||||
foreach (var i in enumerable)
|
||||
Items.Add(i);
|
||||
|
||||
OnCollectionChanged(
|
||||
new NotifyCollectionChangedEventArgs(
|
||||
NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the first occurence of each item in the specified collection from ObservableCollection(Of T).
|
||||
/// </summary>
|
||||
public virtual void RemoveRange(IEnumerable<T> collection)
|
||||
{
|
||||
if (collection == null) throw new ArgumentNullException(nameof(collection));
|
||||
|
||||
foreach (var i in collection)
|
||||
Items.Remove(i);
|
||||
|
||||
OnCollectionChanged(
|
||||
new NotifyCollectionChangedEventArgs(
|
||||
NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the current collection and replaces it with the specified item.
|
||||
/// </summary>
|
||||
public virtual void Replace(T item)
|
||||
{
|
||||
ReplaceRange(new[] {item});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the current collection and replaces it with the specified collection.
|
||||
/// </summary>
|
||||
public void ReplaceRange(IEnumerable<T> collection)
|
||||
{
|
||||
if (collection == null) throw new ArgumentNullException(nameof(collection));
|
||||
|
||||
Items.Clear();
|
||||
foreach (var i in collection) Items.Add(i);
|
||||
OnCollectionChanged(
|
||||
new NotifyCollectionChangedEventArgs(
|
||||
NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace Sicentury.Core.Collections
|
||||
{
|
||||
public sealed class SafeEnumerator<T> : IEnumerator<T>
|
||||
|
||||
{
|
||||
#region variables
|
||||
|
||||
// this is the (thread-unsafe)
|
||||
// enumerator of the underlying collection
|
||||
private readonly IEnumerator<T> _enumeratorInner;
|
||||
|
||||
// this is the object we shall lock on.
|
||||
private readonly SemaphoreSlim _semLocker;
|
||||
|
||||
#endregion
|
||||
|
||||
public SafeEnumerator(IEnumerator<T> inner, SemaphoreSlim semLocker)
|
||||
{
|
||||
// entering lock in constructor
|
||||
//semLocker.Wait();
|
||||
_semLocker = semLocker;
|
||||
|
||||
_enumeratorInner = inner;
|
||||
}
|
||||
|
||||
#region Implementation of IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_semLocker.Release();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IEnumerator
|
||||
|
||||
// we just delegate actual implementation
|
||||
// to the inner enumerator, that actually iterates
|
||||
// over some collection
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
return _enumeratorInner.MoveNext();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_enumeratorInner.Reset();
|
||||
}
|
||||
|
||||
public T Current => _enumeratorInner.Current;
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using DrawingColor = System.Drawing.Color;
|
||||
using MediaColor = System.Windows.Media.Color;
|
||||
|
||||
namespace Sicentury.Core.Converters
|
||||
{
|
||||
internal class DrawingColorToMediaColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is DrawingColor dc)
|
||||
return MediaColor.FromArgb(dc.A, dc.R, dc.G, dc.B);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is MediaColor mc)
|
||||
return DrawingColor.FromArgb(mc.A, mc.R, mc.G, mc.B);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Sicentury.Core.Converters
|
||||
{
|
||||
public class DummyConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
Debugger.Break();
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
Debugger.Break();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Sicentury.Core.Converters
|
||||
{
|
||||
internal class MediaColorToSolidColorBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Color color)
|
||||
return new SolidColorBrush(color);
|
||||
|
||||
return new SolidColorBrush(Colors.Black);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush)
|
||||
return brush.Color;
|
||||
|
||||
return Colors.Black;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Sicentury.Core.Converters
|
||||
{
|
||||
public class ParameterNodeStatisticToStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double dv)
|
||||
{
|
||||
if (double.IsNaN(dv) || double.IsInfinity(dv))
|
||||
return "";
|
||||
|
||||
return dv.ToString("F3");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Sicentury.Core.Converters
|
||||
{
|
||||
internal class ParameterNodeTreeViewVisibilityMultiBindingConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
// 如果绑定的参数个数错误,隐藏节点
|
||||
if (values.Length != 2)
|
||||
{
|
||||
Debugger.Break();
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if (values[0] is bool isMatch && values[1] is Visibility visibility)
|
||||
{
|
||||
// 如果设置为隐藏,则无论是否Filter匹配,均隐藏节点
|
||||
if (visibility != Visibility.Visible)
|
||||
return visibility;
|
||||
|
||||
// 如果设置为显示,则根据Filter是否匹配决定是否显示节点
|
||||
if (isMatch == false)
|
||||
return Visibility.Collapsed;
|
||||
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
// 如果传入的参数类型错误,隐藏节点
|
||||
Debugger.Break();
|
||||
return Visibility.Collapsed;
|
||||
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sicentury.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 该类实现对时间范围进行操作,包括按指定间隔分隔时间范围。
|
||||
/// </summary>
|
||||
public class DateRangeHelper
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public DateRangeHelper(DateTime start, DateTime end)
|
||||
{
|
||||
Start = start;
|
||||
End = end;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public DateTime Start { get; set; }
|
||||
|
||||
public DateTime End { get; set; }
|
||||
|
||||
public TimeSpan Diff => End - Start;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 将时间范围按天为间隔分割为数组。
|
||||
/// </summary>
|
||||
/// <param name="range"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<DateRangeHelper> SplitInToDays(DateRangeHelper range)
|
||||
{
|
||||
var ranges = new List<DateRangeHelper>();
|
||||
|
||||
var currRange = new DateRangeHelper(range.Start, range.Start.Date.AddDays(1).AddTicks(-1));
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (currRange.End.Date <= range.End.Date)
|
||||
{
|
||||
if (currRange.End > range.End)
|
||||
currRange.End = range.End;
|
||||
|
||||
ranges.Add(currRange);
|
||||
|
||||
// 向后移一天
|
||||
currRange = new DateRangeHelper(currRange.Start.Date.AddDays(1),
|
||||
currRange.Start.Date.AddDays(2).AddTicks((-1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ranges;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将时间范围按指定的小时间隔分割为数组。
|
||||
/// </summary>
|
||||
/// <param name="range"></param>
|
||||
/// <param name="hourGap"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public static IEnumerable<DateRangeHelper> SplitInToHours(DateRangeHelper range, int hourGap)
|
||||
{
|
||||
var ranges = new List<DateRangeHelper>();
|
||||
|
||||
var timeBegin = range.Start;
|
||||
if (timeBegin > range.End)
|
||||
return ranges;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var timeEnd = timeBegin.AddHours(hourGap);
|
||||
// 检查是否超过timeStart日期
|
||||
if (timeEnd.Date > timeBegin.Date)
|
||||
timeEnd = timeBegin.Date.AddDays(1).AddTicks(-1);
|
||||
|
||||
if (timeEnd > range.End)
|
||||
timeEnd = range.End;
|
||||
|
||||
ranges.Add(new DateRangeHelper(timeBegin, timeEnd));
|
||||
|
||||
timeBegin = timeEnd.AddTicks(1);
|
||||
|
||||
// 如果其实时间大于给定范围,则退出
|
||||
if (timeBegin > range.End)
|
||||
break;
|
||||
}
|
||||
|
||||
return ranges;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Start:yyyy/MM/dd HH:mm:ss.fff} - {End:yyyy/MM/dd HH:mm:ss.fff}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,178 @@
|
||||
// /************************************************************************
|
||||
// * @file DeviceLocker.cs
|
||||
// * @author Su Liang
|
||||
// * @date 2022/11/16
|
||||
// *
|
||||
// * @copyright © Sicentury Inc.
|
||||
// *
|
||||
// * @brief 设备资源锁定器。
|
||||
// *
|
||||
// * @details 当某个设备或其它资源不能被多个线程同时使用时,可使用此锁定器实现资源互斥操作。
|
||||
// *
|
||||
// *
|
||||
// * *****************************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace Sicentury.Core
|
||||
{
|
||||
public class DeviceLocker
|
||||
{
|
||||
public enum Results
|
||||
{
|
||||
Ok,
|
||||
Error,
|
||||
IHaveLocker
|
||||
}
|
||||
|
||||
private readonly object _syncRoot = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 返回占有该设备的对象名称.
|
||||
/// <para>关于可能使用到的占用者名称,请参考枚举类型<see cref="ModuleName"/>。</para>
|
||||
/// </summary>
|
||||
private readonly List<string> _occupiersCollection;
|
||||
private CancellationTokenSource _cts;
|
||||
private SemaphoreSlim _semResource;
|
||||
private readonly int _maxRes;
|
||||
|
||||
#region Constructor
|
||||
|
||||
public DeviceLocker(string lockerName, int maxResCount)
|
||||
{
|
||||
LockerName = lockerName;
|
||||
_occupiersCollection = new List<string>();
|
||||
_maxRes = maxResCount;
|
||||
_semResource = new SemaphoreSlim(maxResCount, maxResCount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 设备名称。
|
||||
/// </summary>
|
||||
public string LockerName { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region MyRegion
|
||||
|
||||
/// <summary>
|
||||
/// 锁定设备。
|
||||
/// </summary>
|
||||
/// <param name="occupier"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <param name="timeoutInMillisecond"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <returns></returns>
|
||||
public Results TryLock(string occupier, out string reason, int timeoutInMillisecond)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
var a = _occupiersCollection.FirstOrDefault(x => x == occupier.ToString());
|
||||
if (a != null)
|
||||
{
|
||||
reason = $"{LockerName} had been lock by {occupier}";
|
||||
return Results.IHaveLocker;
|
||||
}
|
||||
|
||||
if (_cts != null)
|
||||
{
|
||||
reason = $"{LockerName} is waiting to be locked";
|
||||
return Results.Error;
|
||||
}
|
||||
|
||||
_cts = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (_semResource.Wait(timeoutInMillisecond, _cts.Token))
|
||||
{
|
||||
_occupiersCollection.Add(occupier);
|
||||
reason = "";
|
||||
return Results.Ok;
|
||||
}
|
||||
|
||||
reason =
|
||||
$"Unable to lock {LockerName}, no enough resources, locked by {string.Join(", ", _occupiersCollection)}";
|
||||
return Results.Error;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
reason = $"It's canceled to lock {LockerName}";
|
||||
return Results.Error;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
reason =
|
||||
$"Unable to lock {LockerName}, {ex.Message}";
|
||||
return Results.Error;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 无论锁定是否成功,均销毁CancellationTokenSource。
|
||||
_cts = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放设备。
|
||||
/// </summary>
|
||||
/// <param name="occupier"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <returns></returns>
|
||||
public Results TryUnlock(string occupier, out string reason)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
var a = _occupiersCollection.FirstOrDefault(x => x == occupier);
|
||||
if (a == null)
|
||||
{
|
||||
reason = $"{LockerName} is never locked by {occupier}";
|
||||
return Results.Error;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_semResource.Release(1);
|
||||
_occupiersCollection.Remove(occupier);
|
||||
reason = "";
|
||||
return Results.Ok;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
reason = $"Unable to lock {LockerName} by {occupier}, {ex.Message}";
|
||||
return Results.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消等待可用的锁。
|
||||
/// </summary>
|
||||
public void CancelLockWaiting()
|
||||
{
|
||||
_cts?.Cancel();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
_cts?.Cancel();
|
||||
Thread.Sleep(100); // 等待 Semaphore Cancel
|
||||
_semResource = new SemaphoreSlim(_maxRes, _maxRes);
|
||||
_occupiersCollection.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<Window x:Class="Sicentury.Core.Dialogs.PresetGroupSaveDialog"
|
||||
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:Height="200" d:Width="400"
|
||||
WindowStyle="None"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
ResizeMode="NoResize"
|
||||
AllowsTransparency="True"
|
||||
Background="Transparent">
|
||||
<Grid Height="140" Width="330">
|
||||
<Grid.Effect>
|
||||
<DropShadowEffect BlurRadius="40" ShadowDepth="10" Opacity="0.7" />
|
||||
</Grid.Effect>
|
||||
<Border
|
||||
Background="{DynamicResource Tab_BG}"
|
||||
BorderBrush="Gray"
|
||||
BorderThickness="3">
|
||||
<Grid Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="70"/>
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Border
|
||||
Background="{DynamicResource Table_BG_Content_Highlight}"
|
||||
BorderBrush="{DynamicResource Table_BD}"
|
||||
BorderThickness="1">
|
||||
<Canvas>
|
||||
<TextBlock
|
||||
Canvas.Left="10"
|
||||
Canvas.Top="22"
|
||||
FontFamily="Arial"
|
||||
FontSize="12"
|
||||
Foreground="{DynamicResource FG_Black}"
|
||||
Text="Group Name" />
|
||||
<TextBox
|
||||
x:Name="txtGroupName"
|
||||
Canvas.Left="100"
|
||||
Canvas.Top="16"
|
||||
Width="200"
|
||||
Height="28"
|
||||
MaxLength="30" />
|
||||
<TextBlock
|
||||
x:Name="txtErrors"
|
||||
Canvas.Left="100"
|
||||
Canvas.Top="47"
|
||||
Text="" Foreground="Red"/>
|
||||
|
||||
</Canvas>
|
||||
</Border>
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
Margin="0 10 0 0"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Orientation="Horizontal">
|
||||
<Button x:Name="btnOk"
|
||||
Width="90"
|
||||
Height="30"
|
||||
Content="OK"
|
||||
Click="BtnOk_OnClick">
|
||||
</Button>
|
||||
<Button x:Name="btnCancel"
|
||||
Width="90"
|
||||
Height="30"
|
||||
Margin="10,0,0,0"
|
||||
Content="Cancel"
|
||||
Click="BtnCancel_OnClick">
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace Sicentury.Core.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for PresetGroupSaveDialog.xaml
|
||||
/// </summary>
|
||||
public partial class PresetGroupSaveDialog
|
||||
{
|
||||
#region Variables
|
||||
|
||||
private readonly IEnumerable<string> _existFileNames;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public PresetGroupSaveDialog(string title, IEnumerable<string> existFileNames, string defaultGroupName = "")
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Title = title;
|
||||
_existFileNames = existFileNames;
|
||||
|
||||
if (!string.IsNullOrEmpty(defaultGroupName))
|
||||
txtGroupName.Text = defaultGroupName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string GroupName => txtGroupName.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void OnActivated(System.EventArgs e)
|
||||
{
|
||||
txtGroupName.SelectAll();
|
||||
txtGroupName.Focus();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
private void BtnOk_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 检查文件明是否为空
|
||||
if (string.IsNullOrEmpty(GroupName))
|
||||
{
|
||||
txtErrors.Text = "Group Name is Empty";
|
||||
txtGroupName.SelectAll();
|
||||
txtGroupName.Focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查文件名是否包含非法字符
|
||||
if (GroupName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
|
||||
{
|
||||
txtErrors.Text = "illegal char(s) in Group Name";
|
||||
txtGroupName.SelectAll();
|
||||
txtGroupName.Focus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_existFileNames != null && _existFileNames.Contains(GroupName))
|
||||
{
|
||||
txtErrors.Text = "Group Name has existed";
|
||||
txtGroupName.SelectAll();
|
||||
txtGroupName.Focus();
|
||||
return;
|
||||
}
|
||||
|
||||
this.DialogResult = true;
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DialogResult = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace Sicentury.Core.EventArgs
|
||||
{
|
||||
public class ProgressUpdatingEventArgs : System.EventArgs
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public ProgressUpdatingEventArgs(int currentProgress, int totalProgress, string message)
|
||||
{
|
||||
CurrentProgress = currentProgress;
|
||||
TotalProgress = totalProgress;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properites
|
||||
|
||||
/// <summary>
|
||||
/// 总进度。
|
||||
/// </summary>
|
||||
public int TotalProgress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前进度。
|
||||
/// </summary>
|
||||
public int CurrentProgress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息。
|
||||
/// </summary>
|
||||
public string Message { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel;
|
||||
using Sicentury.Core.Tree;
|
||||
|
||||
namespace Sicentury.Core.EventArgs
|
||||
{
|
||||
public class TreeNodeSelectionChangedEventArgs : CancelEventArgs
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public TreeNodeSelectionChangedEventArgs(TreeNode source, bool? oldValue, bool? newValue)
|
||||
{
|
||||
Source = source;
|
||||
OldValue = oldValue;
|
||||
NewValue = newValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 触发事件的<see cref="TreeNode"/>对象。
|
||||
/// </summary>
|
||||
public TreeNode Source { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回IsSelected旧值。
|
||||
/// </summary>
|
||||
public bool? OldValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回IsSelected新值。
|
||||
/// </summary>
|
||||
public bool? NewValue { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sicentury.Core.Extensions
|
||||
{
|
||||
public static class EnumExtensionMethods
|
||||
{
|
||||
public static string GetDescription(this Enum genericEnum)
|
||||
{
|
||||
var genericEnumType = genericEnum.GetType();
|
||||
var memberInfo = genericEnumType.GetMember(genericEnum.ToString());
|
||||
if ((memberInfo.Length <= 0))
|
||||
return genericEnum.ToString();
|
||||
|
||||
var attributes = memberInfo[0]
|
||||
.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
|
||||
if ((attributes.Any()))
|
||||
{
|
||||
return ((System.ComponentModel.DescriptionAttribute)attributes.ElementAt(0)).Description;
|
||||
}
|
||||
|
||||
return genericEnum.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Sicentury.Core.Extensions
|
||||
{
|
||||
public static class Sha256Extension
|
||||
{
|
||||
public static string Sha256Encoding(this string strSource)
|
||||
{
|
||||
using (var sha = SHA256.Create())
|
||||
{
|
||||
var hashBytes = sha.ComputeHash(Encoding.UTF8.GetBytes(strSource));
|
||||
var hashStr = BitConverter.ToString(hashBytes).Replace("-", "");
|
||||
return hashStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#nullable enable
|
||||
namespace Sicentury.Core.Extensions
|
||||
{
|
||||
public static class StringExtension
|
||||
{
|
||||
public static string? Truncate(this string? value, int maxLength, string truncationSuffix = "…")
|
||||
{
|
||||
return value?.Length > maxLength
|
||||
? value.Substring(0, maxLength) + truncationSuffix
|
||||
: value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
|
||||
using System;
|
||||
using shortid.Configuration;
|
||||
|
||||
namespace Sicentury.Core
|
||||
{
|
||||
public class GlobalDefs
|
||||
{
|
||||
/// <summary>
|
||||
/// 比较两个Double型变量是否相等时的最小误差值。
|
||||
/// </summary>
|
||||
public const double DBL_VAL_COMPARISION_TOLERANCE = 1e-6;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 比较两个Double型变量是否相等。
|
||||
/// <para>注意:未考虑NaN和Infinity情况。</para>
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <param name="tolerance"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static bool IsDoubleValueEquals(double a, double b, double tolerance = DBL_VAL_COMPARISION_TOLERANCE)
|
||||
{
|
||||
return Math.Abs(a - b) < tolerance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将制定的字符串转换为Double型。如果转换失败,返回默认值。
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="valueIfFault"></param>
|
||||
/// <returns></returns>
|
||||
public static double TryParseToDouble(string str, double valueIfFault = 0)
|
||||
{
|
||||
var ret = double.TryParse(str, out var dbv);
|
||||
if (ret == false)
|
||||
dbv = valueIfFault;
|
||||
return dbv;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定长度和格式的唯一识别码。
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="isUseNumber"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetShortUid(int length = 8, bool isUseNumber = true)
|
||||
{
|
||||
return shortid.ShortId.Generate(new GenerationOptions(isUseNumber, false, length));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\Core\Pipelines\PipelineMethodInvoker.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-01
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief The class is design to operate data querying and UI rendering processes in a 2-stage pipeline.
|
||||
*
|
||||
* @details
|
||||
* 2 queues are used to buffer the querying functions and UI rendering functions, and execute them
|
||||
* one by one.
|
||||
*
|
||||
* *****************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Sicentury.Core.Pipelines
|
||||
{
|
||||
public class PipelineMethodInvoker<TResult>
|
||||
{
|
||||
public PipelineMethodInvoker(Func<TResult> func)
|
||||
{
|
||||
Function = func;
|
||||
}
|
||||
|
||||
public bool IsEmpty => Function == null;
|
||||
|
||||
public Func<TResult> Function { get; }
|
||||
|
||||
public TResult Invoke()
|
||||
{
|
||||
return Function.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PipelineMethodInvoker<TParam, TResult>
|
||||
{
|
||||
public PipelineMethodInvoker(Func<TParam, TResult> func)
|
||||
{
|
||||
Function = func;
|
||||
}
|
||||
|
||||
public bool IsEmpty => Function == null;
|
||||
|
||||
public Func<TParam, TResult> Function { get; }
|
||||
|
||||
|
||||
public TResult Invoke(TParam arg)
|
||||
{
|
||||
return Function.Invoke(arg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\DataLogs\Core\TwoStagePipelineBasedTaskExecutor.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-01
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief The class is design to operate data querying and UI rendering processes in a 2-stage pipeline.
|
||||
*
|
||||
* @details
|
||||
* 2 queues are used to buffer the querying functions and UI rendering functions, and execute them
|
||||
* one by one.
|
||||
*
|
||||
* *****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.TextFormatting;
|
||||
|
||||
namespace Sicentury.Core.Pipelines
|
||||
{
|
||||
public class TwoStagePipelineBasedTaskExecutor<TResult1, TResult2> : IDisposable
|
||||
{
|
||||
|
||||
#region Variables
|
||||
|
||||
/// <summary>
|
||||
/// 1级流水线中的任务全部完成事件。
|
||||
/// </summary>
|
||||
public event EventHandler Stage1Finished;
|
||||
|
||||
public event EventHandler Stage2Finished;
|
||||
|
||||
/// <summary>
|
||||
/// 1级流水线中的单个任务启动事件。
|
||||
/// </summary>
|
||||
public event EventHandler Stage1ActionStarted;
|
||||
|
||||
/// <summary>
|
||||
/// 1级流水线中的单个任务完成事件。
|
||||
/// </summary>
|
||||
public event EventHandler Stage1ActionFinished;
|
||||
|
||||
/// <summary>
|
||||
/// 2级流水线中的单个任务启动事件。
|
||||
/// </summary>
|
||||
public event EventHandler Stage2ActionStarted;
|
||||
|
||||
/// <summary>
|
||||
/// 2级流水线中的单个任务完成事件。
|
||||
/// </summary>
|
||||
public event EventHandler Stage2ActionFinished;
|
||||
|
||||
|
||||
private readonly ConcurrentQueue<PipelineMethodInvoker<TResult1>> _queueAction1;
|
||||
private readonly ConcurrentQueue<PipelineMethodInvoker<TResult1, TResult2>> _queueAction2;
|
||||
private readonly ConcurrentQueue<TResult1> _queueAction1Result;
|
||||
private readonly ConcurrentQueue<TResult2> _queueAction2Result;
|
||||
|
||||
private bool _isDisposed;
|
||||
private Exception _lastException;
|
||||
private readonly List<Task> _tskPipeline;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public TwoStagePipelineBasedTaskExecutor()
|
||||
{
|
||||
//ThreadPool.GetMinThreads(out _workerThreadsMin, out _mIocMin);
|
||||
//ThreadPool.SetMinThreads(100, 100);
|
||||
|
||||
_queueAction1 = new ConcurrentQueue<PipelineMethodInvoker<TResult1>>();
|
||||
_queueAction2 = new ConcurrentQueue<PipelineMethodInvoker<TResult1, TResult2>>();
|
||||
_queueAction1Result = new ConcurrentQueue<TResult1>();
|
||||
_queueAction2Result = new ConcurrentQueue<TResult2>();
|
||||
|
||||
_lastException = null;
|
||||
_tskPipeline = new List<Task>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private Task ExecuteFunc1(CancellationTokenSource cancellation)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
while (_isDisposed == false)
|
||||
{
|
||||
if (_queueAction1.Count <= 0)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_queueAction1.TryDequeue(out var invoker))
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (invoker.IsEmpty)
|
||||
{
|
||||
// 列队结束
|
||||
Stage1Finished?.Invoke(this, System.EventArgs.Empty);
|
||||
break;
|
||||
}
|
||||
|
||||
Stage1ActionStarted?.Invoke(this, System.EventArgs.Empty);
|
||||
|
||||
try
|
||||
{
|
||||
_queueAction1Result.Enqueue(invoker.Invoke());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_lastException = ex;
|
||||
throw;
|
||||
}
|
||||
|
||||
Stage1ActionFinished?.Invoke(this, System.EventArgs.Empty);
|
||||
|
||||
Thread.Sleep(1);
|
||||
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Task ExecuteFunc2(CancellationTokenSource cancellation)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
while (_isDisposed == false)
|
||||
{
|
||||
if (_queueAction2.Count <= 0)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_queueAction2.TryDequeue(out var invoker))
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (invoker.IsEmpty)
|
||||
{
|
||||
// 列队结束
|
||||
Stage2Finished?.Invoke(this, System.EventArgs.Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
while (_isDisposed == false)
|
||||
{
|
||||
// 等待 Stage 1 方法返回的结果。
|
||||
if (_queueAction1Result.Count > 0)
|
||||
break;
|
||||
|
||||
Thread.Sleep(1);
|
||||
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
|
||||
// 如果流水线1有错误发生,则中断流水线2
|
||||
if (_lastException != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_queueAction1Result.TryDequeue(out var arg))
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Stage2ActionStarted?.Invoke(this, System.EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
_queueAction2Result.Enqueue(invoker.Invoke(arg));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_lastException = ex;
|
||||
throw;
|
||||
}
|
||||
|
||||
Stage2ActionFinished?.Invoke(this, System.EventArgs.Empty);
|
||||
|
||||
Thread.Sleep(1);
|
||||
|
||||
if (cancellation?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加 Stage1 功能函数。
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
public void AppendFunc1(Func<TResult1> func)
|
||||
{
|
||||
_queueAction1.Enqueue(new PipelineMethodInvoker<TResult1>(func));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加 Stage2 功能函数。
|
||||
/// </summary>
|
||||
public void AppendFunc2(Func<TResult1, TResult2> func)
|
||||
{
|
||||
_queueAction2.Enqueue(new PipelineMethodInvoker<TResult1, TResult2>(func));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动流水线。
|
||||
/// </summary>
|
||||
public List<Task> Start(CancellationTokenSource cancellation)
|
||||
{
|
||||
if (_tskPipeline.Count > 0)
|
||||
throw new InvalidOperationException("the pipeline has been started.");
|
||||
|
||||
_tskPipeline.Add(ExecuteFunc1(cancellation));
|
||||
_tskPipeline.Add(ExecuteFunc2(cancellation));
|
||||
|
||||
return _tskPipeline;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待流水线执行结束。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public async Task WaitDone()
|
||||
{
|
||||
if (_tskPipeline.Count <= 0)
|
||||
throw new InvalidOperationException("the pipeline is not started.");
|
||||
|
||||
await Task.WhenAll(_tskPipeline);
|
||||
|
||||
// 检查是否有Pipeline线程抛异常。
|
||||
var faultedTask = _tskPipeline.Where(t => t.IsFaulted).ToList();
|
||||
if (faultedTask.Any())
|
||||
{
|
||||
var lstEx = new List<Exception>();
|
||||
foreach (var t in faultedTask)
|
||||
{
|
||||
if (t.Exception?.InnerExceptions != null)
|
||||
lstEx.AddRange(t.Exception.InnerExceptions);
|
||||
}
|
||||
|
||||
var aex = new AggregateException(lstEx);
|
||||
throw aex;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动流水线并且等待执行完成。
|
||||
/// </summary>
|
||||
/// <param name="cancellation"></param>
|
||||
/// <returns></returns>
|
||||
public async Task StartAndWaitDone(CancellationTokenSource cancellation)
|
||||
{
|
||||
Start(cancellation);
|
||||
await WaitDone();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_isDisposed = true;
|
||||
_tskPipeline.Clear();
|
||||
|
||||
//try
|
||||
//{
|
||||
// ThreadPool.SetMinThreads(_workerThreadsMin, _mIocMin);
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
// // Ignore
|
||||
//}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Sicentury.Core")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Sicentury.Core")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2020 - 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a78b3f87-4601-43f7-a941-edb339ce35a9")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.4.0.50801")]
|
||||
//[assembly: AssemblyFileVersion("1.0.3.3")]
|
||||
@@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A78B3F87-4601-43F7-A941-EDB339CE35A9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Sicentury.Core</RootNamespace>
|
||||
<AssemblyName>Sicentury.Core</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Dependencies\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="shortid">
|
||||
<HintPath>..\..\Dependencies\shortid.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="WPFLocalizeExtension">
|
||||
<HintPath>..\..\Dependencies\WPFLocalizeExtension.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="XAMLMarkupExtensions">
|
||||
<HintPath>..\..\Dependencies\XAMLMarkupExtensions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AttachedProperties\TextBlockHighlighter.cs" />
|
||||
<Compile Include="AttachedProperties\WatermarkAdorner.cs" />
|
||||
<Compile Include="AttachedProperties\WatermarkService.cs" />
|
||||
<Compile Include="BindableBase.cs" />
|
||||
<Compile Include="Collections\ObservableQueue.cs" />
|
||||
<Compile Include="Converters\DummyConverter.cs" />
|
||||
<Compile Include="Converters\MediaColorToSolidColorBrushConverter.cs" />
|
||||
<Compile Include="Converters\ParameterNodeStatisticToStringConverter.cs" />
|
||||
<Compile Include="Converters\ParameterNodeTreeViewVisibilityMultiBindingConverter.cs" />
|
||||
<Compile Include="Converters\DrawingColorToMediaColorConverter.cs" />
|
||||
<Compile Include="DateRangeHelper.cs" />
|
||||
<Compile Include="Collections\DelayedPresentRollingObservableCollection.cs" />
|
||||
<Compile Include="DeviceLocker.cs" />
|
||||
<Compile Include="Dialogs\PresetGroupSaveDialog.xaml.cs">
|
||||
<DependentUpon>PresetGroupSaveDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="EventArgs\TreeNodeSelectionChangedEventArgs.cs" />
|
||||
<Compile Include="EventArgs\ProgressUpdatingEventArgs.cs" />
|
||||
<Compile Include="Collections\ObservableRangeCollection.cs" />
|
||||
<Compile Include="Extensions\EnumExtensionMethods.cs" />
|
||||
<Compile Include="Extensions\StringExtension.cs" />
|
||||
<Compile Include="GlobalDefs.cs" />
|
||||
<Compile Include="Tree\TreeNode.cs" />
|
||||
<Compile Include="Tree\TreeNodeCollection.cs" />
|
||||
<Compile Include="Tree\TreeNodeSelectionGroupInfo.cs" />
|
||||
<Compile Include="Pipelines\PipelineMethodInvoker.cs" />
|
||||
<Compile Include="Pipelines\TwoStagePipelineBasedTaskExecutor.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Collections\SafeEnumerator.cs" />
|
||||
<Compile Include="UserControls\BusyIndicator.xaml.cs">
|
||||
<DependentUpon>BusyIndicator.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UserControls\CirclePointRingLoading.cs" />
|
||||
<Compile Include="UserControls\ParameterNodeTreeViewControl.xaml.cs">
|
||||
<DependentUpon>ParameterNodeTreeViewControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Dependencies\Newtonsoft.Json.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Dialogs\PresetGroupSaveDialog.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="UserControls\BusyIndicator.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="UserControls\ParameterNodeTreeViewControl.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,647 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\DataLogs\Core\TreeNode.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-01
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief Reconstructed to support rich functions.
|
||||
*
|
||||
* @details
|
||||
* All functions to operate the TreeView are integrated into one class, which
|
||||
* also makes it meet the MVVM coding pattern.
|
||||
* *****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Sicentury.Core.EventArgs;
|
||||
|
||||
namespace Sicentury.Core.Tree
|
||||
{
|
||||
public class TreeNode : BindableBase
|
||||
{
|
||||
#region Variables
|
||||
|
||||
/// <summary>
|
||||
/// 当末端的节点选择属性发生变化时触发此事件。
|
||||
/// </summary>
|
||||
public event EventHandler<TreeNodeSelectionChangedEventArgs> TerminalNodeSelectionChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 当子节点中有元素发生变化时触发事件。
|
||||
/// </summary>
|
||||
public event EventHandler<NotifyCollectionChangedEventArgs> ChildNodesChanged;
|
||||
|
||||
private bool? _isSelected = false;
|
||||
private double _averageValue;
|
||||
private double _minValue;
|
||||
private double _maxValue;
|
||||
private bool _isExpanded;
|
||||
private bool _isMatch = true;
|
||||
private string _filterKeyword;
|
||||
private Visibility _visibility = Visibility.Visible;
|
||||
private int _totalTerminalCount;
|
||||
private int _selectedTerminalCount;
|
||||
|
||||
/// <summary>
|
||||
/// 挂起更新操作时的变量锁,防止多线程问题。
|
||||
/// </summary>
|
||||
private readonly object _suspendUpdateLocker;
|
||||
|
||||
/// <summary>
|
||||
/// 时否挂起更新操作。
|
||||
/// </summary>
|
||||
private bool _isUpdateSuspended;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public TreeNode(string name)
|
||||
{
|
||||
_suspendUpdateLocker = new object();
|
||||
_isUpdateSuspended = false;
|
||||
|
||||
Name = name;
|
||||
//RawData = new List<ParameterNodePoint>();
|
||||
MaxTerminalSelectionAllowed = -1;
|
||||
ChildNodes = new TreeNodeCollection(this);
|
||||
ChildNodes.TerminalNodeSelectionChanged += OnTerminalNodeSelectionChanged;
|
||||
ChildNodes.CollectionChanged += ChildNodesOnCollectionChanged;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 当前树中被选中的终端节点的数量。
|
||||
/// </summary>
|
||||
public int SelectedTerminalCount
|
||||
{
|
||||
get => _selectedTerminalCount;
|
||||
private set => Set(ref _selectedTerminalCount, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前树中终端节点的总数量。
|
||||
/// </summary>
|
||||
public int TotalTerminalCount
|
||||
{
|
||||
get => _totalTerminalCount;
|
||||
private set => Set(ref _totalTerminalCount, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回允许的最大终端节点选中数量。
|
||||
/// <para>-1表示可选中所有终端节点。</para>
|
||||
/// </summary>
|
||||
public int MaxTerminalSelectionAllowed { get; set; }
|
||||
|
||||
public bool? IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
set
|
||||
{
|
||||
if (value == _isSelected)
|
||||
{
|
||||
OnPropertyChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
var snapshot = _isSelected;
|
||||
Set(ref _isSelected, value);
|
||||
|
||||
// 仅当该节点未最末端节点时触发事件。
|
||||
var cancelEventArgs = new TreeNodeSelectionChangedEventArgs(this, snapshot, value);
|
||||
RaiseTerminalNodeSelectionChangedEvent(cancelEventArgs);
|
||||
if (cancelEventArgs.Cancel)
|
||||
{
|
||||
_isSelected = snapshot;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
|
||||
// 处理子节点的选择状态
|
||||
UpdateChildrenSelection();
|
||||
|
||||
// 处理我的状态。
|
||||
UpdateSelectionState(this);
|
||||
|
||||
// 处理父节点的选择状态
|
||||
UpdateParentSelection();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回包含完整路劲的节点名称。
|
||||
/// </summary>
|
||||
public string FullName => ToString();
|
||||
|
||||
public double AverageValue
|
||||
{
|
||||
get => _averageValue;
|
||||
private set => Set(ref _averageValue, value);
|
||||
}
|
||||
|
||||
public double MinValue
|
||||
{
|
||||
get => _minValue;
|
||||
private set => Set(ref _minValue, value);
|
||||
}
|
||||
|
||||
public double MaxValue
|
||||
{
|
||||
get => _maxValue;
|
||||
private set => Set(ref _maxValue, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否展开节点。
|
||||
/// </summary>
|
||||
public bool IsExpanded
|
||||
{
|
||||
get => _isExpanded;
|
||||
set => Set(ref _isExpanded, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含Filter指定的关键字。
|
||||
/// </summary>
|
||||
public bool IsMatch
|
||||
{
|
||||
get => _isMatch;
|
||||
set => Set(ref _isMatch, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回节点是否可见。
|
||||
/// </summary>
|
||||
public Visibility Visibility
|
||||
{
|
||||
get => _visibility;
|
||||
set
|
||||
{
|
||||
Set(ref _visibility, value);
|
||||
|
||||
if (IsTerminal)
|
||||
UpdateParentVisibility(ParentNode);
|
||||
}
|
||||
}
|
||||
|
||||
public TreeNode ParentNode { get; set; }
|
||||
|
||||
//public List<ParameterNodePoint> RawData { get; }
|
||||
|
||||
public Visibility IsVisibilityParentNode { get; set; }
|
||||
|
||||
public TreeNodeCollection ChildNodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 筛选器的关键字。
|
||||
/// </summary>
|
||||
public string FilterKeyWord
|
||||
{
|
||||
get => _filterKeyword;
|
||||
set => Set(ref _filterKeyword, value);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回我是否为最末端节点。
|
||||
/// </summary>
|
||||
public bool IsTerminal => (ChildNodes == null || ChildNodes.Count == 0);
|
||||
|
||||
/// <summary>
|
||||
/// 返回我是否属于一级节点。
|
||||
/// </summary>
|
||||
public bool IsTopLevel => ParentNode == null;
|
||||
|
||||
/// <summary>
|
||||
/// 返回我是否属于二级节点。
|
||||
/// </summary>
|
||||
public bool IsSecondLevel => ParentNode != null && ParentNode.ParentNode == null;
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否有终端节点被选中。
|
||||
/// </summary>
|
||||
public bool HasTerminalSelected => Flatten(true).FirstOrDefault(x => x.IsSelected == true) != null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 如果是末端节点,触发事件。
|
||||
/// </summary>
|
||||
private void RaiseTerminalNodeSelectionChangedEvent(TreeNodeSelectionChangedEventArgs e)
|
||||
{
|
||||
// 仅当该节点未最末端节点时触发事件。
|
||||
if (IsTerminal)
|
||||
TerminalNodeSelectionChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理子节点和父节点的选择状态。
|
||||
/// </summary>
|
||||
private void UpdateChildrenSelection()
|
||||
{
|
||||
if (_isSelected.HasValue == false)
|
||||
return;
|
||||
|
||||
// 刷新子节点的选择状态
|
||||
if (IsTerminal)
|
||||
return;
|
||||
|
||||
//! 遍历子节点时,本节点的_isSelected属性可能被改写。
|
||||
// 例如:某个终端节点的Selected改变时,会反向设置父节点的Selected属性;则接下来所有子节点赋值Selected属性时会使用新值。
|
||||
var fixedIsSelected = _isSelected;
|
||||
Flatten(true).ToList()
|
||||
.ForEach(x =>
|
||||
{
|
||||
if(x.IsMatch)
|
||||
x.SetSelectionProperty(fixedIsSelected);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新父节点的选择状态。
|
||||
/// </summary>
|
||||
public void UpdateParentSelection()
|
||||
{
|
||||
if (ParentNode == null)
|
||||
return;
|
||||
|
||||
// 递归更新IsSelected属性
|
||||
UpdateSelectionState(ParentNode);
|
||||
ParentNode.UpdateParentSelection();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新指定节点的IsSelected属性。
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
private static void UpdateSelectionState(TreeNode node)
|
||||
{
|
||||
if (node.IsTerminal)
|
||||
return;
|
||||
|
||||
// 刷新父节点的选择状态
|
||||
var selectionGroup = node.Flatten(true).GroupBy(x => x.IsSelected);
|
||||
var enumerable = selectionGroup.ToList();
|
||||
if (!enumerable.Any())
|
||||
return;
|
||||
|
||||
if (enumerable.Count() > 1)
|
||||
node.SetSelectionProperty(null);
|
||||
else if (enumerable.Count() == 1)
|
||||
{
|
||||
var ss = enumerable[0].Key;
|
||||
if (ss.HasValue)
|
||||
node.SetSelectionProperty(ss.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 非法情况
|
||||
Debugger.Break();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新父级节点的显示属性。
|
||||
/// </summary>
|
||||
private static void UpdateParentVisibility(TreeNode node)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// 刷新父节点的选择状态
|
||||
var selectionGroup = node.Flatten(true).GroupBy(x => x.Visibility);
|
||||
var enumerable = selectionGroup.ToList();
|
||||
if (!enumerable.Any())
|
||||
return;
|
||||
|
||||
if (enumerable.Count() > 1)
|
||||
// 如果终端节点存在多种情况,则一定显示本节点。
|
||||
node.Visibility = Visibility.Visible;
|
||||
else if (enumerable.Count == 1)
|
||||
{
|
||||
// 如果存在一种情况,则判断是全部为显示还是全部为折叠。
|
||||
|
||||
var ss = enumerable[0].Key;
|
||||
if (ss == Visibility.Visible)
|
||||
node.Visibility = Visibility.Visible;
|
||||
else
|
||||
node.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 非法情况
|
||||
Debugger.Break();
|
||||
}
|
||||
|
||||
|
||||
// 如果本节点已经是顶层节点,则退出
|
||||
if (node.ParentNode == null)
|
||||
break;
|
||||
|
||||
node = node.ParentNode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当终端节点被选则或取消选择时触发此事件。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnTerminalNodeSelectionChanged(object sender, TreeNodeSelectionChangedEventArgs e)
|
||||
{
|
||||
//! 在树的根部检查终端节点选中数是否超过最大限制
|
||||
if (IsTopLevel)
|
||||
{
|
||||
if (MaxTerminalSelectionAllowed > -1)
|
||||
if (GetSelectedTerminalCount() > MaxTerminalSelectionAllowed)
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateTerminalNodeCountInfo();
|
||||
}
|
||||
|
||||
TerminalNodeSelectionChanged?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当ChildNodes元素发生变化时触发此事件。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ChildNodesOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
/*
|
||||
* 如果当前节点是顶层节点,则统计终端节点总数,否则继续向父级节点传递事件。
|
||||
*/
|
||||
|
||||
if (IsTopLevel)
|
||||
UpdateTerminalNodeCountInfo();
|
||||
|
||||
ChildNodesChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新终端节点数量信息。
|
||||
/// </summary>
|
||||
private void UpdateTerminalNodeCountInfo()
|
||||
{
|
||||
lock (_suspendUpdateLocker)
|
||||
{
|
||||
if (_isUpdateSuspended)
|
||||
return;
|
||||
|
||||
SelectedTerminalCount = GetSelectedTerminalCount();
|
||||
TotalTerminalCount = ChildNodes.Sum(x => x.Flatten(true).ToList().Count);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 该方法用于Tree内部设置<see cref="IsSelected"/>属性的状态。
|
||||
/// </summary>
|
||||
/// <param name="isSelected"></param>
|
||||
private void SetSelectionProperty(bool? isSelected)
|
||||
{
|
||||
var snapshot = _isSelected;
|
||||
_isSelected = isSelected;
|
||||
|
||||
var args = new TreeNodeSelectionChangedEventArgs(this, snapshot, _isSelected);
|
||||
RaiseTerminalNodeSelectionChangedEvent(args);
|
||||
if (args.Cancel)
|
||||
_isSelected = snapshot;
|
||||
|
||||
OnPropertyChanged(nameof(IsSelected));
|
||||
|
||||
if (IsTerminal)
|
||||
UpdateParentSelection();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找指定完整路径名称的末端节点。
|
||||
/// </summary>
|
||||
/// <param name="fullName"></param>
|
||||
/// <returns></returns>
|
||||
public TreeNode FindTerminalByFullName(string fullName)
|
||||
{
|
||||
return Flatten(true).FirstOrDefault(x => x.FullName == fullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定层级的节点。
|
||||
/// </summary>
|
||||
/// <param name="level">0-based层级,0表示Tree的根节点。</param>
|
||||
/// <returns></returns>
|
||||
public TreeNode GetNodeByLevel(int level)
|
||||
{
|
||||
var list = new List<TreeNode>();
|
||||
list.Add(this);
|
||||
while (true)
|
||||
{
|
||||
if (ParentNode != null)
|
||||
list.Add(this.ParentNode);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (level >= list.Count)
|
||||
return null;
|
||||
|
||||
return list[level];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取被选中的终端节点的数量。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetSelectedTerminalCount()
|
||||
{
|
||||
return Flatten(true).Where(x => x.IsSelected == true).ToList().Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数中的节点转换为节点数组。
|
||||
/// </summary>
|
||||
/// <param name="terminalOnly">是否仅枚举最末端节点。</param>
|
||||
/// <para>更新子节点的Selected属性时,需要同时更新中间节点的属性;更新父节点时,只评估终端节点的Selected属性。</para>
|
||||
/// <returns></returns>
|
||||
public List<TreeNode> Flatten(bool terminalOnly)
|
||||
{
|
||||
if (ChildNodes == null || ChildNodes.Count <= 0)
|
||||
return new List<TreeNode>(new[] { this });
|
||||
|
||||
var lst = ChildNodes.SelectMany(x => x.Flatten(terminalOnly)).ToList();
|
||||
if(!terminalOnly)
|
||||
lst.Add(this);
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除统计数据。
|
||||
/// </summary>
|
||||
public void ClearStatistic()
|
||||
{
|
||||
MinValue = double.NaN;
|
||||
MaxValue = double.NaN;
|
||||
AverageValue = double.NaN;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置统计数据。
|
||||
/// </summary>
|
||||
/// <param name="min"></param>
|
||||
/// <param name="max"></param>
|
||||
/// <param name="average"></param>
|
||||
public void SetStatistic(double min, double max, double average)
|
||||
{
|
||||
MinValue = min;
|
||||
MaxValue = max;
|
||||
AverageValue = average;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消所有节点选择状态。
|
||||
/// </summary>
|
||||
public void UnselectAll()
|
||||
{
|
||||
SuspendUpdate();
|
||||
Flatten(true).ForEach(x => x.IsSelected = false);
|
||||
ResumeUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择所有节点。
|
||||
/// </summary>
|
||||
public void SelectAll()
|
||||
{
|
||||
SuspendUpdate();
|
||||
Flatten(true).ForEach(x => x.IsSelected = true);
|
||||
ResumeUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 折叠所有节点。
|
||||
/// </summary>
|
||||
public void CollapseAll()
|
||||
{
|
||||
Flatten(false).ForEach(x => x.IsExpanded = false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 展开所有节点。
|
||||
/// </summary>
|
||||
public void ExpandAll()
|
||||
{
|
||||
Flatten(false).ForEach(x => x.IsExpanded = true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示所有节点。
|
||||
/// </summary>
|
||||
public void ShowAll()
|
||||
{
|
||||
Flatten(true).ForEach(x => x.Visibility = Visibility.Visible);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示选中的项目。
|
||||
/// </summary>
|
||||
public void ShowSelectedOnly()
|
||||
{
|
||||
Flatten(true).Where(x => x.IsSelected == false).ToList()
|
||||
.ForEach(x => x.Visibility = Visibility.Collapsed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用筛选器。
|
||||
/// </summary>
|
||||
/// <param name="keyWord"></param>
|
||||
public void ApplyFilter(string keyWord)
|
||||
{
|
||||
//! 自顶向下遍历,仅需关心子节点状态。
|
||||
|
||||
// 如果父节点匹配,则我强制匹配。
|
||||
IsMatch = (ParentNode != null && ParentNode.IsMatch) || Name.ToLower().Contains(keyWord.ToLower());
|
||||
FilterKeyWord = keyWord;
|
||||
|
||||
// 如果是终端节点,则仅检查是否匹配关键字,然后退出
|
||||
if (IsTerminal)
|
||||
return;
|
||||
|
||||
// 否则检查我的名称是否匹配关键字,并检查我的子节点中是否有匹配关键字的节点,如果有,则我也要显示。
|
||||
foreach (var node in ChildNodes)
|
||||
{
|
||||
node.ApplyFilter(keyWord);
|
||||
}
|
||||
|
||||
var isMatchedNodes = Flatten(false).Where(x => x.IsMatch).ToList();
|
||||
if (isMatchedNodes.Any())
|
||||
IsMatch = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除筛选器。
|
||||
/// </summary>
|
||||
public void ClearFilter()
|
||||
{
|
||||
IsMatch = true;
|
||||
FilterKeyWord = "";
|
||||
|
||||
if (IsTerminal)
|
||||
return;
|
||||
|
||||
foreach (var node in ChildNodes)
|
||||
{
|
||||
node.ClearFilter();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 挂起TreeView视图更新。
|
||||
/// <para>通常在后端对节点Selected属性操作时,挂起视图更新,以提高性能。</para>
|
||||
/// </summary>
|
||||
public void SuspendUpdate()
|
||||
{
|
||||
lock (_suspendUpdateLocker)
|
||||
{
|
||||
_isUpdateSuspended = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复TreeView视图更新。
|
||||
/// <para>通常在后端对节点Selected属性操作时,挂起视图更新,以提高性能。</para>
|
||||
/// <para>恢复视图更新后,主动更新节点数量统计值。</para>
|
||||
/// </summary>
|
||||
public void ResumeUpdate()
|
||||
{
|
||||
lock (_suspendUpdateLocker)
|
||||
{
|
||||
_isUpdateSuspended = false;
|
||||
}
|
||||
|
||||
UpdateTerminalNodeCountInfo();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
// 完整路径中删除根节点的名称,以确保FullName匹配系统中的定义。
|
||||
return (ParentNode?.ParentNode == null) ? Name : $"{ParentNode}.{Name}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Sicentury.Core.Collections;
|
||||
using Sicentury.Core.EventArgs;
|
||||
|
||||
namespace Sicentury.Core.Tree
|
||||
{
|
||||
public class TreeNodeCollection : ObservableRangeCollection<TreeNode>
|
||||
{
|
||||
#region Variables
|
||||
|
||||
public event EventHandler<TreeNodeSelectionChangedEventArgs> TerminalNodeSelectionChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public TreeNodeCollection(TreeNode parent, IEnumerable<TreeNode> collection) : base(collection)
|
||||
{
|
||||
Parent = parent;
|
||||
if (collection != null)
|
||||
{
|
||||
var list = collection.ToList();
|
||||
foreach (var subNode in list)
|
||||
{
|
||||
subNode.ParentNode = Parent;
|
||||
subNode.TerminalNodeSelectionChanged += SubNodeOnTerminalNodeSelectionChanged;
|
||||
subNode.ChildNodesChanged += SubNodeOnChildNodesChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TreeNodeCollection(TreeNode parent) : this(parent, new TreeNode[0])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 父节点。
|
||||
/// </summary>
|
||||
public TreeNode Parent { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override void AddRange(IEnumerable<TreeNode> collection)
|
||||
{
|
||||
var lst = collection?.ToList();
|
||||
lst?.ForEach(subNode =>
|
||||
{
|
||||
subNode.ParentNode = Parent;
|
||||
subNode.TerminalNodeSelectionChanged += SubNodeOnTerminalNodeSelectionChanged;
|
||||
subNode.ChildNodesChanged += SubNodeOnChildNodesChanged;
|
||||
});
|
||||
|
||||
base.AddRange(lst);
|
||||
}
|
||||
|
||||
protected override void InsertItem(int index, TreeNode subNode)
|
||||
{
|
||||
if (subNode == null)
|
||||
return;
|
||||
|
||||
subNode.ParentNode = Parent;
|
||||
subNode.TerminalNodeSelectionChanged += SubNodeOnTerminalNodeSelectionChanged;
|
||||
subNode.ChildNodesChanged += SubNodeOnChildNodesChanged;
|
||||
|
||||
base.InsertItem(index, subNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当子节点触发TerminalNodeSelectionChanged事件时调用该方法,通知父节点。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SubNodeOnTerminalNodeSelectionChanged(object sender, TreeNodeSelectionChangedEventArgs e)
|
||||
{
|
||||
TerminalNodeSelectionChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当某个节点的ChildNodes列表发生变化时调用该方法,通知父节点。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SubNodeOnChildNodesChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
OnCollectionChanged(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Sicentury.Core.Tree
|
||||
{
|
||||
public class TreeNodeSelectionGroupInfo
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public TreeNodeSelectionGroupInfo()
|
||||
{
|
||||
SelectedTerminalNodes = new List<string>();
|
||||
}
|
||||
|
||||
public TreeNodeSelectionGroupInfo(IEnumerable<string> collection)
|
||||
{
|
||||
SelectedTerminalNodes = new List<string>(collection);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
|
||||
public List<string> SelectedTerminalNodes
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 从指定的文件恢复节点选择
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
internal static void RecoveryFromJsonFile(string fileName, TreeNode treeRoot)
|
||||
{
|
||||
if (treeRoot == null)
|
||||
throw new ArgumentNullException(nameof(treeRoot));
|
||||
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
throw new ArgumentException("the file name is not specified.", nameof(fileName));
|
||||
|
||||
var json = File.ReadAllText(fileName);
|
||||
var info = JsonConvert.DeserializeObject<TreeNodeSelectionGroupInfo>(json);
|
||||
|
||||
// 如果没有正确恢复Preset Group文件,则提示错误
|
||||
if (info.SelectedTerminalNodes == null)
|
||||
throw new JsonException($"the file of preset group might be incorrect.");
|
||||
|
||||
treeRoot.UnselectAll();
|
||||
|
||||
treeRoot.SuspendUpdate();
|
||||
var flattenTree = treeRoot.Flatten(true);
|
||||
info.SelectedTerminalNodes.ForEach(x =>
|
||||
{
|
||||
var matched = flattenTree.FirstOrDefault(f => f.ToString() == x.ToString());
|
||||
if (matched != null)
|
||||
matched.IsSelected = true;
|
||||
});
|
||||
treeRoot.ResumeUpdate();
|
||||
}
|
||||
|
||||
|
||||
internal static void SaveToJsonFile(string fileName, TreeNode treeRoot)
|
||||
{
|
||||
if (treeRoot == null)
|
||||
throw new ArgumentNullException(nameof(treeRoot));
|
||||
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
throw new ArgumentException("the file name is not specified.", nameof(fileName));
|
||||
|
||||
var selectedNodes =
|
||||
treeRoot.Flatten(true)
|
||||
.Where(x => x.IsSelected == true)
|
||||
.Select(x=>x.ToString());
|
||||
var info = new TreeNodeSelectionGroupInfo(selectedNodes);
|
||||
var json = JsonConvert.SerializeObject(info, Formatting.Indented);
|
||||
File.WriteAllText(fileName, json);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,418 @@
|
||||
<UserControl
|
||||
x:Class="Sicentury.Core.UserControls.BusyIndicator"
|
||||
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:local="clr-namespace:Sicentury.Core.UserControls"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="150"
|
||||
d:DesignWidth="230"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<Style TargetType="{x:Type local:CirclePointRingLoading}">
|
||||
<Setter Property="Foreground" Value="#FFFFFFFF" />
|
||||
<Setter Property="IsHitTestVisible" Value="False" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="MinHeight" Value="20" />
|
||||
<Setter Property="MinWidth" Value="20" />
|
||||
<Setter Property="Height" Value="60" />
|
||||
<Setter Property="Width" Value="60" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type local:CirclePointRingLoading}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}">
|
||||
<FrameworkElement.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style x:Key="ProgressRingEllipseStyle" TargetType="{x:Type Ellipse}">
|
||||
<Setter Property="Opacity" Value="0" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</FrameworkElement.Resources>
|
||||
<Grid
|
||||
Name="Ring"
|
||||
MaxWidth="{Binding MaxSideLength, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
MaxHeight="{Binding MaxSideLength, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
FlowDirection="LeftToRight"
|
||||
RenderTransformOrigin=".5,.5"
|
||||
Visibility="Visible">
|
||||
<Canvas RenderTransformOrigin=".5,.5">
|
||||
<UIElement.RenderTransform>
|
||||
<RotateTransform x:Name="E1R" />
|
||||
</UIElement.RenderTransform>
|
||||
<Ellipse
|
||||
Name="E1"
|
||||
Width="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Height="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Margin="{Binding EllipseOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Style="{StaticResource ProgressRingEllipseStyle}" />
|
||||
</Canvas>
|
||||
<Canvas RenderTransformOrigin=".5,.5">
|
||||
<UIElement.RenderTransform>
|
||||
<RotateTransform x:Name="E2R" />
|
||||
</UIElement.RenderTransform>
|
||||
<Ellipse
|
||||
Name="E2"
|
||||
Width="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Height="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Margin="{Binding EllipseOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Style="{StaticResource ProgressRingEllipseStyle}" />
|
||||
</Canvas>
|
||||
<Canvas RenderTransformOrigin=".5,.5">
|
||||
<UIElement.RenderTransform>
|
||||
<RotateTransform x:Name="E3R" />
|
||||
</UIElement.RenderTransform>
|
||||
<Ellipse
|
||||
Name="E3"
|
||||
Width="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Height="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Margin="{Binding EllipseOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Style="{StaticResource ProgressRingEllipseStyle}" />
|
||||
</Canvas>
|
||||
<Canvas RenderTransformOrigin=".5,.5">
|
||||
<UIElement.RenderTransform>
|
||||
<RotateTransform x:Name="E4R" />
|
||||
</UIElement.RenderTransform>
|
||||
<Ellipse
|
||||
Name="E4"
|
||||
Width="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Height="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Margin="{Binding EllipseOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Style="{StaticResource ProgressRingEllipseStyle}" />
|
||||
</Canvas>
|
||||
<Canvas RenderTransformOrigin=".5,.5">
|
||||
<UIElement.RenderTransform>
|
||||
<RotateTransform x:Name="E5R" />
|
||||
</UIElement.RenderTransform>
|
||||
<Ellipse
|
||||
Name="E5"
|
||||
Width="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Height="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Margin="{Binding EllipseOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Style="{StaticResource ProgressRingEllipseStyle}" />
|
||||
</Canvas>
|
||||
<Canvas
|
||||
Name="SixthCircle"
|
||||
RenderTransformOrigin=".5,.5"
|
||||
Visibility="Collapsed">
|
||||
<UIElement.RenderTransform>
|
||||
<RotateTransform x:Name="E6R" />
|
||||
</UIElement.RenderTransform>
|
||||
<Ellipse
|
||||
Name="E6"
|
||||
Width="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Height="{Binding EllipseDiameter, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Margin="{Binding EllipseOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Style="{StaticResource ProgressRingEllipseStyle}" />
|
||||
</Canvas>
|
||||
</Grid>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="SizeStates">
|
||||
<VisualState x:Name="Large">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames
|
||||
Storyboard.TargetName="SixthCircle"
|
||||
Storyboard.TargetProperty="Visibility"
|
||||
Duration="0">
|
||||
<DiscreteObjectKeyFrame KeyTime="0">
|
||||
<ObjectKeyFrame.Value>
|
||||
<Visibility>Visible</Visibility>
|
||||
</ObjectKeyFrame.Value>
|
||||
</DiscreteObjectKeyFrame>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Small" />
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup x:Name="ActiveStates">
|
||||
<VisualState x:Name="Inactive" />
|
||||
<VisualState x:Name="Active">
|
||||
<Storyboard RepeatBehavior="Forever">
|
||||
<ObjectAnimationUsingKeyFrames
|
||||
Storyboard.TargetName="Ring"
|
||||
Storyboard.TargetProperty="Visibility"
|
||||
Duration="0">
|
||||
<DiscreteObjectKeyFrame KeyTime="0">
|
||||
<ObjectKeyFrame.Value>
|
||||
<Visibility>Visible</Visibility>
|
||||
</ObjectKeyFrame.Value>
|
||||
</DiscreteObjectKeyFrame>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="0"
|
||||
Storyboard.TargetName="E1"
|
||||
Storyboard.TargetProperty="Opacity">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.21" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.22" Value="0" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.47" Value="0" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.167"
|
||||
Storyboard.TargetName="E2"
|
||||
Storyboard.TargetProperty="Opacity">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.21" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.22" Value="0" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.47" Value="0" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.334"
|
||||
Storyboard.TargetName="E3"
|
||||
Storyboard.TargetProperty="Opacity">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.21" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.22" Value="0" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.47" Value="0" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.501"
|
||||
Storyboard.TargetName="E4"
|
||||
Storyboard.TargetProperty="Opacity">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.21" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.22" Value="0" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.47" Value="0" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.668"
|
||||
Storyboard.TargetName="E5"
|
||||
Storyboard.TargetProperty="Opacity">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.21" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.22" Value="0" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.47" Value="0" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.835"
|
||||
Storyboard.TargetName="E6"
|
||||
Storyboard.TargetProperty="Opacity">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.21" Value="1" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.22" Value="0" />
|
||||
<DiscreteDoubleKeyFrame KeyTime="0:0:3.47" Value="0" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="0"
|
||||
Storyboard.TargetName="E1R"
|
||||
Storyboard.TargetProperty="Angle">
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.13,0.21,0.1,0.7"
|
||||
KeyTime="0"
|
||||
Value="-110" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.02,0.33,0.38,0.77"
|
||||
KeyTime="0:0:0.433"
|
||||
Value="10" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="93" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.57,0.17,0.95,0.75"
|
||||
KeyTime="0:0:1.617"
|
||||
Value="205" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0.19,0.07,0.72"
|
||||
KeyTime="0:0:2.017"
|
||||
Value="357" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:2.783" Value="439" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0,0.95,0.37"
|
||||
KeyTime="0:0:3.217"
|
||||
Value="585" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.167"
|
||||
Storyboard.TargetName="E2R"
|
||||
Storyboard.TargetProperty="Angle">
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.13,0.21,0.1,0.7"
|
||||
KeyTime="0"
|
||||
Value="-116" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.02,0.33,0.38,0.77"
|
||||
KeyTime="0:0:0.433"
|
||||
Value="4" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="87" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.57,0.17,0.95,0.75"
|
||||
KeyTime="0:0:1.617"
|
||||
Value="199" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0.19,0.07,0.72"
|
||||
KeyTime="0:0:2.017"
|
||||
Value="351" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:2.783" Value="433" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0,0.95,0.37"
|
||||
KeyTime="0:0:3.217"
|
||||
Value="579" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.334"
|
||||
Storyboard.TargetName="E3R"
|
||||
Storyboard.TargetProperty="Angle">
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.13,0.21,0.1,0.7"
|
||||
KeyTime="0"
|
||||
Value="-122" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.02,0.33,0.38,0.77"
|
||||
KeyTime="0:0:0.433"
|
||||
Value="-2" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="81" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.57,0.17,0.95,0.75"
|
||||
KeyTime="0:0:1.617"
|
||||
Value="193" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0.19,0.07,0.72"
|
||||
KeyTime="0:0:2.017"
|
||||
Value="345" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:2.783" Value="427" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0,0.95,0.37"
|
||||
KeyTime="0:0:3.217"
|
||||
Value="573" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.501"
|
||||
Storyboard.TargetName="E4R"
|
||||
Storyboard.TargetProperty="Angle">
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.13,0.21,0.1,0.7"
|
||||
KeyTime="0"
|
||||
Value="-128" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.02,0.33,0.38,0.77"
|
||||
KeyTime="0:0:0.433"
|
||||
Value="-8" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="75" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.57,0.17,0.95,0.75"
|
||||
KeyTime="0:0:1.617"
|
||||
Value="187" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0.19,0.07,0.72"
|
||||
KeyTime="0:0:2.017"
|
||||
Value="339" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:2.783" Value="421" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0,0.95,0.37"
|
||||
KeyTime="0:0:3.217"
|
||||
Value="567" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.668"
|
||||
Storyboard.TargetName="E5R"
|
||||
Storyboard.TargetProperty="Angle">
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.13,0.21,0.1,0.7"
|
||||
KeyTime="0"
|
||||
Value="-134" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.02,0.33,0.38,0.77"
|
||||
KeyTime="0:0:0.433"
|
||||
Value="-14" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="69" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.57,0.17,0.95,0.75"
|
||||
KeyTime="0:0:1.617"
|
||||
Value="181" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0.19,0.07,0.72"
|
||||
KeyTime="0:0:2.017"
|
||||
Value="331" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:2.783" Value="415" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0,0.95,0.37"
|
||||
KeyTime="0:0:3.217"
|
||||
Value="561" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00.835"
|
||||
Storyboard.TargetName="E6R"
|
||||
Storyboard.TargetProperty="Angle">
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.13,0.21,0.1,0.7"
|
||||
KeyTime="0"
|
||||
Value="-140" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.02,0.33,0.38,0.77"
|
||||
KeyTime="0:0:0.433"
|
||||
Value="-20" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="63" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0.57,0.17,0.95,0.75"
|
||||
KeyTime="0:0:1.617"
|
||||
Value="175" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0.19,0.07,0.72"
|
||||
KeyTime="0:0:2.017"
|
||||
Value="325" />
|
||||
<SplineDoubleKeyFrame KeyTime="0:0:2.783" Value="409" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeySpline="0,0,0.95,0.37"
|
||||
KeyTime="0:0:3.217"
|
||||
Value="555" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Border>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
||||
<local:CirclePointRingLoading
|
||||
Width="20"
|
||||
Height="20"
|
||||
HorizontalAlignment="Left"
|
||||
EllipseDiameter="3"
|
||||
Foreground="#3ca9fe"
|
||||
IsActive="True"
|
||||
IsLarge="True"
|
||||
Visibility="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=Visibility}" />
|
||||
<StackPanel>
|
||||
<TextBlock
|
||||
Margin="10,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="10"
|
||||
Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=Message}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<Button
|
||||
x:Name="btnCancel"
|
||||
Grid.Row="1"
|
||||
Width="60"
|
||||
Height="25"
|
||||
Margin="0,5,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Click="BtnCancel_OnClick"
|
||||
Content="Cancel"
|
||||
FontSize="8" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,70 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\Core\UserControls\BusyIndicator.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-03
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief Reconstructed to support rich functions.
|
||||
*
|
||||
* @details
|
||||
* *****************************************************************************/
|
||||
|
||||
|
||||
using System.Windows;
|
||||
|
||||
namespace Sicentury.Core.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for BusyIndicator.xaml
|
||||
/// </summary>
|
||||
public partial class BusyIndicator
|
||||
{
|
||||
public BusyIndicator()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
|
||||
"Message", typeof(string), typeof(BusyIndicator), new PropertyMetadata(default(string)));
|
||||
|
||||
public string Message
|
||||
{
|
||||
get => (string)GetValue(MessageProperty);
|
||||
set => SetValue(MessageProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Routed Events
|
||||
|
||||
// Register a custom routed event using the Bubble routing strategy.
|
||||
public static readonly RoutedEvent CanceledEvent = EventManager.RegisterRoutedEvent(
|
||||
name: nameof(Canceled),
|
||||
routingStrategy: RoutingStrategy.Bubble,
|
||||
handlerType: typeof(RoutedEventHandler),
|
||||
ownerType: typeof(ParameterNodeTreeViewControl));
|
||||
|
||||
// Provide CLR accessors for assigning an event handler.
|
||||
public event RoutedEventHandler Canceled
|
||||
{
|
||||
add => AddHandler(CanceledEvent, value);
|
||||
remove => RemoveHandler(CanceledEvent, value);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(CanceledEvent));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Sicentury.Core.UserControls
|
||||
{
|
||||
[TemplateVisualState(Name = "Large", GroupName = "SizeStates")]
|
||||
[TemplateVisualState(Name = "Small", GroupName = "SizeStates")]
|
||||
[TemplateVisualState(Name = "Inactive", GroupName = "ActiveStates")]
|
||||
[TemplateVisualState(Name = "Active", GroupName = "ActiveStates")]
|
||||
public class CirclePointRingLoading : Control
|
||||
{
|
||||
// Token: 0x17000001 RID: 1
|
||||
// (get) Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
|
||||
// (set) Token: 0x06000002 RID: 2 RVA: 0x00002072 File Offset: 0x00000272
|
||||
public double BindableWidth
|
||||
{
|
||||
get => (double)base.GetValue(CirclePointRingLoading.BindableWidthProperty);
|
||||
private set => base.SetValue(CirclePointRingLoading.BindableWidthProperty, value);
|
||||
}
|
||||
|
||||
// Token: 0x06000003 RID: 3 RVA: 0x00002088 File Offset: 0x00000288
|
||||
private static void BindableWidthCallback(DependencyObject dependencyObject,
|
||||
DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var circlePointRingLoading = dependencyObject as CirclePointRingLoading;
|
||||
var flag = circlePointRingLoading == null;
|
||||
if (!flag)
|
||||
{
|
||||
circlePointRingLoading.SetEllipseDiameter((double)e.NewValue);
|
||||
circlePointRingLoading.SetEllipseOffset((double)e.NewValue);
|
||||
circlePointRingLoading.SetMaxSideLength((double)e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000004 RID: 4 RVA: 0x000020E0 File Offset: 0x000002E0
|
||||
private void SetEllipseDiameter(double width)
|
||||
{
|
||||
this.EllipseDiameter = width / 8.0;
|
||||
}
|
||||
|
||||
// Token: 0x06000005 RID: 5 RVA: 0x000020F5 File Offset: 0x000002F5
|
||||
private void SetEllipseOffset(double width)
|
||||
{
|
||||
this.EllipseOffset = new Thickness(0.0, width / 2.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
// Token: 0x06000006 RID: 6 RVA: 0x0000212A File Offset: 0x0000032A
|
||||
private void SetMaxSideLength(double width)
|
||||
{
|
||||
this.MaxSideLength = ((width <= 20.0) ? 20.0 : width);
|
||||
}
|
||||
|
||||
// Token: 0x17000002 RID: 2
|
||||
// (get) Token: 0x06000007 RID: 7 RVA: 0x0000214C File Offset: 0x0000034C
|
||||
// (set) Token: 0x06000008 RID: 8 RVA: 0x0000216E File Offset: 0x0000036E
|
||||
public bool IsActive
|
||||
{
|
||||
get => (bool)base.GetValue(CirclePointRingLoading.IsActiveProperty);
|
||||
set => base.SetValue(CirclePointRingLoading.IsActiveProperty, value);
|
||||
}
|
||||
|
||||
// Token: 0x06000009 RID: 9 RVA: 0x00002184 File Offset: 0x00000384
|
||||
private static void IsActiveChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var circlePointRingLoading = sender as CirclePointRingLoading;
|
||||
var flag = circlePointRingLoading == null;
|
||||
if (!flag)
|
||||
{
|
||||
circlePointRingLoading.UpdateActiveState();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600000A RID: 10 RVA: 0x000021AC File Offset: 0x000003AC
|
||||
private void UpdateActiveState()
|
||||
{
|
||||
var isActive = this.IsActive;
|
||||
if (isActive)
|
||||
{
|
||||
VisualStateManager.GoToState(this, this.StateActive, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
VisualStateManager.GoToState(this, this.StateInActive, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000003 RID: 3
|
||||
// (get) Token: 0x0600000B RID: 11 RVA: 0x000021E4 File Offset: 0x000003E4
|
||||
// (set) Token: 0x0600000C RID: 12 RVA: 0x00002206 File Offset: 0x00000406
|
||||
public bool IsLarge
|
||||
{
|
||||
get => (bool)base.GetValue(CirclePointRingLoading.IsLargeProperty);
|
||||
set => base.SetValue(CirclePointRingLoading.IsLargeProperty, value);
|
||||
}
|
||||
|
||||
// Token: 0x0600000D RID: 13 RVA: 0x0000221C File Offset: 0x0000041C
|
||||
private static void IsLargeChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var circlePointRingLoading = sender as CirclePointRingLoading;
|
||||
var flag = circlePointRingLoading == null;
|
||||
if (!flag)
|
||||
{
|
||||
circlePointRingLoading.UpdateLargeState();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600000E RID: 14 RVA: 0x00002244 File Offset: 0x00000444
|
||||
private void UpdateLargeState()
|
||||
{
|
||||
var isLarge = this.IsLarge;
|
||||
if (isLarge)
|
||||
{
|
||||
VisualStateManager.GoToState(this, this.StateLarge, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
VisualStateManager.GoToState(this, this.StateSmall, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000004 RID: 4
|
||||
// (get) Token: 0x0600000F RID: 15 RVA: 0x0000227C File Offset: 0x0000047C
|
||||
// (set) Token: 0x06000010 RID: 16 RVA: 0x0000229E File Offset: 0x0000049E
|
||||
public double MaxSideLength
|
||||
{
|
||||
get => (double)base.GetValue(CirclePointRingLoading.MaxSideLengthProperty);
|
||||
set => base.SetValue(CirclePointRingLoading.MaxSideLengthProperty, value);
|
||||
}
|
||||
|
||||
// Token: 0x17000005 RID: 5
|
||||
// (get) Token: 0x06000011 RID: 17 RVA: 0x000022B4 File Offset: 0x000004B4
|
||||
// (set) Token: 0x06000012 RID: 18 RVA: 0x000022D6 File Offset: 0x000004D6
|
||||
public double EllipseDiameter
|
||||
{
|
||||
get => (double)base.GetValue(CirclePointRingLoading.EllipseDiameterProperty);
|
||||
set => base.SetValue(CirclePointRingLoading.EllipseDiameterProperty, value);
|
||||
}
|
||||
|
||||
// Token: 0x17000006 RID: 6
|
||||
// (get) Token: 0x06000013 RID: 19 RVA: 0x000022EC File Offset: 0x000004EC
|
||||
// (set) Token: 0x06000014 RID: 20 RVA: 0x0000230E File Offset: 0x0000050E
|
||||
public Thickness EllipseOffset
|
||||
{
|
||||
get => (Thickness)base.GetValue(CirclePointRingLoading.EllipseOffsetProperty);
|
||||
set => base.SetValue(CirclePointRingLoading.EllipseOffsetProperty, value);
|
||||
}
|
||||
|
||||
// Token: 0x06000015 RID: 21 RVA: 0x00002324 File Offset: 0x00000524
|
||||
public CirclePointRingLoading()
|
||||
{
|
||||
|
||||
|
||||
base.SizeChanged += new SizeChangedEventHandler((object argument0, SizeChangedEventArgs argument1) =>
|
||||
this.BindableWidth = base.ActualWidth);
|
||||
}
|
||||
|
||||
// Token: 0x06000016 RID: 22 RVA: 0x00002378 File Offset: 0x00000578
|
||||
static CirclePointRingLoading()
|
||||
{
|
||||
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(CirclePointRingLoading),
|
||||
new FrameworkPropertyMetadata(typeof(CirclePointRingLoading)));
|
||||
UIElement.VisibilityProperty.OverrideMetadata(typeof(CirclePointRingLoading), new FrameworkPropertyMetadata(
|
||||
delegate (DependencyObject ringObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var flag = e.NewValue != e.OldValue;
|
||||
if (flag)
|
||||
{
|
||||
var circlePointRingLoading = (CirclePointRingLoading)ringObject;
|
||||
var flag2 = (Visibility)e.NewValue > Visibility.Visible;
|
||||
if (flag2)
|
||||
{
|
||||
circlePointRingLoading.SetCurrentValue(CirclePointRingLoading.IsActiveProperty, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
circlePointRingLoading.IsActive = true;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// Token: 0x06000017 RID: 23 RVA: 0x00002531 File Offset: 0x00000731
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
this.UpdateLargeState();
|
||||
this.UpdateActiveState();
|
||||
}
|
||||
|
||||
// Token: 0x04000001 RID: 1
|
||||
private string StateActive = "Active";
|
||||
|
||||
// Token: 0x04000002 RID: 2
|
||||
private string StateInActive = "InActive";
|
||||
|
||||
// Token: 0x04000003 RID: 3
|
||||
private string StateLarge = "Large";
|
||||
|
||||
// Token: 0x04000004 RID: 4
|
||||
private string StateSmall = "Small";
|
||||
|
||||
// Token: 0x04000005 RID: 5
|
||||
public static readonly DependencyProperty BindableWidthProperty = DependencyProperty.Register("BindableWidth",
|
||||
typeof(double), typeof(CirclePointRingLoading),
|
||||
new PropertyMetadata(0.0, new PropertyChangedCallback(CirclePointRingLoading.BindableWidthCallback)));
|
||||
|
||||
// Token: 0x04000006 RID: 6
|
||||
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register("IsActive",
|
||||
typeof(bool), typeof(CirclePointRingLoading),
|
||||
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
new PropertyChangedCallback(CirclePointRingLoading.IsActiveChanged)));
|
||||
|
||||
// Token: 0x04000007 RID: 7
|
||||
public static readonly DependencyProperty IsLargeProperty = DependencyProperty.Register("IsLarge", typeof(bool),
|
||||
typeof(CirclePointRingLoading),
|
||||
new PropertyMetadata(true, new PropertyChangedCallback(CirclePointRingLoading.IsLargeChangedCallback)));
|
||||
|
||||
// Token: 0x04000008 RID: 8
|
||||
public static readonly DependencyProperty MaxSideLengthProperty = DependencyProperty.Register("MaxSideLength",
|
||||
typeof(double), typeof(CirclePointRingLoading), new PropertyMetadata(0.0));
|
||||
|
||||
// Token: 0x04000009 RID: 9
|
||||
public static readonly DependencyProperty EllipseDiameterProperty =
|
||||
DependencyProperty.Register("EllipseDiameter", typeof(double), typeof(CirclePointRingLoading),
|
||||
new PropertyMetadata(0.0));
|
||||
|
||||
// Token: 0x0400000A RID: 10
|
||||
public static readonly DependencyProperty EllipseOffsetProperty = DependencyProperty.Register("EllipseOffset",
|
||||
typeof(Thickness), typeof(CirclePointRingLoading), new PropertyMetadata(default(Thickness)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<UserControl
|
||||
x:Class="Sicentury.Core.UserControls.ParameterNodeTreeViewControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:attachedProperties="clr-namespace:Sicentury.Core.AttachedProperties"
|
||||
xmlns:converters="clr-namespace:Sicentury.Core.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:lex="http://wpflocalizeextension.codeplex.com"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="400"
|
||||
mc:Ignorable="d"
|
||||
lex:LocalizeDictionary.DesignCulture="en"
|
||||
lex:ResxLocalizationProvider.DefaultAssembly="Sicentury.Localization"
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_common">
|
||||
<UserControl.Resources>
|
||||
<converters:ParameterNodeTreeViewVisibilityMultiBindingConverter x:Key="NodeVisibilityConverter" />
|
||||
|
||||
<Style x:Key="styleTitle" TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
<Setter Property="FontWeight" Value="Black" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Margin" Value="5,0" />
|
||||
</Style>
|
||||
|
||||
<Style BasedOn="{StaticResource {x:Type Button}}" TargetType="Button">
|
||||
<Setter Property="Margin" Value="1,0,0,0" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Width" Value="30" />
|
||||
<Setter Property="Height" Value="30" />
|
||||
</Style>
|
||||
<Style TargetType="Path">
|
||||
<Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground, Mode=OneTime}" />
|
||||
<Setter Property="Stretch" Value="Uniform" />
|
||||
<Setter Property="Width" Value="16" />
|
||||
<Setter Property="Height" Value="16" />
|
||||
|
||||
</Style>
|
||||
|
||||
<ResourceDictionary x:Key="whatever">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/MECF.Framework.UI.Client;component/Themes/SeaBlue/Button.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Group management Group list -->
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Margin="0,5,0,0"
|
||||
Visibility="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=VisibilityTopTools}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70" />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Style="{StaticResource styleTitle}" Text="{lex:Loc ID_TXT_Group}" />
|
||||
<ComboBox
|
||||
x:Name="cbxPresetList"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectedItem="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=SelectedGroup}"
|
||||
SelectionChanged="CbxPresetList_OnSelectionChanged" />
|
||||
|
||||
<!-- Group management toolbar -->
|
||||
<StackPanel
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
x:Name="btnNewGroup"
|
||||
Click="BtnNewGroup_OnClick"
|
||||
ToolTip="New Group">
|
||||
<Button.Content>
|
||||
<Path Data="M405 213v43h-64v64h-42v-64h-64v-43h64v-64h42v64h64zM427 384c24 0 42 -19 42 -43v-213c0 -24 -18 -43 -42 -43h-342c-24 0 -42 19 -42 43v256c0 24 18 43 42 43h128l43 -43h171z">
|
||||
<Path.LayoutTransform>
|
||||
<ScaleTransform ScaleY="-1" />
|
||||
</Path.LayoutTransform>
|
||||
</Path>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnSave"
|
||||
Click="BtnSave_OnClick"
|
||||
ToolTip="Save">
|
||||
<Button.Content>
|
||||
<Path Data="M15,9H5V5H15M12,19A3,3 0 0,1 9,16A3,3 0 0,1 12,13A3,3 0 0,1 15,16A3,3 0 0,1 12,19M17,3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V7L17,3Z" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnSaveAs"
|
||||
Click="BtnSaveAs_OnClick"
|
||||
ToolTip="Save As">
|
||||
<Button.Content>
|
||||
<Path Data="M17,7V3H7V7H17M14,17A3,3 0 0,0 17,14A3,3 0 0,0 14,11A3,3 0 0,0 11,14A3,3 0 0,0 14,17M19,1L23,5V17A2,2 0 0,1 21,19H7C5.89,19 5,18.1 5,17V3A2,2 0 0,1 7,1H19M1,7H3V21H17V23H3A2,2 0 0,1 1,21V7Z" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnDelete"
|
||||
Click="BtnDelete_OnClick"
|
||||
ToolTip="Delete">
|
||||
<Button.Content>
|
||||
<Path Data="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnRefreshPresetList"
|
||||
Click="BtnRefreshPresetList_OnClick"
|
||||
ToolTip="Refresh">
|
||||
<Button.Content>
|
||||
<Path Data=" M536.3 250.4H750V464C749.7 511.3 722 522.7 688.6 489.2L640.5 441C598.3 474.1 546.5 492.2 492 492.2C427.4 492.2 366.6 467 321 421.3C275.2 375.8 250 315 250 250.4C250 185.7 275.2 124.9 320.9 79.3C366.6 33.5 427.3 8.3 492 8.3C556.5 8.3 617.3 33.5 663 79.3C675.4 91.7 686.3 105.2 695.5 119.5C710 142 703.5 172 681 186.4C658.5 200.8 628.5 194.3 614.1 171.8C608.6 163.2 602 155.1 594.6 147.6C567.2 120.2 530.7 105.1 492 105.1C453.2 105.1 416.8 120.2 389.3 147.6C361.9 175 346.8 211.5 346.8 250.3C346.8 289.1 361.9 325.5 389.3 352.9C416.8 380.3 453.2 395.4 492 395.4C520.6 395.4 548 387 571.5 371.6L511.2 311.1C477.7 277.7 489.1 250.4 536.3 250.4z" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
<TreeView
|
||||
x:Name="ParameterTreeView"
|
||||
Grid.Row="2"
|
||||
Margin="0,5,0,0"
|
||||
ItemsSource="{Binding Path=TreeRoot.ChildNodes, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Mode=TwoWay}"
|
||||
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
|
||||
VirtualizingStackPanel.CacheLengthUnit="Item"
|
||||
VirtualizingStackPanel.IsVirtualizing="True"
|
||||
VirtualizingStackPanel.ScrollUnit="Pixel"
|
||||
VirtualizingStackPanel.VirtualizationMode="Recycling">
|
||||
<!--<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="TreeView.SelectedItemChanged">
|
||||
<cal:ActionMessage MethodName="OnTreeSelectedChanged">
|
||||
<cal:Parameter Value="{Binding ElementName=ParameterTreeView,Path=SelectedItem}"></cal:Parameter>
|
||||
</cal:ActionMessage>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>-->
|
||||
<TreeView.ItemContainerStyle>
|
||||
<Style BasedOn="{StaticResource ResourceKey={x:Type TreeViewItem}}" TargetType="{x:Type TreeViewItem}">
|
||||
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="Visibility">
|
||||
<Setter.Value>
|
||||
<MultiBinding Converter="{StaticResource NodeVisibilityConverter}">
|
||||
<Binding Path="IsMatch" />
|
||||
<Binding Path="Visibility" />
|
||||
</MultiBinding>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</TreeView.ItemContainerStyle>
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding ChildNodes}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, Delay=10}">
|
||||
<!--<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Click">
|
||||
<micro:ActionMessage MethodName="ParameterCheck">
|
||||
<micro:Parameter Value="{Binding }"/>
|
||||
</micro:ActionMessage>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>-->
|
||||
</CheckBox>
|
||||
<TextBlock
|
||||
attachedProperties:TextBlockHighlighter.ForeColor="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}"
|
||||
attachedProperties:TextBlockHighlighter.HighlightColor="Yellow"
|
||||
attachedProperties:TextBlockHighlighter.Selection="{Binding Path=FilterKeyWord, Mode=OneWay}"
|
||||
Text="{Binding Name}" />
|
||||
</StackPanel>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
|
||||
|
||||
|
||||
<!-- Tree View Function Buttons -->
|
||||
<Grid Grid.Row="3">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Margin" Value="0,0,5,0" />
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Path
|
||||
Width="16"
|
||||
Height="16"
|
||||
Margin="5,0,10,0"
|
||||
VerticalAlignment="Center"
|
||||
Data="M1024 320v256h-704v-64h-128v192h576v256h-768v-256h128v-640h192v-128h704v256h-704v-64h-128v320h128v-128z"
|
||||
Fill="Black"
|
||||
ToolTip="Selection" />
|
||||
<TextBlock Text="{Binding TreeRoot.SelectedTerminalCount, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}" ToolTip="Selected Nodes" />
|
||||
<TextBlock Text="/" />
|
||||
<TextBlock Text="{Binding TreeRoot.TotalTerminalCount, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}" ToolTip="Total Nodes" />
|
||||
</StackPanel>
|
||||
<StackPanel
|
||||
Margin="0,5,0,0"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation=" Horizontal">
|
||||
<Button
|
||||
x:Name="btnExcludeNode"
|
||||
Click="BtnExcludeNode_OnClick"
|
||||
ToolTip="Edit Exclude Nodes List"
|
||||
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=VisibilityExcludeNodesButton}">
|
||||
<Button.Content>
|
||||
<Path Data="M117.65 187.5H82.35L76.3 157.2125L50.6 174.3375L25.65 149.4L42.775 123.7L12.5 117.65V82.35L42.7875 76.3L25.6625 50.6L50.6 25.65L76.3 42.775L82.35 12.5H108.3875A56.575 56.575 0 0 0 96.925 25.0625H92.65L89.05 43.075A55.9125 55.9125 0 0 0 88.2125 47.25L86.7625 54.5375L77.2125 58.4875L52.2125 41.8125L41.8125 52.2L58.5 77.2125L54.55 86.7625L25.075 92.65V107.35L54.55 113.2375L58.5 122.7875L41.825 147.7875L52.2125 158.1875L77.2125 141.5L86.7625 145.45L92.65 174.925H107.35L113.2375 145.45L122.7875 141.5L147.7875 158.175L158.1875 147.7875L141.5125 122.775L145.4625 113.225L152.7375 111.775C154.15 111.55 155.55 111.275 156.925 110.9375L174.9375 107.3375V103.0625C179.6875000000001 99.8875 183.9250000000001 96.025 187.5000000000001 91.6V117.65L157.225 123.7L174.3500000000001 149.4L149.4 174.35L123.7000000000001 157.225L117.65 187.5zM100 125A25 25 0 0 0 123.4375 108.725A55.75 55.75 0 0 1 112.1875 102.8125A12.5 12.5 0 1 1 97.1875 87.8125A55.75 55.75 0 0 1 91.275 76.5625A25 25 0 0 0 100 125zM116 90.0625A43.75 43.75 0 1 0 171.5 22.4375A43.75 43.75 0 0 0 116 90.0625zM112.5 62.5V50H175V62.5H112.5z">
|
||||
<Path.LayoutTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform ScaleY="-1" />
|
||||
</TransformGroup>
|
||||
</Path.LayoutTransform>
|
||||
</Path>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnShowAll"
|
||||
Click="BtnShowAll_OnClick"
|
||||
ToolTip="Show All">
|
||||
<Button.Content>
|
||||
<Path Data="M512 746.667c-325.675 0-423.552-282.325-424.448-285.184l-4.523-13.483 4.48-13.483c0.939-2.859 98.816-285.184 424.491-285.184s423.552 282.325 424.448 285.184l4.523 13.483-4.48 13.483c-0.939 2.859-98.816 285.184-424.491 285.184zM512 277.333c-94.123 0-170.667 76.544-170.667 170.667s76.544 170.667 170.667 170.667 170.667-76.544 170.667-170.667-76.544-170.667-170.667-170.667zM512 533.333c-46.251 0-85.333-39.083-85.333-85.333s39.083-85.333 85.333-85.333 85.333 39.083 85.333 85.333-39.083 85.333-85.333 85.333z" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
x:Name="btnShowSelectedOnly"
|
||||
Click="BtnShowSelectedOnly_OnClick"
|
||||
ToolTip="Show Selected Only">
|
||||
<Button.Content>
|
||||
<Path Data="M256,352c53,0,96-43,96-96s-43-96-96-96s-96,43-96,96S203,352,256,352z M256,432c-97,0-176-80-176-176c0-95,75-176,176-176c96,0,176,74,176,176C432,354,354,432,256,432z M256,480c121,0,224-97,224-224c0-121-97-224-224-224C135,32,32,129,32,256C32,377,129,480,256,480z">
|
||||
<Path.LayoutTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform ScaleY="-1" />
|
||||
</TransformGroup>
|
||||
</Path.LayoutTransform>
|
||||
</Path>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
x:Name="btnCollapseAll"
|
||||
Click="BtnCollapseAll_OnClick"
|
||||
ToolTip="Collapse All">
|
||||
<Button.Content>
|
||||
<Path Data="M 19,29L 47,29L 47,57L 19,57L 19,29 Z M 43,33L 23,33.0001L 23,53L 43,53L 43,33 Z M 39,41L 39,45L 27,45L 27,41L 39,41 Z M 24,24L 51.9999,24.0001L 51.9999,52L 48.9999,52.0001L 48.9999,27.0001L 24,27.0001L 24,24 Z M 54,47L 53.9999,22.0001L 29,22L 29,19L 57,19L 57,47L 54,47 Z " />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnExpandAll"
|
||||
Click="BtnExpandAll_OnClick"
|
||||
ToolTip="Expand All">
|
||||
<Button.Content>
|
||||
<Path Data="M 19,29L 47,29L 47,57L 19,57L 19,29 Z M 43,33L 23,33.0001L 23,53L 43,53L 43,33 Z M 39,41L 39,45L 35,45L 35,49L 31,49L 31,45L 27,45L 27,41L 31,41L 31,37L 35,37L 35,41L 39,41 Z M 24,24L 51.9999,24.0001L 51.9999,52L 48.9999,52.0001L 48.9999,27.0001L 24,27.0001L 24,24 Z M 53.9999,47L 53.9999,22.0001L 29,22L 29,19L 56.9999,19.0001L 57,47L 53.9999,47 Z " />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Filter Input Box -->
|
||||
<Grid Grid.Row="4" Margin="0,5,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Filter Toolbar -->
|
||||
<TextBlock Style="{StaticResource styleTitle}" Text="{lex:Loc ID_TXT_Filter}" />
|
||||
<TextBox
|
||||
x:Name="txtFilterKeyword"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
KeyDown="TxtFilterKeyword_OnKeyDown">
|
||||
<attachedProperties:WatermarkService.Watermark>
|
||||
<TextBlock VerticalAlignment="Center" Text="Press Enter to Apply" />
|
||||
</attachedProperties:WatermarkService.Watermark>
|
||||
</TextBox>
|
||||
<StackPanel
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
x:Name="btnApplyFilter"
|
||||
Click="BtnApplyFilter_OnClick"
|
||||
ToolTip="Apply Filter">
|
||||
<Button.Content>
|
||||
<Path Data="M416 448L319 351Q277 383 224 383 181 383 144 362 107 340 86 303 64 266 64 223 64 180 86 143 107 106 144 85 181 63 224 63 267 63 304 85 341 106 363 143 384 180 384 223 384 277 351 319L448 416 416 448ZM223 336Q270 336 303 303 335 270 335 224 335 177 303 145 270 112 223 112 177 112 144 145 111 177 111 224 111 270 144 303 177 336 223 336Z" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnClearFilter"
|
||||
Click="BtnClearFilter_OnClick"
|
||||
ToolTip="Clear Filter">
|
||||
<Button.Content>
|
||||
<Path Data="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48L7.48 8z">
|
||||
<Path.LayoutTransform>
|
||||
<ScaleTransform ScaleY="-1" />
|
||||
</Path.LayoutTransform>
|
||||
</Path>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,537 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\Core\UserControls\ParameterNodeTreeViewControl.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-01
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief Reconstructed to support rich functions.
|
||||
*
|
||||
* @details
|
||||
* *****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using Sicentury.Core.Dialogs;
|
||||
using Sicentury.Core.Tree;
|
||||
|
||||
namespace Sicentury.Core.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ParameterNodeTreeViewControl.xaml
|
||||
/// </summary>
|
||||
public partial class ParameterNodeTreeViewControl
|
||||
{
|
||||
#region Variables
|
||||
|
||||
private bool _clearGroupSelectionOnly = false;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 父级文件夹。
|
||||
/// </summary>
|
||||
private const string PRESET_GROUP_SUB_FOLDER_NAME = "PresetGroups";
|
||||
|
||||
public ParameterNodeTreeViewControl()
|
||||
{
|
||||
//InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnInitialized(System.EventArgs e)
|
||||
{
|
||||
InitializeComponent();
|
||||
base.OnInitialized(e);
|
||||
|
||||
LoadPresetGroupFilesList();
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
public static readonly DependencyProperty TreeRootProperty = DependencyProperty.Register(
|
||||
nameof(TreeRoot), typeof(TreeNode), typeof(ParameterNodeTreeViewControl),
|
||||
new PropertyMetadata(default(TreeNode), (o, p) =>
|
||||
{
|
||||
if (o is ParameterNodeTreeViewControl control)
|
||||
{
|
||||
if (p.NewValue is TreeNode tree)
|
||||
{
|
||||
tree.TerminalNodeSelectionChanged += (sender, b) =>
|
||||
{
|
||||
control.RaiseEvent(new RoutedEventArgs(TerminalNodeSelectionChangedEvent, sender));
|
||||
};
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回TreeView数据源。
|
||||
/// </summary>
|
||||
public TreeNode TreeRoot
|
||||
{
|
||||
get => (TreeNode)GetValue(TreeRootProperty);
|
||||
set => SetValue(TreeRootProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly DependencyProperty PresetGroupsFolderNameProperty = DependencyProperty.Register(
|
||||
"PresetGroupsFolderName", typeof(string), typeof(ParameterNodeTreeViewControl),
|
||||
new PropertyMetadata(default(string)));
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回存放预设组信息的子文件夹名称。
|
||||
/// </summary>
|
||||
public string PresetGroupsFolderName
|
||||
{
|
||||
get => (string)GetValue(PresetGroupsFolderNameProperty);
|
||||
set => SetValue(PresetGroupsFolderNameProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly DependencyProperty VisibilityExcludeNodesButtonProperty = DependencyProperty.Register(
|
||||
nameof(VisibilityExcludeNodesButton), typeof(Visibility), typeof(ParameterNodeTreeViewControl), new PropertyMetadata(System.Windows.Visibility.Hidden));
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示节点排除列表编辑按钮。
|
||||
/// </summary>
|
||||
public Visibility VisibilityExcludeNodesButton
|
||||
{
|
||||
get => (Visibility)GetValue(VisibilityExcludeNodesButtonProperty);
|
||||
set => SetValue(VisibilityExcludeNodesButtonProperty, value);
|
||||
}
|
||||
|
||||
//
|
||||
public static readonly DependencyProperty VisibilityTopToolsProperty = DependencyProperty.Register(
|
||||
nameof(VisibilityTopTools), typeof(Visibility), typeof(ParameterNodeTreeViewControl), new PropertyMetadata(System.Windows.Visibility.Visible));
|
||||
/// <summary>
|
||||
/// 顶部工具栏显示属性,不需要编辑时;
|
||||
/// </summary>
|
||||
public Visibility VisibilityTopTools
|
||||
{
|
||||
get => (Visibility)GetValue(VisibilityTopToolsProperty);
|
||||
set => SetValue(VisibilityTopToolsProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Routed Events
|
||||
|
||||
// Register a custom routed event using the Bubble routing strategy.
|
||||
public static readonly RoutedEvent TerminalNodeSelectionChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
name: nameof(TerminalNodeSelectionChanged),
|
||||
routingStrategy: RoutingStrategy.Bubble,
|
||||
handlerType: typeof(RoutedEventHandler),
|
||||
ownerType: typeof(ParameterNodeTreeViewControl));
|
||||
|
||||
// Provide CLR accessors for assigning an event handler.
|
||||
public event RoutedEventHandler TerminalNodeSelectionChanged
|
||||
{
|
||||
add => AddHandler(TerminalNodeSelectionChangedEvent, value);
|
||||
remove => RemoveHandler(TerminalNodeSelectionChangedEvent, value);
|
||||
}
|
||||
|
||||
|
||||
// Register a custom routed event using the Bubble routing strategy.
|
||||
public static readonly RoutedEvent EditExcludeNodesListEvent = EventManager.RegisterRoutedEvent(
|
||||
name: nameof(EditExcludeNodesList),
|
||||
routingStrategy: RoutingStrategy.Bubble,
|
||||
handlerType: typeof(RoutedEventHandler),
|
||||
ownerType: typeof(ParameterNodeTreeViewControl));
|
||||
|
||||
// Provide CLR accessors for assigning an event handler.
|
||||
public event RoutedEventHandler EditExcludeNodesList
|
||||
{
|
||||
add => AddHandler(EditExcludeNodesListEvent, value);
|
||||
remove => RemoveHandler(EditExcludeNodesListEvent, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 返回组信息文件名的完整路径。
|
||||
/// </summary>
|
||||
/// <param name="groupName">组名称</param>
|
||||
/// <returns></returns>
|
||||
private string GetPresetGroupFullFileName(string groupName)
|
||||
{
|
||||
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PRESET_GROUP_SUB_FOLDER_NAME,
|
||||
PresetGroupsFolderName, groupName + ".json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回保存组信息的文件夹名称。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string GetPresetGroupsFolderName()
|
||||
{
|
||||
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PRESET_GROUP_SUB_FOLDER_NAME,
|
||||
PresetGroupsFolderName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载指定文件夹内的所有json文件。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private void LoadPresetGroupFilesList(string selectedGroupName = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(PresetGroupsFolderName))
|
||||
throw new ArgumentException("the preset group files folder is not set.",
|
||||
paramName: nameof(PresetGroupsFolderName));
|
||||
|
||||
var folderName = GetPresetGroupsFolderName();
|
||||
|
||||
|
||||
var previousSelection = selectedGroupName;
|
||||
// 如果未指定下次待加载的项目,则保存当前的选择
|
||||
if (string.IsNullOrEmpty(previousSelection))
|
||||
if (cbxPresetList.SelectedItem != null)
|
||||
previousSelection = cbxPresetList.SelectedItem.ToString();
|
||||
|
||||
// 如果文件夹不存在,返回空列表
|
||||
if (!Directory.Exists(folderName))
|
||||
{
|
||||
Directory.CreateDirectory(folderName);
|
||||
cbxPresetList.ItemsSource = new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
var source =
|
||||
Directory.EnumerateFiles(folderName, "*.json")
|
||||
.Select(Path.GetFileNameWithoutExtension)
|
||||
.ToList();
|
||||
cbxPresetList.ItemsSource = source;
|
||||
|
||||
// 重新选择上次的选择
|
||||
if (string.IsNullOrEmpty(previousSelection) == false)
|
||||
{
|
||||
if (source.FirstOrDefault(x => x == previousSelection) != null)
|
||||
cbxPresetList.SelectedItem = previousSelection;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果TreeView还没有加载内容,则不要自动选择
|
||||
if (TreeRoot != null)
|
||||
cbxPresetList.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 仅清空Group下拉框的选项,而不清除TreeView的选择状态。
|
||||
/// <para>通常用于DataGrid中删除条目后,清除Group选项。</para>
|
||||
/// </summary>
|
||||
public void ClearPresetGroupSelectionOnly()
|
||||
{
|
||||
_clearGroupSelectionOnly = true;
|
||||
cbxPresetList.SelectedIndex = -1;
|
||||
_clearGroupSelectionOnly = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// 创建节点排除清单。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void BtnExcludeNode_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.RaiseEvent(new RoutedEventArgs(EditExcludeNodesListEvent, this));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重新加载组列表。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnRefreshPresetList_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadPresetGroupFilesList();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var err = $"Unable to refresh the group list, {ex.Message}";
|
||||
MessageBox.Show(err, "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新建组。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnNewGroup_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
TreeRoot.UnselectAll();
|
||||
cbxPresetList.SelectedIndex = -1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var err = $"Unable to create new group, {ex.Message}";
|
||||
MessageBox.Show(err, "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存组。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnSave_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
var groupName = "";
|
||||
|
||||
//if (TreeRoot.SelectedTerminalCount > TreeNode.QUERY_LIMIT_COUNT)
|
||||
//{
|
||||
// MessageBox.Show($"Too many items are selected, it's limited to {TreeNode.QUERY_LIMIT_COUNT}.",
|
||||
// "Error", MessageBoxButton.OK,
|
||||
// MessageBoxImage.Error);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (cbxPresetList.SelectedIndex == -1)
|
||||
{
|
||||
var dlg = new PresetGroupSaveDialog("Save Group", cbxPresetList.ItemsSource?.Cast<string>());
|
||||
var ret = dlg.ShowDialog();
|
||||
if (ret.HasValue && ret.Value == true)
|
||||
{
|
||||
groupName = dlg.GroupName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
groupName = cbxPresetList.SelectedItem.ToString();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 保存
|
||||
TreeNodeSelectionGroupInfo.SaveToJsonFile(GetPresetGroupFullFileName(groupName), TreeRoot);
|
||||
|
||||
LoadPresetGroupFilesList(groupName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var err = $"Unable to save group {groupName}, {ex.Message}";
|
||||
MessageBox.Show(err, "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 另存为组。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnSaveAs_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (cbxPresetList.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("No group is selected.", "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var newName = $"Copy of {cbxPresetList.SelectedValue}";
|
||||
|
||||
var dlg = new PresetGroupSaveDialog("Save As Group",
|
||||
cbxPresetList.ItemsSource?.Cast<string>(),
|
||||
newName);
|
||||
|
||||
var ret = dlg.ShowDialog();
|
||||
if (ret.HasValue && ret.Value)
|
||||
{
|
||||
var groupName = cbxPresetList.SelectedItem.ToString();
|
||||
|
||||
try
|
||||
{
|
||||
// 保存
|
||||
TreeNodeSelectionGroupInfo.SaveToJsonFile(GetPresetGroupFullFileName(groupName), TreeRoot);
|
||||
|
||||
// 保存一个空文件
|
||||
TreeNodeSelectionGroupInfo.SaveToJsonFile(GetPresetGroupFullFileName(dlg.GroupName), TreeRoot);
|
||||
|
||||
LoadPresetGroupFilesList(dlg.GroupName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var err = $"Unable to save as group {groupName}, {ex.Message}";
|
||||
MessageBox.Show(err, "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择组。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void CbxPresetList_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (cbxPresetList.SelectedIndex == -1)
|
||||
{
|
||||
//
|
||||
if (_clearGroupSelectionOnly)
|
||||
return;
|
||||
|
||||
TreeRoot.UnselectAll();
|
||||
return;
|
||||
}
|
||||
|
||||
var groupName = cbxPresetList.SelectedValue.ToString();
|
||||
|
||||
try
|
||||
{
|
||||
TreeNodeSelectionGroupInfo.RecoveryFromJsonFile(GetPresetGroupFullFileName(groupName), TreeRoot);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var err = $"Unable to recovery group {groupName}, {ex.Message}";
|
||||
MessageBox.Show(err, "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除组。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnDelete_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 如果没选中任何组,忽略操作
|
||||
if (cbxPresetList.SelectedIndex == -1)
|
||||
return;
|
||||
|
||||
var groupName = cbxPresetList.SelectedItem.ToString();
|
||||
if (string.IsNullOrEmpty(groupName))
|
||||
return;
|
||||
|
||||
var ret = MessageBox.Show($"Are you sure to delete the group {groupName}", "Warning",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (ret == MessageBoxResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileSystem.DeleteFile(GetPresetGroupFullFileName(groupName), UIOption.OnlyErrorDialogs,
|
||||
RecycleOption.SendToRecycleBin);
|
||||
LoadPresetGroupFilesList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var err = $"Unable to delete group {groupName}, {ex.Message}";
|
||||
MessageBox.Show(err, "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 折叠所有节点。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnCollapseAll_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (TreeRoot.ChildNodes.Count > 0)
|
||||
{
|
||||
TreeRoot.CollapseAll();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 展开所有节点。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnExpandAll_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (TreeRoot.ChildNodes.Count > 0)
|
||||
{
|
||||
TreeRoot.ExpandAll();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用筛选器。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void BtnApplyFilter_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TreeRoot.SuspendUpdate();
|
||||
TreeRoot.ApplyFilter(txtFilterKeyword.Text);
|
||||
TreeRoot.ResumeUpdate();
|
||||
txtFilterKeyword.SelectAll();
|
||||
txtFilterKeyword.Focus();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除筛选器
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnClearFilter_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TreeRoot.SuspendUpdate();
|
||||
TreeRoot.ClearFilter();
|
||||
TreeRoot.ResumeUpdate();
|
||||
txtFilterKeyword.Text = "";
|
||||
txtFilterKeyword.Focus();
|
||||
|
||||
}
|
||||
|
||||
private void TxtFilterKeyword_OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key != Key.Enter)
|
||||
return;
|
||||
|
||||
TreeRoot.ApplyFilter(txtFilterKeyword.Text);
|
||||
txtFilterKeyword.SelectAll();
|
||||
txtFilterKeyword.Focus();
|
||||
}
|
||||
|
||||
private void BtnShowSelectedOnly_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TreeRoot.ShowSelectedOnly();
|
||||
}
|
||||
|
||||
private void BtnShowAll_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TreeRoot.ShowAll();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user