82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
|
|
namespace DTS.Common.Classes.ClockSync
|
|
{
|
|
/// <summary>
|
|
/// this converter is used for displaying StreamingFilterCollection/array in property grids
|
|
/// </summary>
|
|
public class ClockSyncProfileConverter : ArrayConverter
|
|
{
|
|
private ClockSyncProfileCollection _collection = null;
|
|
private static readonly object MyLock = new object();
|
|
private ClockSyncProfile[] _values = null;
|
|
private ClockSyncProfileCollection GetCollection()
|
|
{
|
|
lock (MyLock)
|
|
{
|
|
if (null == _collection)
|
|
{
|
|
_collection = ClockSyncProfileCollection.GetCollection();
|
|
}
|
|
return _collection;
|
|
}
|
|
}
|
|
public ClockSyncProfile[] Values
|
|
{
|
|
get
|
|
{
|
|
lock (MyLock)
|
|
{
|
|
if (null == _values)
|
|
{
|
|
var collection = GetCollection();
|
|
|
|
var list = new List<ClockSyncProfile>();
|
|
using (var e = collection.GetEnumerator())
|
|
{
|
|
while (e.MoveNext())
|
|
{
|
|
if( null != e.Current && e.Current.Visible)
|
|
{
|
|
list.Add(e.Current);
|
|
}
|
|
}
|
|
}
|
|
list.Sort((x,y) => { return x.DisplayOrder.CompareTo(y.DisplayOrder); });
|
|
_values = list.ToArray();
|
|
}
|
|
}
|
|
return _values;
|
|
}
|
|
}
|
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|
{
|
|
if (sourceType == typeof(string)) { return true; }
|
|
return base.CanConvertFrom(context, sourceType);
|
|
}
|
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|
{
|
|
var result = Array.Find(Values, x => x.ProfileName == (string)value);
|
|
if (result != null) { return result; }
|
|
return base.ConvertFrom(context, culture, value);
|
|
}
|
|
|
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
|
{
|
|
return true;
|
|
}
|
|
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
|
|
{
|
|
return true;
|
|
}
|
|
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
{
|
|
var collection = GetCollection();
|
|
return new StandardValuesCollection(collection);
|
|
}
|
|
}
|
|
}
|