using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; using System.Globalization; using DTS.Common.Settings; namespace DTS.Slice.Users.UserSettings { public class SampleRateConverter : DoubleConverter { List _validSampleRateList = new List(); private const int SampleRateIndiceCountDefault = 24; private const int SPSINDICE_COUNT = 56; private const string SAMPLERATE_INDEX = "SPSINDEX_"; public static int[] AvailableSampleRatesDefault = new int[] { 5, 50, 100, 200, 250, //TDC rates start here, everything from here to next comment is in default TDC.ini 500, 1000, 2000, 2500, 5000, 8000, 10000, 12500, 20000, 25000, 40000, 50000, 60000, 75000, 100000, 150000, 300000, //TDC rates end here 400000, 500000, 1000000 }; public SampleRateConverter() { } //public SampleRateConverter(List validSampleRateList) //{ // _validSampleRateList = validSampleRateList; //} public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { var SampleRateIndiceCount = SettingsDB.GetGlobalValueInt(SPSINDICE_COUNT.ToString(), SampleRateIndiceCountDefault); _validSampleRateList.Clear(); for (var i = 0; i < SampleRateIndiceCount; i++) { var defaultValue = -1; if (i < AvailableSampleRatesDefault.Length) { defaultValue = AvailableSampleRatesDefault[i]; } var value = SettingsDB.GetGlobalValueInt(SAMPLERATE_INDEX + i.ToString(CultureInfo.InvariantCulture), defaultValue); if (_validSampleRateList.Contains(value)) continue; if (value > 0) { _validSampleRateList.Add(Convert.ToDouble(value)); } } return new StandardValuesCollection(_validSampleRateList.ToArray()); } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { return base.ConvertFrom(context, culture, value); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return base.CanConvertFrom(context, sourceType); } public override bool CanConvertTo(ITypeDescriptorContext context, Type t) { return base.CanConvertTo(context, t); } } }