Example #1
0
        private void GlucoseOnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            var glucose  = (GlucoseItem)sender;
            var oldPoint = glucose.GetDataPoint();

            GlucoseDataPoints.Remove(oldPoint);
            AddGlucoseDatapoint(glucose.GenerateDataPoint());
            RaisePropertyChanged(() => GlucoseDataPoints);
        }
Example #2
0
        private void PopulateGlucoseDataPoints()
        {
            foreach (var glucose in Glucoses)
            {
                GlucoseDataPoints.Add(glucose.GetDataPoint());
            }
            ;

            GlucoseDataPoints.Sort(point => point.X);
        }
Example #3
0
        public void AddGlucoseDatapoint(DataPoint point)
        {
            var item = GlucoseDataPoints.FirstOrDefault(p => p.X > point.X);

            if (item.Equals(new DataPoint()))
            {
                GlucoseDataPoints.Add(point);
            }
            else
            {
                var index = GlucoseDataPoints.IndexOf(item);
                GlucoseDataPoints.Insert(index, point);
            }
        }
Example #4
0
        private void GlucoseCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:

                foreach (GlucoseItem glucose in args.NewItems)
                {
                    AddGlucoseDatapoint(glucose.GetDataPoint());
                }
                break;

            case NotifyCollectionChangedAction.Remove:

                foreach (GlucoseItem glucose in args.OldItems)
                {
                    GlucoseDataPoints.Remove(glucose.GetDataPoint());
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                int count = args.OldItems.Count;
                for (int i = 0; i < count; i++)
                {
                    var glucose = args.OldItems[i] as GlucoseItem;
                    if (!GlucoseDataPoints.Contains(glucose.GetDataPoint()))
                    {
                        throw new ValueUnavailableException("Datapoint is missing.");
                    }

                    GlucoseDataPoints.Remove(glucose.GetDataPoint());
                    if (args.NewItems[i] is GlucoseItem newGlucose)
                    {
                        AddGlucoseDatapoint(newGlucose.GetDataPoint());
                    }
                }

                break;

            case NotifyCollectionChangedAction.Move:
                break;

            case NotifyCollectionChangedAction.Reset:
                GlucoseDataPoints.Clear();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }