public void Initialize()
 {
     _list = new ContinuousCollection <PropertyChangedClass>
     {
         new PropertyChangedClass {
             DecimalTargetValue = 10, TargetValue = 10
         },
         new PropertyChangedClass {
             DecimalTargetValue = 23, TargetValue = 23
         },
         new PropertyChangedClass {
             DecimalTargetValue = null, TargetValue = null
         },
         new PropertyChangedClass {
             DecimalTargetValue = 2, TargetValue = 2
         },
         new PropertyChangedClass {
             DecimalTargetValue = null, TargetValue = null
         },
         new PropertyChangedClass {
             DecimalTargetValue = null, TargetValue = null
         },
         new PropertyChangedClass {
             DecimalTargetValue = 1, TargetValue = 1
         },
     };
     _target = _list.AsReadOnly();
 }
Beispiel #2
0
        public ScopeItemViewModel(ScopeItemViewModel parent, IFolderItem folderItem, IFolderPath folderPath)
        {
            // parent can be null.
            _parent = parent;

            if (folderItem == null)
                throw new ArgumentNullException("folderItem");

            _folderItem = folderItem;

            if (folderPath == null)
                throw new ArgumentNullException("folderPath");

            _folderPath = folderPath;

            // TODO: Use the WeakPropertyChangedEventHandler (in CLINQ) to bind to some interesting properties on the IFolderItem?
            _realChildren = _folderItem.Children.Select(x => new ScopeItemViewModel(this, x, folderPath));
            //_folderItem.Children.CollectionChanged += (sender, e) => { Children = _realChildren; };
            //_realChildren.CollectionChanged += (sender, e) => { Children = _realChildren; };

            // If it can contain folders, but we don't know what they are yet, put a fake child in.
            if (_folderItem.CanContainFolders && _realChildren.Count == 0)
                Children = DeferredChildren;
            else
                Children = _realChildren;
        }
        public void AsReadOnly_SourceHasItems_ReturnsPassThroughReadOnlyContinuousCollection()
        {
            ReadOnlyContinuousCollection <Person> result = _source.AsReadOnly();

            Assert.IsNotNull(result);
            result.Should().BeOfType <PassThroughReadOnlyContinuousCollection <Person> >();
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double ActualWidth  = 400;
            double ActualHeight = 160;


            ReadOnlyContinuousCollection <StockTransaction> tickCollection =
                (ReadOnlyContinuousCollection <StockTransaction>)value;

            if (tickCollection.Count == 0)
            {
                return(null);
            }

            double priceMin = Math.Min(PreviousClosingPrice, tickCollection.Min(t => t.Price));
            double priceMax = Math.Max(PreviousClosingPrice, tickCollection.Max(t => t.Price));

            double tickMin = tickCollection.Min(t => t.TimeStamp.Ticks);
            double tickMax = tickCollection.Max(t => t.TimeStamp.Ticks);

            double yScale = ActualHeight / (priceMax - priceMin);
            double xScale = ActualWidth / Math.Min((tickMax - tickMin), _fiveMinuteWindow);

            StockTransaction[] querySource = tickCollection.ToArray(); // turn CLINQ off
            var newPoints =
                from tick in querySource
                select new Point
            {
                X = (tick.TimeStamp.Ticks - tickMin) * xScale,
                Y = (ActualHeight - (tick.Price - priceMin) * yScale)
            };

            return(new PointCollection(newPoints.ToArray()));
        }
Beispiel #5
0
        public Track(Timeline timeline, string label)
        {
            _timeline = timeline;
            _label    = label;

            Blocks = timeline.Blocks.Where(block => block.TrackNotificationPlaceholder && block.Tracks.Contains(this));
        }
Beispiel #6
0
        public void AsReadOnly_SourceHasItems_ReturnsPassThroughReadOnlyContinuousCollection()
        {
            ReadOnlyContinuousCollection <Person> result = _source.AsReadOnly();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(typeof(PassThroughReadOnlyContinuousCollection <Person>), result);
        }
Beispiel #7
0
        public SessionData()
        {
            NewPrimitives     = new ObservableCollection <NewPrimitive>();
            SnappedPrimitives = new ObservableCollection <SnappedPrimitive>();
            Annotations       = new ObservableCollection <Annotation>();
            sketchObjects     = new PointsSequence[0];
            FeatureCurves     = new ObservableCollection <FeatureCurve>();

            newPrimitivesSelectionListener = new SelectionListener <NewPrimitive>(NewPrimitives, p => p.IsSelected);
            sketchObjectsSelectionListener = new SelectionListener <PointsSequence>(sketchObjects, o => o.IsSelected);
            featureCurvesSelectionListener = new SelectionListener <FeatureCurve>(FeatureCurves, c => c.IsSelected);

            allPrimitives =
                NewPrimitives
                .Select(x => (SelectablePrimitive)x)
                .Concat(SnappedPrimitives.Select(x => (SelectablePrimitive)x));
            allPrimitivesSelectionListener = new SelectionListener <SelectablePrimitive>(allPrimitives, p => p.IsSelected);

            SelectedNewPrimitives = newPrimitivesSelectionListener.SelectedItems;
            SelectedSketchObjects = sketchObjectsSelectionListener.SelectedItems;
            SelectedFeatureCurves = featureCurvesSelectionListener.SelectedItems;
            SelectedPrimitives    = allPrimitivesSelectionListener.SelectedItems;

            PreprocessingData = new Dictionary <string, object>();
        }
        public VisualizationViewModel(SequencerViewModel sequencer)
        {
            this.sequencer   = sequencer;
            VisualizedTracks = sequencer.GetModel().Tracks.Select(t => new VisualizedTrackViewModel(t));

            ForwardPropertyEvents(nameof(sequencer.CursorPosition), sequencer, OnCursorPositionChanged, true);
            ForwardPropertyEvents(nameof(IsEnabled), this, OnIsEnabledChanged);
        }
Beispiel #9
0
        public void Select_ReadOnlyObservableCollection_InputContentsMatchOutputContents()
        {
            var readOnlySource = new ReadOnlyObservableCollection <Person>(_source);
            ReadOnlyContinuousCollection <Person> output = from person in readOnlySource
                                                           select person;

            Assert.AreEqual(readOnlySource, output);
        }
Beispiel #10
0
        public void Where_FilterContainsAConstant_CorrectlyFiltered()
        {
            Person person = new Person("Ninja", 20);

            ReadOnlyContinuousCollection <Person> peopleMatchingAge = person.GetPeopleWithSameAge(_source);

            Assert.AreEqual(1, peopleMatchingAge.Count);
        }
Beispiel #11
0
        public void Where_SimpleOnePropertyFilter_ItemsFiltered()
        {
            ReadOnlyContinuousCollection <Person> output = from person in _source
                                                           where person.Age > 10
                                                           select person;

            Assert.AreEqual(1, output.Count);
        }
Beispiel #12
0
        public void Where_FilterContainsTwoLevelConstantWithConstantNull_CorrectResultsReturned()
        {
            Person person = new Person("Ninja", 20);

            ReadOnlyContinuousCollection <Person> peopleMatchingAge = person.GetPeopleWithSameAgeAsBrother(_source);

            Assert.AreEqual(0, peopleMatchingAge.Count);
        }
        public NotesViewModel(SequencerViewModel sequencer)
        {
            this.sequencer = sequencer;
            Notes          = sequencer.GetModel().Notes.Select(note => new NoteViewModel(sequencer, note));
            NotesSorted    = Notes.OrderBy(note => note.TimeSeconds);

            ForwardCollectionEvents(Notes, nameof(HasNotes));
        }
Beispiel #14
0
        public void Sort_ThenBy_CountRemainsTheSame()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age, person.Name
            select person;

            Assert.AreEqual(_source.Count, output.Count);
        }
        public void AsReadOnly_SourceHasItems_AllItemsInResult()
        {
            ReadOnlyContinuousCollection <Person> result = _source.AsReadOnly();

            for (int i = 0; i < _source.Count; i++)
            {
                Assert.AreEqual(_source[i], result[i]);
            }
        }
