public void AutomaticallyNestingUsingLinq() { var a = new CompositeSourceList<CompositeSourceList<int>>(); var b = new CompositeSourceList<int>(); var c = new CompositeSourceList<int>(); var d = new CompositeSourceList<int>(); var e = from p in a from q in p select q; b.Source = b.Source.Add(1); b.Source = b.Source.Add(2); a.Source = a.Source.Add(b); using (var s = e.Subscribe()) { s.Items.Should().BeEquivalentTo(1,2); a.Source = a.Source.Remove(b); s.Items.Should().BeEquivalentTo(); a.Source = a.Source.Add(c); s.Items.Should().BeEquivalentTo(); c.Source = c.Source.Add(2); s.Items.Should().BeEquivalentTo(2); c.Source = c.Source.Add(3); s.Items.Should().BeEquivalentTo(2,3); a.Source=a.Source.Add(b); s.Items.Should().BeEquivalentTo(2,3,1,2); } }
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 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 WhereShouldBePerformant() { var a = new CompositeSourceList <CompositeSourceList <CompositeSourceList <int> > >(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a from t in clist where t.Any(v => v > 10) select t.Select(v => v + 1); using (var s = b.Subscribe()) { var x = new CompositeSourceList <CompositeSourceList <int> >(); var y = new CompositeSourceList <CompositeSourceList <int> >(); a.Add(x); a.Add(y); var xx = new CompositeSourceList <int>(); var yy = new CompositeSourceList <int>(); x.Add(xx); y.Add(yy); for (int i = 0; i < 100000; i++) { xx.Add(i); yy.Add(i + 1); } s.Items.Count.Should().BeGreaterThan(0); } }
public void DynamicWhereShouldWork() { var a = new CompositeSourceList <int>(); var b = new CompositeSourceList <int>(); var filter = new BehaviorSubject <Func <int, bool> >(v => v > 5); var c = a.Concat(b).Where(filter); using (var r = c.Subscribe()) { r.Items.Count.Should().Be(0); a.AddRange(new List <int> { 1, 2, 3 }); r.Items.Should().BeEquivalentTo(); b.AddRange(new List <int> { 5, 6, 7 }); r.Items.Should().BeEquivalentTo(6, 7); } filter.OnNext(v => true); using (var r = c.Subscribe()) { r.Items.Should().BeEquivalentTo(1, 2, 3, 5, 6, 7); } }
public void WhereManyShouldWork() { var a = new CompositeSourceList <CompositeSourceList <int> >(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a where clist.Any(v => v > 10) select clist; using (var s = b.Subscribe()) { var x = new CompositeSourceList <int>(); var y = new CompositeSourceList <int>(); a.Add(x); a.Add(y); s.Items.Count.Should().Be(0); x.Add(9); s.Items.Count.Should().Be(0); x.Add(11); s.Items.Count.Should().Be(1); y.Add(12); s.Items.Count.Should().Be(2); x.Remove(11); s.Items.Count.Should().Be(1); x.Remove(9); s.Items.Count.Should().Be(1); y.Remove(12); s.Items.Count.Should().Be(0); } }
public void AddedObservableShouldWork() { var a = new CompositeSourceList<int>(); var b = new CompositeSourceList<int>(); var c = a.Concat(b); var addedResult = new List<IReadOnlyCollection<int>>(); var removedResult = new List<IReadOnlyCollection<int>>(); c.AddedToSetObservable().Subscribe(added => addedResult.Add(added)); c.RemovedFromSetObservable().Subscribe(removed => removedResult.Add(removed)); a.AddRange(new [] {1,2}); b.AddRange(new [] {8,2}); b.Remove(8); a.Remove(2); // Doesn't cause a remove event as 2 belongs to both sources a.Remove(1); addedResult[0].Should().BeEquivalentTo(1, 2); addedResult[1].Should().BeEquivalentTo(8); removedResult[0].Should().BeEquivalentTo(8); removedResult[1].Should().BeEquivalentTo(1); }
public void AutomaticallyNestingUsingLinq() { var a = new CompositeSourceList <CompositeSourceList <int> >(); var b = new CompositeSourceList <int>(); var c = new CompositeSourceList <int>(); var d = new CompositeSourceList <int>(); var e = from p in a from q in p select q; b.Source = b.Source.Add(1); b.Source = b.Source.Add(2); a.Source = a.Source.Add(b); using (var s = e.Subscribe()) { s.Items.Should().BeEquivalentTo(1, 2); a.Source = a.Source.Remove(b); s.Items.Should().BeEquivalentTo(); a.Source = a.Source.Add(c); s.Items.Should().BeEquivalentTo(); c.Source = c.Source.Add(2); s.Items.Should().BeEquivalentTo(2); c.Source = c.Source.Add(3); s.Items.Should().BeEquivalentTo(2, 3); a.Source = a.Source.Add(b); s.Items.Should().BeEquivalentTo(2, 3, 1, 2); } }
public void AddedObservableShouldWork() { var a = new CompositeSourceList <int>(); var b = new CompositeSourceList <int>(); var c = a.Concat(b); var addedResult = new List <IReadOnlyCollection <int> >(); var removedResult = new List <IReadOnlyCollection <int> >(); c.AddedToSetObservable().Subscribe(added => addedResult.Add(added)); c.RemovedFromSetObservable().Subscribe(removed => removedResult.Add(removed)); a.AddRange(new [] { 1, 2 }); b.AddRange(new [] { 8, 2 }); b.Remove(8); a.Remove(2); // Doesn't cause a remove event as 2 belongs to both sources a.Remove(1); addedResult[0].Should().BeEquivalentTo(1, 2); addedResult[1].Should().BeEquivalentTo(8); removedResult[0].Should().BeEquivalentTo(8); removedResult[1].Should().BeEquivalentTo(1); }
public LogViewer() { InitializeComponent(); LogEntries = new CompositeSourceList<LogEntry>(); this.LoadUnloadHandler(() => Init()); }
public LogViewer() { InitializeComponent(); LogEntries = new CompositeSourceList <LogEntry>(); this.LoadUnloadHandler(() => Init()); }
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 void BindingShouldWork() { var a = new CompositeSourceList <int>(); var b = new CompositeSourceList <int>(); var c = new CompositeSourceList <int>(); var d = b.Concat(c); d.Bind(a); }
public static IDisposable CreateControls(PropertyManagerPageBase pmp, IPropertyManagerPageGroup @group, CompositeSourceList <SwEq> list) { var d = new CompositeDisposable(); for (var i = 0; i < list.Source.Count; i++) { d.Add(CreateControl(pmp, @group, list, i)); } return(d); }
public void SelectManyWorkWithIEnumerable() { var a = new CompositeSourceList <IList <int> >(); var b = a.SelectMany(v => v); using (var r = b.Subscribe()) { r.Items.Count.Should().Be(0); a.Source = a.Source.Add(new List <int> { 1, 2, 3 }); r.Items.Should().BeEquivalentTo(1, 2, 3); } }
public void WhereShouldWork() { var a = new CompositeSourceList <int>(); var b = new CompositeSourceList <int>(); var c = a.Concat(b).Where(v => v > 5); using (var r = c.Subscribe()) { r.Items.Count.Should().Be(0); a.AddRange(new List <int> { 1, 2, 3 }); r.Items.Should().BeEquivalentTo(); b.AddRange(new List <int> { 5, 6, 7 }); r.Items.Should().BeEquivalentTo(6, 7); a.Source = ImmutableList <int> .Empty; r.Items.Should().BeEquivalentTo(6, 7); } }
public void ShouldBeAbleToConcatLists() { var a = new CompositeSourceList <int>(); var b = new CompositeSourceList <int>(); var c = a.Concat(b); using (var r = c.Subscribe()) { r.Items.Count.Should().Be(0); a.AddRange(new List <int> { 1, 2, 3 }); r.Items.Should().BeEquivalentTo(1, 2, 3); b.AddRange(new List <int> { 5, 6, 7 }); r.Items.Should().BeEquivalentTo(1, 2, 3, 5, 6, 7); a.Source = ImmutableList <int> .Empty; r.Items.Should().BeEquivalentTo(5, 6, 7); } }
public void AutomaticallyNestingWithTransformationAndLinq() { var a = new CompositeSourceList <ICompositeList <string> >(); var b = new CompositeSourceList <int>(); var c = new CompositeSourceList <int>(); var e = from p in a from q in p select q + "x"; b.Source = b.Source.Add(1); b.Source = b.Source.Add(2); var bt = b.Select(v => v.ToString()); a.Source = a.Source.Add(bt); var count = 0; using (var s = e.Subscribe()) { s.PropertyChanged += (_, __) => count++; s.Items.Should().BeEquivalentTo("1x", "2x"); a.Source = a.Source.Remove(bt); s.Items.Should().BeEquivalentTo(); a.Source = a.Source.Add(c.Select(v => v.ToString())); s.Items.Should().BeEquivalentTo(); c.Source = c.Source.Add(2); s.Items.Should().BeEquivalentTo("2x"); c.Source = c.Source.Add(3); s.Items.Should().BeEquivalentTo("2x", "3x"); a.Source = a.Source.Add(bt); s.Items.Should().BeEquivalentTo("2x", "3x", "1x", "2x"); } // 6 changes should be recorded count.Should().Be(4); }
public void ManuallyNesting() { var a = new CompositeSourceList <int>(); var b = new CompositeSourceList <int>(); var c = new CompositeSourceList <int>(); var x = a.Concat(b); var y = x.Concat(c); using (var s = y.Subscribe()) { s.Items.Should().BeEmpty(); a.Source = a.Source.Add(1); s.Items.ShouldBeEquivalentTo(new[] { 1 }); b.Source = b.Source.Add(1); s.Items.Should().BeEquivalentTo(new[] { 1, 1 }); b.Source = b.Source.Add(3); s.Items.Should().BeEquivalentTo(new[] { 1, 1, 3 }); c.Source = c.Source.AddRange(new [] { 5, 6, 8 }); s.Items.Should().BeEquivalentTo(new[] { 1, 1, 3, 5, 6, 8 }); } }
public void AutomaticallyNestingWithTransformationAndLinq() { var a = new CompositeSourceList<ICompositeList<string>>(); var b = new CompositeSourceList<int>(); var c = new CompositeSourceList<int>(); var e = from p in a from q in p select q+"x"; b.Source=b.Source.Add(1); b.Source=b.Source.Add(2); var bt = b.Select(v=>v.ToString()); a.Source=a.Source.Add(bt); var count = 0; using (var s = e.Subscribe()) { s.PropertyChanged += (_,__)=>count++; s.Items.Should().BeEquivalentTo("1x", "2x"); a.Source=a.Source.Remove(bt); s.Items.Should().BeEquivalentTo(); a.Source=a.Source.Add(c.Select(v=>v.ToString())); s.Items.Should().BeEquivalentTo(); c.Source=c.Source.Add(2); s.Items.Should().BeEquivalentTo("2x"); c.Source=c.Source.Add(3); s.Items.Should().BeEquivalentTo("2x", "3x"); a.Source=a.Source.Add(bt); s.Items.Should().BeEquivalentTo("2x", "3x", "1x", "2x"); } // 6 changes should be recorded count.Should().Be(4); }
public void ShouldWorkWithRangeOperators() { 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.AddRange(new [] {0,1,2}); observableCollection.Should().Equal(0, 1,2); source0.Add(1); source1.Add(6); observableCollection.Should().Equal(0, 1, 2, 1, 6); source1.AddRange(new [] {3,4,5}); observableCollection.Should().Equal(0, 1, 2, 1, 6, 3, 4, 5); source0.InsertRangeAt(1, new [] {6,7}); observableCollection.Should().Equal(0, 6, 7, 1, 2, 1, 6, 3, 4, 5); source1.InsertRangeAt(1, new [] {6,7}); observableCollection.Should().Equal(0, 6, 7, 1, 2, 1, 6, 6, 7, 3, 4, 5); source0.Source.Should().Equal(0, 6, 7, 1, 2,1); source0.Replace(1,99); observableCollection.Should().Equal(0, 6, 7, 99, 2, 1, 6, 6, 7, 3, 4, 5); } }
public void BindingShouldWork() { var a = new CompositeSourceList<int>(); var b = new CompositeSourceList<int>(); var c = new CompositeSourceList<int>(); var d = b.Concat(c); d.Bind(a); }
public void DynamicWhereShouldWork() { var a = new CompositeSourceList<int>(); var b = new CompositeSourceList<int>(); var filter = new BehaviorSubject<Func<int,bool>>(v=>v>5); var c = a.Concat(b).Where(filter); using (var r = c.Subscribe()) { r.Items.Count.Should().Be(0); a.AddRange(new List<int> {1,2,3}); r.Items.Should().BeEquivalentTo(); b.AddRange(new List<int> {5,6,7}); r.Items.Should().BeEquivalentTo(6,7); } filter.OnNext(v=>true); using (var r = c.Subscribe()) { r.Items.Should().BeEquivalentTo(1, 2, 3, 5, 6, 7); } }
public void ManuallyNesting() { var a = new CompositeSourceList<int>(); var b = new CompositeSourceList<int>(); var c = new CompositeSourceList<int>(); var x = a.Concat(b); var y = x.Concat(c); using (var s = y.Subscribe()) { s.Items.Should().BeEmpty(); a.Source=a.Source.Add(1); s.Items.ShouldBeEquivalentTo(new[]{1}); b.Source=b.Source.Add(1); s.Items.Should().BeEquivalentTo(new[]{1,1}); b.Source=b.Source.Add(3); s.Items.Should().BeEquivalentTo(new[]{1,1,3}); c.Source=c.Source.AddRange(new [] {5,6,8}); s.Items.Should().BeEquivalentTo(new[]{1,1,3,5,6,8}); } }
public void SelectManyWorkWithIEnumerable() { var a = new CompositeSourceList<IList<int>>(); var b = a.SelectMany(v => v); using (var r = b.Subscribe()) { r.Items.Count.Should().Be(0); a.Source = a.Source.Add(new List<int> {1, 2, 3}); r.Items.Should().BeEquivalentTo(1, 2, 3); } }
public void ShouldBeAbleToConcatLists() { var a = new CompositeSourceList<int>(); var b = new CompositeSourceList<int>(); var c = a.Concat(b); using (var r = c.Subscribe()) { r.Items.Count.Should().Be(0); a.AddRange(new List<int> {1,2,3}); r.Items.Should().BeEquivalentTo(1, 2, 3); b.AddRange(new List<int> {5,6,7}); r.Items.Should().BeEquivalentTo(1, 2, 3,5,6,7); a.Source = ImmutableList<int>.Empty; r.Items.Should().BeEquivalentTo(5,6,7); } }
public void WhereManyShouldWork() { var a = new CompositeSourceList<CompositeSourceList<int>>(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a where clist.Any(v => v > 10) select clist; using (var s = b.Subscribe()) { var x = new CompositeSourceList<int>(); var y = new CompositeSourceList<int>(); a.Add(x); a.Add(y); s.Items.Count.Should().Be(0); x.Add(9); s.Items.Count.Should().Be(0); x.Add(11); s.Items.Count.Should().Be(1); y.Add(12); s.Items.Count.Should().Be(2); x.Remove(11); s.Items.Count.Should().Be(1); x.Remove(9); s.Items.Count.Should().Be(1); y.Remove(12); s.Items.Count.Should().Be(0); } }
public void WhereShouldBePerformant() { var a = new CompositeSourceList<CompositeSourceList<CompositeSourceList<int>>>(); // Note that clist.Any(v => v>10) returns IObservable<bool> var b = from clist in a from t in clist where t.Any(v => v > 10) select t.Select(v=>v+1); using (var s = b.Subscribe()) { var x = new CompositeSourceList<CompositeSourceList<int>>(); var y = new CompositeSourceList<CompositeSourceList<int>>(); a.Add(x); a.Add(y); var xx = new CompositeSourceList<int>(); var yy = new CompositeSourceList<int>(); x.Add(xx); y.Add(yy); for (int i = 0; i < 100000; i++) { xx.Add(i); yy.Add(i+1); } s.Items.Count.Should().BeGreaterThan(0); } }
public static IDisposable CreateControls(PropertyManagerPageBase pmp, IPropertyManagerPageGroup @group, CompositeSourceList<SwEq> list) { var d = new CompositeDisposable(); for (var i = 0; i < list.Source.Count; i++) { d.Add(CreateControl(pmp, @group, list, i)); } return d; }
public void WhereShouldWork() { var a = new CompositeSourceList<int>(); var b = new CompositeSourceList<int>(); var c = a.Concat(b).Where(v=>v>5); using (var r = c.Subscribe()) { r.Items.Count.Should().Be(0); a.AddRange(new List<int> {1,2,3}); r.Items.Should().BeEquivalentTo(); b.AddRange(new List<int> {5,6,7}); r.Items.Should().BeEquivalentTo(6,7); a.Source = ImmutableList<int>.Empty; r.Items.Should().BeEquivalentTo(6,7); } }
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)); }