This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
using System;
using System.Windows.Controls;
using System.Windows.Data;
using DTS.Common.Base;
namespace DTS.Common.Converters
{
public class ActiveContentConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is ContentControl)
return value;
return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is ContentControl)
return value;
return Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// simple converter that converts array or lists so visible or hidden
/// </summary>
public class ArrayVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (null == value) { return Visibility.Hidden; }
if (value is IList list) { return list.Count > 0 ? Visibility.Visible : Visibility.Collapsed; }
if (value is Array array)
{
return array.Length > 0 ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class BooleanAndToVisibilityMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var useFalseAsVisible = parameter != null && parameter.ToString().ToUpper().Contains("FALSE");
var hideNotCollapse = parameter != null && parameter.ToString().ToUpper().Contains("HIDE");
bool value = !Array.TrueForAll(values, val => val is bool) ? false : values.All(val => (bool)val);
if (useFalseAsVisible)
{
if (!value)
return Visibility.Visible;
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
}
if (!value)
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Linq;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class BooleanOrMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return !Array.TrueForAll(values, val => val is bool) ? false : (object)Array.Exists(values, val => (bool)val);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class BooleanOrToVisibilityMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var useFalseAsVisible = parameter != null && parameter.ToString().ToUpper().Contains("FALSE");
var hideNotCollapse = parameter != null && parameter.ToString().ToUpper().Contains("HIDE");
bool value = !Array.TrueForAll(values, val => val is bool) ? false : Array.Exists(values, val => (bool)val);
if (useFalseAsVisible)
{
if (!value)
return Visibility.Visible;
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
}
if (!value)
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class BooleanToBorderBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value != null && (bool)value ? BrushesAndColors.Brush_Warning : Brushes.Transparent;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class BooleanToBorderThicknessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value)
{
return 1;
}
return 2;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class BooleanToColorConverter : IValueConverter
{
public bool Background { get; set; } = false;
public bool Inverted { get; set; } = false;
public bool AttentionBrush { get; set; } = false;
public bool WarningBrush { get; set; } = false;
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
value = Inverted ? !(bool)value : value;
if ((bool)value)
{
return Background ? Brushes.Transparent : BrushesAndColors.Brush_NoError;
}
return AttentionBrush ? BrushesAndColors.Brush_Attention : WarningBrush ? BrushesAndColors.Brush_Warning : BrushesAndColors.Brush_Error;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,84 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Represents the converter that converts Boolean values to and from width values.
/// </summary>
///
/// <remarks>
/// Use the BooleanToColumnWidthConverter class to convert a Boolean to and from a width value.
/// The Convert method returns <see cref="Visibility.Visible">Visibility.Visible</see> when <b>true</b> is passed in
/// or <see cref="Visibility.Collapsed">Visibility.Collapsed</see> when <b>false</b> is passed in.
/// Note that the <see cref="Visibility.Collapsed">Visibility.Collapsed</see> value hides the control and does not reserve space for it in a layout.
/// When you call the ConvertBack method and specify a reference to an object, it returns <b>true</b>
/// if the object is <see cref="Visibility.Visible">Visible</see>; otherwise, it returns <b>false</b>.
/// </remarks>
///
public abstract class BooleanToColumnWidthConverter : IValueConverter
{
public abstract double DefaultWidth { get; }
/// <summary>
/// Converts a Boolean value to a Visibility enumeration value.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var useFalseAsVisible = parameter != null && parameter.ToString().ToUpper() == "FALSE";
if (useFalseAsVisible)
{
if ((bool)value)
return 0D;
return DefaultWidth;
}
if ((bool)value)
return DefaultWidth;
return 0D;
}
/// <summary>
/// Converts a Visibility enumeration value to a Boolean value.
/// </summary>
/// <param name="value">A Visibility enumeration value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
public class DASTableBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 110D; }
}
public class ImportTestSetupBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 175D; }
}
public class ImportTestSetupISOCodeBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 140; }
}
public class ImportTestSetupISOChannelBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 190; }
}
public class LevelTriggerBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 210D; }
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class BooleanToGreenBorderConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value != null && (bool)value ? BrushesAndColors.BrushApplicationStatusPowerGreen : Brushes.Transparent;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class BooleanToItalicFontStyleConverter : IValueConverter
{
/// <summary>
/// Converts a Boolean value to a FontStyle enumeration value.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="culture"></param>
/// <param name="parameter"></param>
/// <param name="targetType"></param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value != null && (bool)value ? FontStyles.Italic : FontStyles.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,35 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Represents the converter that converts Boolean values to Opacity value.
/// Use the BooleanToOpacityConverter class to convert a Boolean to Opacity value to provide visual feedback to the user if control enable or disable.
/// </summary>
public class BooleanToOpacityConverter : IValueConverter
{
/// <summary>
/// Converts a Boolean value to a Opacity to show user control enable/disable.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && (bool)value)
return 0.5;
return 1;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Represents the converter that converts Boolean values to and from <see cref="Visibility">Visibility</see> enumeration values.
/// </summary>
///
/// <remarks>
/// Use the BooleanToVisibilityConverter class to convert a Boolean to and from a <see cref="Visibility">Visibility</see> value.
/// The Convert method returns <see cref="Visibility.Visible">Visibility.Visible</see> when <b>true</b> is passed in
/// or <see cref="Visibility.Collapsed">Visibility.Collapsed</see> when <b>false</b> is passed in.
/// Note that the <see cref="Visibility.Collapsed">Visibility.Collapsed</see> value hides the control and does not reserve space for it in a layout.
/// When you call the ConvertBack method and specify a reference to an object, it returns <b>true</b>
/// if the object is <see cref="Visibility.Visible">Visible</see>; otherwise, it returns <b>false</b>.
/// </remarks>
///
public class BooleanToVisibilityConverter : IValueConverter
{
/// <summary>
/// Converts a Boolean value to a Visibility enumeration value.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var useFalseAsVisible = parameter != null && parameter.ToString().ToUpper() == "FALSE";
var hideNotCollapse = parameter != null && parameter.ToString().ToUpper() == "HIDE";
if (!useFalseAsVisible)
{
if ((bool)value)
return Visibility.Visible;
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
}
if ((bool)value)
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
return Visibility.Visible;
}
/// <summary>
/// Converts a Visibility enumeration value to a Boolean value.
/// </summary>
/// <param name="value">A Visibility enumeration value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class ColorToSolidColorBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// For a more sophisticated converter, check also the targetType and react accordingly..
if (value is Color color)
{
return new SolidColorBrush(color);
}
return null;
// You can support here more source types if you wish
// For the example I throw an exception
//var type = value.GetType();
//throw new InvalidOperationException("Unsupported type [" + type.Name + "]");
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// If necessary, here you can convert back. Check if which brush it is (if its one),
// get its Color-value and return it.
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,39 @@
using DTS.Common.Interface.Hardware;
using System;
using System.Windows;
using System.Windows.Data;
// ReSharper disable PossibleNullReferenceException
namespace DTS.Common.Converters
{
public class DASStatusArmColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DASStatuses status)
{
switch (status)
{
case DASStatuses.MissingNotBooted:
return BrushesAndColors.Brush_ApplicationStatus_Failed;
case DASStatuses.BootedNotArmedYet:
return BrushesAndColors.Brush_ApplicationStatus_Failed;
case DASStatuses.BootedNeverArmed:
return BrushesAndColors.Brush_ApplicationStatus_Failed;
case DASStatuses.ArmedReady:
return BrushesAndColors.Brush_ApplicationStatus_Complete;
case DASStatuses.ArmedButFailedDiag:
return BrushesAndColors.Brush_ApplicationStatus_Busy;
case DASStatuses.ReadyForDownload:
return BrushesAndColors.Brush_ApplicationStatus_Idle;
}
}
return BrushesAndColors.Brush_ApplicationStatus_Idle;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,39 @@
using DTS.Common.Interface.Hardware;
using System;
using System.Windows;
using System.Windows.Data;
// ReSharper disable PossibleNullReferenceException
namespace DTS.Common.Converters
{
public class DASStatusArmTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DASStatuses status)
{
switch (status)
{
case DASStatuses.MissingNotBooted:
return Strings.Strings.Table_NA;
case DASStatuses.BootedNotArmedYet:
return Strings.Strings.NotArmed;
case DASStatuses.BootedNeverArmed:
return Strings.Strings.NotArmed;
case DASStatuses.ArmedReady:
return Strings.Strings.Armed;
case DASStatuses.ArmedButFailedDiag:
return Strings.Strings.Armed;
case DASStatuses.ReadyForDownload:
return Strings.Strings.NotArmed;
}
}
return Strings.Strings.Table_NA;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,39 @@
using DTS.Common.Interface.Hardware;
using System;
using System.Windows;
using System.Windows.Data;
// ReSharper disable PossibleNullReferenceException
namespace DTS.Common.Converters
{
public class DASStatusColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DASStatuses status)
{
switch (status)
{
case DASStatuses.MissingNotBooted:
return BrushesAndColors.Brush_ApplicationStatus_Idle;
case DASStatuses.BootedNotArmedYet:
return BrushesAndColors.Brush_ApplicationStatus_Busy;
case DASStatuses.BootedNeverArmed:
return BrushesAndColors.Brush_ApplicationStatus_Failed;
case DASStatuses.ArmedReady:
return BrushesAndColors.Brush_ApplicationStatus_Complete;
case DASStatuses.ArmedButFailedDiag:
return BrushesAndColors.Brush_ApplicationStatus_Failed;
case DASStatuses.ReadyForDownload:
return BrushesAndColors.Brush_ApplicationStatus_Complete;
}
}
return BrushesAndColors.Brush_ApplicationStatus_Idle;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "Acronym")]
public class DSPStreamingFilterFrequencyConverter : IValueConverter
{
private const double EPSILON = .00001D;
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double d)
{
if (double.IsNaN(d)) { return string.Empty; }
if (Math.Abs(d - 0D) < EPSILON) { return Strings.Strings.Table_NA; }
return d.ToString("F1");
}
return Strings.Strings.Table_NA;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Date converter that will display Table_NA when date is null, otherwise datetime [xaml responsible for formatting]
/// </summary>
public class DateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DateTime dt) { return dt; }
return Strings.Strings.Table_NA;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DateTime dt) { return dt; }
return Strings.Strings.Table_NA;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class DateTimeWithMillisecondsToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Utils.Utils.FormatTimeStamp(System.Convert.ToDateTime(value));
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,30 @@
using DTS.Common.Interface.Hardware;
using System;
using System.Windows;
using System.Windows.Data;
// ReSharper disable PossibleNullReferenceException
namespace DTS.Common.Converters
{
public class DiagStatusOffsetColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DiagStatuses status)
{
if (status == DiagStatuses.NoResults) { return BrushesAndColors.Brush_ApplicationStatus_Idle; }
if ((status & DiagStatuses.FailedOffset) == DiagStatuses.FailedOffset)
{
return BrushesAndColors.Brush_ApplicationStatus_Failed;
}
return BrushesAndColors.Brush_ApplicationStatus_Complete;
}
return BrushesAndColors.Brush_ApplicationStatus_Idle;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,30 @@
using DTS.Common.Interface.Hardware;
using System;
using System.Windows;
using System.Windows.Data;
// ReSharper disable PossibleNullReferenceException
namespace DTS.Common.Converters
{
public class DiagStatusShuntColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DiagStatuses status)
{
if (status == DiagStatuses.NoResults) { return BrushesAndColors.Brush_ApplicationStatus_Idle; }
if ((status & DiagStatuses.FailedShunt) == DiagStatuses.FailedShunt)
{
return BrushesAndColors.Brush_ApplicationStatus_Failed;
}
return BrushesAndColors.Brush_ApplicationStatus_Complete;
}
return BrushesAndColors.Brush_ApplicationStatus_Idle;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class DoubleFromThousandthUnitToBaseUnit : IValueConverter
{
/// <summary>
/// Used to convert a Thousandth value to its base unit.
/// For example to convert millivolts to volts
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double milliUnit)
{
if (double.IsNaN(milliUnit)) { return 0D; }
return milliUnit / 1000.0D;
}
else
{
return 0D;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double unit)
{
if (double.IsNaN(unit)) { return 0D; }
return unit * 1000.0D;
}
else
{
return 0D;
}
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Windows;
using System.Windows.Data;
// ReSharper disable PossibleNullReferenceException
namespace DTS.Common.Converters
{
public class EnumBooleanConverter : IValueConverter
{
//#region IValueConverter Members
//public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
//{
// var parameterString = parameter as string;
// if (parameterString == null)
// return DependencyProperty.UnsetValue;
// if (Enum.IsDefined(value.GetType(), value) == false)
// return DependencyProperty.UnsetValue;
// var parameterValue = Enum.Parse(value.GetType(), parameterString);
// return parameterValue.Equals(value);
//}
//public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
//{
// var parameterString = parameter as string;
// return parameterString == null ? DependencyProperty.UnsetValue : Enum.Parse(targetType, parameterString);
//}
//#endregion
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.ComponentModel;
using System.Linq;
namespace DTS.Common.Converters
{
/// <summary>
/// Display enum description instead of enum value
/// http://brianlagunas.com/a-better-way-to-data-bind-enums-in-wpf/
/// </summary>
public class EnumDescriptionTypeConverter : EnumConverter
{
public EnumDescriptionTypeConverter(Type type)
: base(type)
{
}
/// <summary>
/// Modifies the source data before passing it to the target for display in the UI.
/// </summary>
/// <param name="value">The value to be converted</param>
/// <param name="context">The source data being passed to the target.</param>
/// <param name="culture">The culture of the conversion.</param>
/// <param name="destinationType">The System.Type of data expected by the target dependency property.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType != typeof(string)) return base.ConvertTo(context, culture, value, destinationType);
if (value == null) return string.Empty;
var fi = value.GetType().GetField(value.ToString());
if (fi == null) return string.Empty;
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (!attributes.Any() || string.IsNullOrEmpty(attributes[0].Description)) return value.ToString();
var s = Strings.Strings.ResourceManager.GetString(attributes[0].Description);
return string.IsNullOrWhiteSpace(s) ? attributes[0].Description : s;
}
public static string GetEnumDescription(Enum value)
{
var fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes
(typeof(DescriptionAttribute), false);
if (attributes.Length > 0)
{
var s = Strings.Strings.ResourceManager.GetString(attributes[0].Description);
if (!string.IsNullOrWhiteSpace(s)) { return s; }
return attributes[0].Description;
}
return value.ToString();
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class EnumVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null != value && value.Equals(parameter) ? Visibility.Visible : Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null != value && value.Equals(Visibility.Visible) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
class ErrorToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// For a more sophisticated converter, check also the targetType and react accordingly..
if (value is string)
{
return string.IsNullOrEmpty(value.ToString());
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// If necessary, here you can convert back. Check if which brush it is (if its one),
// get its Color-value and return it.
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class ErrorToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// For a more sophisticated converter, check also the targetType and react accordingly..
if (value is string)
{
return String.IsNullOrEmpty(value.ToString()) ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.Red);
}
return new SolidColorBrush(Colors.Black);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// If necessary, here you can convert back. Check if which brush it is (if its one),
// get its Color-value and return it.
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class FaultedColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool b)
{
if (b) { return BrushesAndColors.Brush_ApplicationStatus_Failed.Color; }
else { return BrushesAndColors.Brush_ApplicationStatus_Complete.Color; }
}
return Brushes.Transparent.Color;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class FaultedTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool b)
{
if (b) { return Strings.Strings.Faulted; }
else { return Strings.Strings.FaultsClear; }
}
return Strings.Strings.FaultsClear;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Converter which converts percentage to String.
/// </summary>
public class FilePathsToShortStringConverter : IValueConverter
{
/// <summary>
///
/// </summary>
/// <param name="value">The decimal value to convert. This value can be a standard decimal value or a nullable decimal value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">The culture to use in the format operation.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var filePaths = value as string[];
if (null == filePaths || filePaths.Length < 1)
{
return string.Empty;
}
if (filePaths.Length > 1)
{
return Strings.Strings.MultipleFiles;
}
var fi = new FileInfo(filePaths[0]);
return fi.Name;
}
/// <summary>
/// Conversion back is not supported.
/// </summary>
/// <param name="value">A currency value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// converts between two values and a bool (a >= b)
/// currently only handles two ints or two doubles
/// </summary>
public class GreaterEqualThanToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is int a && parameter is int b)
{
return a >= b;
}
if (value is double dA && parameter is double dB)
{
return dA >= dB;
}
if (value is ushort uShortA && parameter is ushort uShortB)
{
return uShortA >= uShortB;
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return false;
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;
using DTS.Common.Classes.Groups;
namespace DTS.Common.Converters
{
/// <summary>
/// Converter which converts percentage to String.
/// </summary>
public class GroupImportErrorToStringConverter : IValueConverter
{
/// <summary>
///
/// </summary>
/// <param name="value">The decimal value to convert. This value can be a standard decimal value or a nullable decimal value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">The culture to use in the format operation.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var error = value as GroupImportError;
if (null == error)
{
return string.Empty;
}
return error.ExtraInfo;
}
/// <summary>
/// Conversion back is not supported.
/// </summary>
/// <param name="value">A currency value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Represents the converter that converts Text (GroupName) values to and from <see cref="Visibility">Visibility</see> enumeration values.
/// </summary>
public class GroupNameToVisibilityConverter : IValueConverter
{
/// <summary>
/// Converts a Group Name value to a Visibility enumeration value.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value.ToString().Trim().StartsWith("Graph")) { return Visibility.Visible; }
return Visibility.Collapsed;
}
/// <summary>
///
/// </summary>
/// <param name="value">A Visibility enumeration value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace DTS.Common.Converters
{
public class HeightConverter : MarkupExtension, IValueConverter
{
private static HeightConverter _instance;
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return System.Convert.ToDouble(value) - System.Convert.ToInt32(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
#endregion
public override object ProvideValue(IServiceProvider serviceProvider)
{
return _instance ?? (_instance = new HeightConverter());
}
}
}

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class InitialOffsetToIEPESensorOffsetConverter : IValueConverter
{
/// <summary>
/// Used to convert millivolt offset to IEPE sensor offset in volts
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double milliUnit)
{
return ConvertDouble(milliUnit);
}
else
{
return 0D;
}
}
const double IEPE_MIDPOINT = 12.25D;
public static double ConvertDouble(double milliUnit)
{
if (double.IsNaN(milliUnit)) { return 0D; }
return (milliUnit / 1000.0D) + IEPE_MIDPOINT;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double unit)
{
if (double.IsNaN(unit)) { return 0D; }
return (unit - IEPE_MIDPOINT) * 1000.0D;
}
else
{
return 0D;
}
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// converts between two values and a bool (a >= b)
/// currently only handles two ints or two doubles
/// </summary>
public class IntervalToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var on = false;
if (value is int a && parameter is int b)
{
on = a >= b;
}
if (value is double dA && parameter is double dB)
{
on = dA >= dB;
}
if (value is ushort uShortA && parameter is ushort uShortB)
{
on = uShortA >= uShortB;
}
return on ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return false;
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Represents a converter that converts a Boolean value to its inverse.
/// </summary>
public class InverseBooleanConverter : IValueConverter
{
/// <summary>
/// Modifies the source data before passing it to the target for display in the UI.
/// </summary>
/// <param name="value">The source data being passed to the target.</param>
/// <param name="targetType">The System.Type of data expected by the target dependency property.</param>
/// <param name="parameter">An optional parameter to be used in the converter logic.</param>
/// <param name="culture">The culture of the conversion.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null) return false;
bool val;
bool.TryParse(value.ToString(), out val);
return !val;
}
/// <summary>
/// Modifies the target data before passing it to the source object. This method is called only in System.Windows.Data.BindingMode.TwoWay bindings.
/// </summary>
/// <param name="value">The target data being passed to the source.</param>
/// <param name="targetType">The System.Type of data expected by the source object.</param>
/// <param name="parameter">An optional parameter to be used in the converter logic.</param>
/// <param name="culture">The culture of the conversion.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null) return false;
bool val;
bool.TryParse(value.ToString(), out val);
return !val;
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class InverseBooleanToOpacityConverter : IValueConverter
{
/// <summary>
/// Converts a Boolean value to a Opacity to show user control enable/disable.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && (bool)value)
return 1.0;
return 0.5;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Represents the converter that converts Boolean values to and from <see cref="Visibility">Visibility</see> enumeration values.
/// </summary>
///
/// <remarks>
/// Use the BooleanToVisibilityConverter class to convert a Boolean to and from a <see cref="Visibility">Visibility</see> value.
/// The Convert method returns <see cref="Visibility.Visible">Visibility.Visible</see> when <b>true</b> is passed in
/// or <see cref="Visibility.Collapsed">Visibility.Collapsed</see> when <b>false</b> is passed in.
/// Note that the <see cref="Visibility.Collapsed">Visibility.Collapsed</see> value hides the control and does not reserve space for it in a layout.
/// When you call the ConvertBack method and specify a reference to an object, it returns <b>true</b>
/// if the object is <see cref="Visibility.Visible">Visible</see>; otherwise, it returns <b>false</b>.
/// </remarks>
///
public class InverseBooleanToVisibilityConverter : IValueConverter
{
/// <summary>
/// Converts a Boolean value to a Visibility enumeration value.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var useFalseAsVisible = parameter != null && parameter.ToString().ToUpper() == "FALSE";
var hideNotCollapse = parameter != null && parameter.ToString().ToUpper() == "HIDE";
if (!useFalseAsVisible)
{
if (value != null && (bool)value)
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
return Visibility.Visible;
}
if (value != null && (bool)value)
return Visibility.Visible;
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
}
/// <summary>
/// Converts a Visibility enumeration value to a Boolean value.
/// </summary>
/// <param name="value">A Visibility enumeration value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// returns true or false based on enum value to parameter, intended for IsEnabled, but returns a bool so can just be
/// InvertEnumBool converter
/// </summary>
public class InverseEnumEnabledConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null != value && value.Equals(parameter) ? false : true;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null != value && value.Equals(false) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class InverseEnumVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null != value && value.Equals(parameter) ? Visibility.Hidden : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null != value && value.Equals(Visibility.Hidden) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class IsGreaterThanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var left = value != null && decimal.TryParse(value.ToString(), out _) ? decimal.Parse(value.ToString(), culture.NumberFormat) : 0;
var right = parameter != null && decimal.TryParse(parameter.ToString(), out _) ? decimal.Parse(parameter.ToString(), culture.NumberFormat) : 0;
return left > right;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class IsLessThanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var left = value != null && decimal.TryParse(value.ToString(), out _) ? decimal.Parse(value.ToString(), culture.NumberFormat) : 0;
var right = parameter != null && decimal.TryParse(parameter.ToString(), out _) ? decimal.Parse(parameter.ToString(), culture.NumberFormat) : 0;
return left < right;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Windows.Data;
namespace DTS.Common.Converters
{
[ValueConversion(typeof(List<string>), typeof(string))]
public class ListToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (targetType != typeof(string))
throw new InvalidOperationException("The target must be a String");
return String.Join(", ", ((List<string>)value)?.ToArray() ?? throw new InvalidOperationException());
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class NonZeroToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value.ToString() == "0")
{
return BrushesAndColors.BrushApplicationStatusPowerGreen;
}
if (value != null && value.ToString() == "---")
{
return BrushesAndColors.BrushApplicationStatusPowerClear;
}
return BrushesAndColors.BrushApplicationStatusPowerRed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Date converter that will display Table_NA when date is null, otherwise datetime [xaml responsible for formatting]
/// </summary>
public class NullableFloatConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double d) { return d; }
return value is float ft ? ft : (object)string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value is float ft ? ft : (object)string.Empty;
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class NumericStringFormatConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (null != values && values.Length == 2)
{
try
{
if (values[0] is int i)
{
return i.ToString(values[1] as string, CultureInfo.InvariantCulture);
}
if (values[0] is double d)
{
return (d is double.NaN) ? Strings.Strings.Table_NA : d.ToString(values[1] as string, CultureInfo.InvariantCulture);
}
if (values[0] is float f)
{
return (f is float.NaN) ? Strings.Strings.Table_NA : f.ToString(values[1] as string, CultureInfo.InvariantCulture);
}
if (values[0] is decimal deci)
{
return deci.ToString(values[1] as string, CultureInfo.InvariantCulture);
}
}
catch
{
}
}
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,40 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Converter which converts percentage to String.
/// </summary>
public class PercentConverter : IValueConverter
{
/// <summary>
///
/// </summary>
/// <param name="value">The decimal value to convert. This value can be a standard decimal value or a nullable decimal value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">The culture to use in the format operation.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var result = value as decimal? ?? 0;
return String.Format(CultureInfo.CurrentUICulture, "{0:F1}%", result);
}
/// <summary>
/// Conversion back is not supported.
/// </summary>
/// <param name="value">A currency value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,68 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// This converter is used to bind a value to a group of radio buttons, and can be used with bool parameters only.
/// It depends on the converter parameter, which maps a radio button to a specific value.
/// </summary>
///
/// <remarks>
/// <para>
/// Notice the converter parameter.
/// Its role is to make sure to get opposite values for the two radio buttons (when one is true, the other is false).
/// --------------------------------------------------------------------------------------------------
/// | value | param | result : (RadioButton.IsChecked = !(value ^ param)) where ^ is the XOR operator |
/// --------------------------------------------------------------------------------------------------
/// | true | true | true |
/// | false | true | false |
/// | true | false | false |
/// | false | false | true |
/// --------------------------------------------------------------------------------------------------
/// </para>
/// </remarks>
[ValueConversion(typeof(bool?), typeof(bool))]
public class RadioButtonCheckedConverter : IValueConverter
{
/// <summary>
/// Maps a radio button to a specific value.
/// </summary>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The target output type.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the format operation.</param>
/// <returns>
/// <value>
/// <see langword="true" /> if [value] and [parameter] have same values; otherwise <see langword="false" />.
/// </value>
/// </returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var param = bool.Parse(parameter.ToString());
if (value == null)
return false;
return !((bool)value ^ param); // ^ is the XOR operator
}
/// <summary>
/// Maps a radio button to a specific value.
/// </summary>
/// <param name="value">The value that is produced by the binding target.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>
/// <value>
/// <see langword="true" /> if [value] and [parameter] have same values; otherwise <see langword="false" />.
/// </value>
/// </returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var param = bool.Parse(parameter.ToString());
return !((bool)value ^ param);
}
}
}