Beispiel #16
0
 public static ContinuousValue <double> ContinuousVwap <T>(
     this ReadOnlyContinuousCollection <T> input,
     Func <T, double> priceSelector,
     Func <T, int> quantitySelector,
     Action <double> afterEffect)
     where T : INotifyPropertyChanged
 {
     return(new ContinuousValue <T, double, double>(input, null,
                                                    (list, selector) => ComputeVwap <T>(list, priceSelector, quantitySelector), afterEffect));
 }
        public void Sort_Descending_TailBecomesHead()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age descending
                select person;

            _source[_source.Count - 1].Age = 99; // reversed direction, set to 99 should put it first.
            Assert.AreEqual(_source[_source.Count - 1].Age, output[0].Age);
        }
        public TrackViewModel(SequencerViewModel sequencer, Model.Track model)
        {
            this.sequencer = sequencer;
            this.model     = model;

            ForwardPropertyEvents(nameof(model.Label), model, nameof(Label));
            ForwardPropertyEvents(nameof(sequencer.SelectedTrack), sequencer, nameof(IsSelected));

            Blocks = model.Blocks.Select(b => BlockViewModel.FromModel(sequencer, b));
        }
        public void Sort_Descending_HeadBecomesTail()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age descending
                select person;

            _source[0].Age = -1; // reversed direction, set to -1 should put it last.

            Assert.AreEqual(_source[0].Age, output[output.Count - 1].Age);
        }
        public void Sort_HeadBecomesTail()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age
                select person;

            _source[0].Age = 99; //move the first to the last.

            Assert.AreEqual(_source[0].Age, output[output.Count - 1].Age);
        }
        public void Sort_TailBecomesHead()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age
                select person;

            _source[_source.Count - 1].Age = -1;

            Assert.AreEqual(_source[_source.Count - 1].Age, output[0].Age);
        }
Beispiel #22
0
        public void Select_SimplePassThrough_InputContentsMatchOutputContents()
        {
            ReadOnlyContinuousCollection <Person> output = from person in _source
                                                           select person;

            Assert.AreEqual(_source.Count, output.Count);

            for (int i = 0; i < _source.Count; i++)
            {
                Assert.AreSame(_source[i], output[i]);
            }
        }
Beispiel #23
0
        public void Setup()
        {
            _source = ClinqTestFactory.CreateTwoPersonSourceWithParents();

            _parents = new ObservableCollection <ObservableCollection <Person> >()
            {
                _source[0].Parents,
                _source[1].Parents
            };

            _target = _source.SelectMany(src => src.Parents);
        }
Beispiel #24
0
        public void Setup()
        {
            _outer = ClinqTestFactory.CreateTwoPersonSource();
            _inner = ClinqTestFactory.CreateTwoPersonSource();

            _target = from outerPerson in _outer
                      join innerPerson in _inner on outerPerson.Age equals innerPerson.Age into innersMatchingOuterAge
                      select new Pair <Person, ReadOnlyContinuousCollection <Person> >(outerPerson, innersMatchingOuterAge);

            _standardLinqResults = from outerPerson in _outer.AsEnumerable()
                                   join innerPerson in _inner on outerPerson.Age equals innerPerson.Age into innersMatchingOuterAge
                                   select new Pair <Person, IEnumerable <Person> >(outerPerson, innersMatchingOuterAge);
        }
        public void Sort_SortedListRemainsSorted()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age
                select person;

            // source list is already pre-sorted by age, verify that it
            // stayed that way.
            for (int x = 0; x < _source.Count; x++)
            {
                Assert.AreEqual(_source[x].Age, output[x].Age);
            }
        }
        public VisualizationViewModel()
        {
            sequencer = null;
            var tl = new Timeline();

            VisualizedTracks = new ObservableCollection <Track> {
                new Track(tl, "Track 01"),
                new Track(tl, "Track 02"),
                new Track(tl, "Track 03"),
                new Track(tl, "Track 04"),
                new Track(tl, "Track 05"),
                new Track(tl, "Track 06"),
            }.Select(t => new VisualizedTrackViewModel(t));
        }
Beispiel #27
0
        public void Select_SourceContainsNonNotifyingObject_OnlyMonitorsCollectionChanges()
        {
            ObservableCollection <int> source = new ObservableCollection <int> {
                0, 1, 2, 3
            };
            ReadOnlyContinuousCollection <int> result = source.Select(item => item);
            int callCount = 0;

            result.CollectionChanged += (sender, args) => callCount++;

            source.Add(4);

            Assert.AreEqual(1, callCount);
            Assert.AreEqual(4, result[4]);
        }
Beispiel #28
0
        public void Where_FilterContainsAConstantWithPropertyChangingOnConstant_CorrectResultsReturned()
        {
            Person person = new Person("Ninja", 20);

            ReadOnlyContinuousCollection <Person> peopleMatchingAge = person.GetPeopleWithSameAge(_source);

            int callCount = 0;

            peopleMatchingAge.CollectionChanged += (sender, args) => callCount++;

            person.Age = 10;

            Assert.AreEqual(2, callCount); // one remove and one add
            Assert.AreEqual(1, peopleMatchingAge.Count);
        }
        public void Sort_Descending_SortedItemsAreInProperIndexes()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age descending
                select person;

            int outputIdx = output.Count - 1;

            for (int sourceIdx = 0; sourceIdx < _source.Count; sourceIdx++)
            {
                Assert.AreEqual(_source[sourceIdx].Age, output[outputIdx].Age);
                outputIdx--;
            }
        }
