public void DynamicFilterShouldWork() { var data = new CompositeSourceList <int>(); var filters = new CompositeSourceList <Func <int, bool> >(); // Compose a dynamic filtering system by using a CompositeSourceList // to hold a filter. var target = from fn in filters from s in data where fn(s) select s; data.AddRange(new [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); // Convert to an observable collection for testing purposes using (var oc = target.CreateObservableCollection(EqualityComparer <int> .Default)) { // Set the filter to be everything greater than 5 filters.Add(v => v > 5); oc.Should().Equal(6, 7, 8, 9, 10); // Set the filter to be everything less than 5 filters.ReplaceAt(0, v => v < 5); oc.Should().Equal(0, 1, 2, 3, 4); } }
public void ShouldWork() { var source0 = new CompositeSourceList<int>(); var source1 = new CompositeSourceList<int>(); var target = source0.Concat(source1); using (var observableCollection = target.CreateObservableCollection(EqualityComparer<int>.Default)) { observableCollection.Count.Should().Be(0); source0.Add(0); source1.Add(5); observableCollection.Should().Equal(0, 5); source0.Add(1); source1.Add(6); observableCollection.Should().Equal(0, 1, 5, 6); source0.Remove(1); observableCollection.Should().Equal(0, 5, 6); source1.Remove(5); observableCollection.Should().Equal(0, 6); source0.ReplaceAt(0, 10); observableCollection.Should().Equal(10, 6); } }
public void ShouldWork() { var source0 = new CompositeSourceList <int>(); var source1 = new CompositeSourceList <int>(); var target = source0.Concat(source1); using (var observableCollection = target.CreateObservableCollection(EqualityComparer <int> .Default)) { observableCollection.Count.Should().Be(0); source0.Add(0); source1.Add(5); observableCollection.Should().Equal(0, 5); source0.Add(1); source1.Add(6); observableCollection.Should().Equal(0, 1, 5, 6); source0.Remove(1); observableCollection.Should().Equal(0, 5, 6); source1.Remove(5); observableCollection.Should().Equal(0, 6); source0.ReplaceAt(0, 10); observableCollection.Should().Equal(10, 6); } }
public static IDisposable CreateControl(PropertyManagerPageBase pmp, IPropertyManagerPageGroup @group, CompositeSourceList <SwEq> list, int index) { var equation = list.Source[index]; var caption = equation.Id.CamelCaseToHumanReadable(); var label = pmp.CreateLabel(@group, caption, caption); var id = pmp.NextId(); var box = @group.CreateNumberBox(id, caption, caption); if (equation.UnitsType == UnitsEnum.Angle) { box.SetRange2((int)swNumberboxUnitType_e.swNumberBox_Angle, -10, 10, true, 0.005, 0.010, 0.001); box.DisplayedUnit = (int)swAngleUnit_e.swDEGREES; } else { const double increment = 1e-2; box.SetRange2((int)swNumberboxUnitType_e.swNumberBox_Length, -10, 10, true, increment, increment * 10, increment / 10); box.DisplayedUnit = (int)swLengthUnit_e.swMM; } var obs = pmp.NumberBoxChangedObservable(id); var d2 = obs.Subscribe(value => list.ReplaceAt(index, equation.WithValue(value))); var d3 = list.ChangesObservable() .Ignore() .StartWith(Unit.Default) // Don't set value when we selected another model with less equations. We will recreate the controls anyway. .Where(_ => list.Source.Count > index) .Subscribe(v => box.Value = list.Source[index].Val); return(ControlHolder.Create(@group, box, d2, label, d3)); }
public static IDisposable CreateControl(PropertyManagerPageBase pmp, IPropertyManagerPageGroup @group, CompositeSourceList<SwEq> list, int index) { var equation = list.Source[index]; var caption = equation.Id.CamelCaseToHumanReadable(); var label = pmp.CreateLabel(@group, caption, caption); var id = pmp.NextId(); var box = @group.CreateNumberBox(id, caption, caption); if (equation.UnitsType == UnitsEnum.Angle) { box.SetRange2((int) swNumberboxUnitType_e.swNumberBox_Angle, -10, 10, true, 0.005, 0.010, 0.001); box.DisplayedUnit = (int) swAngleUnit_e.swDEGREES; } else { const double increment = 1e-2; box.SetRange2((int)swNumberboxUnitType_e.swNumberBox_Length, -10, 10, true, increment, increment * 10, increment / 10); box.DisplayedUnit = (int)swLengthUnit_e.swMM; } var obs = pmp.NumberBoxChangedObservable(id); var d2 = obs.Subscribe(value => list.ReplaceAt(index,equation.WithValue(value))); var d3 = list.ChangesObservable() .Ignore() .StartWith(Unit.Default) // Don't set value when we selected another model with less equations. We will recreate the controls anyway. .Where(_ => list.Source.Count > index) .Subscribe(v => box.Value = list.Source[index].Val); return ControlHolder.Create(@group, box, d2, label, d3); }