View File

@@ -0,0 +1,38 @@
using DTS.Common.Enums;
using DTS.Common.Enums.DASFactory;
using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// This converter will returns a visibility based on whether pretrigger should be shown or not
/// it should be bound to RecordingMode an optional parameter allows inverting the return
/// </summary>
public class RecordingModePreTriggerVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var showPreTrigger = true;
if ((value is RecordingModes mode) &&
(RecordingModeExtensions.IsAnActiveMode(mode) || !RecordingModeExtensions.CanProgramPreTrigger(mode)))
{
showPreTrigger = false;
}
var invert = false;
if (bool.TrueString.Equals(parameter)) { invert = true; }
if (showPreTrigger)
{
return invert ? Visibility.Collapsed : Visibility.Visible;
}
else { return invert ? Visibility.Visible : Visibility.Collapsed; }
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null != value && value.Equals(Visibility.Visible) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,31 @@
using DTS.Common.Enums;
using System;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class StatusToBorderThicknessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!(value is UIItemStatus itemStatus))
{
return 1;
}
switch (itemStatus)
{
case UIItemStatus.None: return 1;
case UIItemStatus.Success: return 2;
case UIItemStatus.Failed: return 2;
case UIItemStatus.Error: return 2;
case UIItemStatus.Warning: return 2;
}
return 1;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,32 @@
using DTS.Common.Enums;
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class StatusToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!(value is UIItemStatus itemStatus))
{
return Brushes.Transparent;
}
switch (itemStatus)
{
case UIItemStatus.None: return Brushes.Black;
case UIItemStatus.Success: return BrushesAndColors.Brush_ApplicationStatus_Complete;
case UIItemStatus.Failed: return BrushesAndColors.Brush_ApplicationStatus_Failed;
case UIItemStatus.Error: return Brushes.Red;
case UIItemStatus.Warning: return Brushes.OrangeRed;
}
return Brushes.Black;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using System.Windows;
namespace DTS.Common.Converters
{
[ValueConversion(typeof(List<string>), typeof(Visibility))]
public class StringListToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (targetType != typeof(Visibility))
throw new InvalidOperationException("The target must be a Visibility");
return (((List<string>)value) ?? throw new InvalidOperationException()).Any() ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Globalization;
using System.Windows.Data;
using DTS.Common.Enums;
namespace DTS.Common.Converters
{
public class TestDataToRegionOfInterestMaximumConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//values: dataStart, dataEnd, PreTrigger, PostTrigger, RecordingMode
if (values.Length == 5)
{
if (values[2] is double && values[3] is double postTrigger &&
values[4] is RecordingModes recordingMode)
{
switch (recordingMode)
{
case RecordingModes.CircularBuffer:
case RecordingModes.RAMActive:
case RecordingModes.MultipleEventRAMActive:
case RecordingModes.CircularBufferAndStreamSubSample:
case RecordingModes.CircularBufferPlusUART:
case RecordingModes.MultipleEventCircularBuffer:
case RecordingModes.MultipleEventCircularBufferPlusUART:
//maximum is PostTrigger
return postTrigger;
case RecordingModes.Recorder:
case RecordingModes.RecorderPlusUART:
case RecordingModes.MultipleEventRecorder:
case RecordingModes.MultipleEventRecorderPlusUART:
case RecordingModes.HybridRecorder:
case RecordingModes.HybridAndStream:
case RecordingModes.MultipleEventHybridAndStream:
case RecordingModes.MultipleEventHybridRecorder:
case RecordingModes.ContinuousRecorder:
case RecordingModes.ContinuousRecorderPlusUART:
case RecordingModes.RecordOnBoot:
case RecordingModes.RecordOnBootPlusUART:
case RecordingModes.RecorderAndStreamSubSample:
case RecordingModes.MultipleEventRecorderAndStream:
// FB16465: maximum is DataEnd. if it's currently unknown, return PostTrigger
// FB17991: could also be set to Max instead of unknown, same difference
case RecordingModes.Active:
case RecordingModes.MultipleEventActive:
// FB18333: max holds for Active too.
return values[1] is double end ? end < double.MaxValue ? end : postTrigger : postTrigger;
}
}
}
return double.PositiveInfinity;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.Globalization;
using System.Windows.Data;
using DTS.Common.Enums;
using DTS.Common.Enums.DASFactory;
namespace DTS.Common.Converters
{
public class TestDataToRegionOfInterestMinimumConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//values: DataStart, DataEnd, PreTrigger, PostTrigger, RecordingMode
if (values.Length == 5 && values[2] is double preTrigger && values[3] is double postTrigger &&
values[4] is RecordingModes recordingMode)
{
if (RecordingModeExtensions.IsAHybridRecorderMode((RecordingModes)values[4]) &&
values[0] is double d && d == double.MinValue)
{
return double.NegativeInfinity;
}
switch (recordingMode)
{
case RecordingModes.CircularBuffer:
case RecordingModes.RAMActive:
case RecordingModes.MultipleEventRAMActive:
case RecordingModes.MultipleEventCircularBuffer:
case RecordingModes.CircularBufferPlusUART:
case RecordingModes.MultipleEventCircularBufferPlusUART:
case RecordingModes.CircularBufferAndStreamSubSample:
case RecordingModes.MultipleEventCircularBufferAndStream:
//minimum is -PreTrigger
return -1D * preTrigger;
case RecordingModes.Recorder:
case RecordingModes.RecorderPlusUART:
case RecordingModes.HybridRecorder:
case RecordingModes.HybridAndStream:
case RecordingModes.MultipleEventHybridAndStream:
case RecordingModes.MultipleEventHybridRecorder:
case RecordingModes.MultipleEventRecorder:
case RecordingModes.MultipleEventRecorderPlusUART:
case RecordingModes.ContinuousRecorder:
case RecordingModes.ContinuousRecorderPlusUART:
case RecordingModes.RecordOnBoot:
case RecordingModes.RecordOnBootPlusUART:
case RecordingModes.RecorderAndStreamSubSample:
case RecordingModes.MultipleEventRecorderAndStream:
case RecordingModes.Active:
case RecordingModes.MultipleEventActive:
// FB16465: minimum is DataStart. if it's currently unknown, return -PostTrigger
// FB17991: could also be set to Min instead of unknown, same difference
return values[0] is double recStart ? recStart > double.MinValue ? recStart : -1D * postTrigger : -1D * postTrigger;
}
}
return double.NegativeInfinity;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class TriggerColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool b)
{
if (b) { return BrushesAndColors.Brush_ApplicationStatus_Failed.Color; }
else { return BrushesAndColors.Brush_ApplicationStatus_Waiting.Color; }
}
return Brushes.Transparent.Color;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace DTS.Common.Converters
{
public class TriggerTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool b)
{
if (b) { return Strings.Strings.Triggered; }
else { return Strings.Strings.TriggerClear; }
}
return Strings.Strings.TriggerClear;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Windows.Data;
using System.Windows;
namespace DTS.Common.Converters
{
public class VisibilityToRowHeightConverter : DependencyObject, IValueConverter
{
/// <summary>
/// inverts the source prior to conversion
/// </summary>
public bool InvertSource
{
get => (bool)GetValue(InvertSourceProperty);
set => SetValue(InvertSourceProperty, value);
}
public static readonly DependencyProperty InvertSourceProperty =
DependencyProperty.Register("InvertSource", typeof(bool), typeof(VisibilityToRowHeightConverter), new PropertyMetadata(false));
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is Visibility vis)
{
if (InvertSource)
{
switch (vis)
{
case Visibility.Visible:
vis = Visibility.Collapsed;
break;
case Visibility.Hidden:
case Visibility.Collapsed:
vis = Visibility.Visible;
break;
}
}
if (vis == Visibility.Collapsed)
{
return 0;
}
}
//return parameter;
return parameter ?? 0;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace DTS.Common.Converters
{
public class WidthConverter : MarkupExtension, IValueConverter
{
private static WidthConverter _instance;
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return System.Convert.ToDouble(value) * System.Convert.ToDouble(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
public override object ProvideValue(IServiceProvider serviceProvider)
{
return _instance ?? (_instance = new WidthConverter());
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Windows.Data;
//FB 44625 Converter used in Xamal to Dectect Yes/No/NotSet
namespace DTS.Common.Converters
{
public class YesNoRadioButtonsConventer : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return parameter.ToString() == value.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (bool)value ? parameter : Binding.DoNothing;
}
}
}