Beispiel #30
0
        public void Sort_ThenBy_SortedItemsAreInProperIndexes()
        {
            ReadOnlyContinuousCollection <Person> output =
                from person in _source
                orderby person.Age, person.Name
            select person;

            Assert.AreEqual(output[0].Age, 0);
            Assert.AreEqual(output[1].Age, 20);
            Assert.AreEqual(output[2].Age, 20);
            // output IDX 1 should be alfonse
            // output IDX 2 should be zoolander

            Assert.AreEqual(output[1].Name, "Alfonse");
            Assert.AreEqual(output[2].Name, "Zoolander");
        }
Beispiel #31
0
        public MusicSegmentViewModel(SequencerViewModel sequencer, Model.MusicSegment model)
        {
            this.sequencer = sequencer;
            this.model     = model;

            ReferringBlocksDummies = sequencer.GetModel().Blocks.Where(b => b.SegmentContext == model).Select(b => (object)null);

            ForwardPropertyEvents(nameof(model.Label), model, nameof(Label));
            ForwardPropertyEvents(nameof(model.Bpm), model, nameof(Bpm));
            ForwardPropertyEvents(nameof(model.BeatsPerBar), model, nameof(BeatsPerBar));
            ForwardPropertyEvents(nameof(model.TimeOrigin), model, nameof(TimeOrigin), nameof(TimeOriginSeconds));
            ForwardPropertyEvents(nameof(model.IsReadOnly), model, nameof(IsReadOnly));
            ForwardPropertyEvents(nameof(model.IsDefault), model, nameof(IsDefault));

            ForwardPropertyEvents(nameof(Bpm), this, () => sequencer.NotifyGridInterval());
        }
Beispiel #32
0
        public ModelRoot()
        {
            _allTransactions = new ObservableCollection<StockTransaction>();

            // Note that all of these queries are defined against an EMPTY
            // source collection...
            _bids = from tx in _allTransactions
                    where tx.TransactionType == TransactionType.Bid &&
                          tx.Symbol == "AAPL"
                    orderby tx.Price ascending
                    select tx;

            _asks = from tx in _allTransactions
                    where tx.TransactionType == TransactionType.Ask &&
                          tx.Symbol == "AAPL"
                    orderby tx.Price descending
                    select tx;

            _executions = from tx in _allTransactions
                          where tx.TransactionType == TransactionType.Execution &&
                                tx.Symbol == "AAPL"
                          orderby tx.Price descending
                          select tx;

            _graphExecutions = from tx in _executions
                               where tx.TimeStamp >= DateTime.Now.AddMinutes(-5)
                               select tx;

            _minPrice = _executions.ContinuousMin(tx => tx.Price,
                                                       newPrice => this.CurrentMin = newPrice);
            _maxPrice = _executions.ContinuousMax(tx => tx.Price,
                                                       newPrice => this.CurrentMax = newPrice);

            _vwap = _executions.ContinuousVwap(tx => tx.Price, tx => tx.Quantity,
                newVwap => this.CurrentVwap = newVwap);

            _simulationTimer = new Timer(1000);
            _simulationTimer.Elapsed += GenerateBogusData;
            _simulationTimer.Start();
        }
        public void Setup()
        {
            _source = ClinqTestFactory.CreateTwoPersonSourceWithParents();

            _parents = new ObservableCollection<ObservableCollection<Person>>()
            {
                _source[0].Parents,
                _source[1].Parents
            };

            _target = _source.SelectMany(src => src.Parents);
        }
 public void Initialize()
 {
     _list = new ContinuousCollection<PropertyChangedClass>
                   {
                       new PropertyChangedClass { DecimalTargetValue = 10, TargetValue = 10 },
                       new PropertyChangedClass { DecimalTargetValue = 23, TargetValue = 23 },
                       new PropertyChangedClass { DecimalTargetValue = null, TargetValue = null },
                       new PropertyChangedClass { DecimalTargetValue = 2, TargetValue = 2 },
                       new PropertyChangedClass { DecimalTargetValue = null, TargetValue = null },
                       new PropertyChangedClass { DecimalTargetValue = null, TargetValue = null },
                       new PropertyChangedClass { DecimalTargetValue = 1, TargetValue = 1 },
                   };
     _target = _list.AsReadOnly();
 }