public MainWindowViewModel(IWindowManager windowManager, SimpleContainer container)
        {
            _windowManager = windowManager;
            _container = container;

            _sensorsToGraph = new ObservableCollection<GraphableSensor>();
            SensorsToCheckMethodsAgainst = new ObservableCollection<Sensor>();

            _erroneousValuesFromDataTable = new List<ErroneousValue>();

            #region Set Up Detection Methods
            ShowLastZoom = false;
            _minMaxDetector = new MinMaxDetector();
            _minMaxDetector.GraphUpdateNeeded += () =>
                                                     {
                                                         SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph,
                                                                      "MinMaxDetectorGraphUpdate");
                                                         CalculateYAxis(false);
                                                     };

            _runningMeanStandardDeviationDetector = new RunningMeanStandardDeviationDetector();
            _runningMeanStandardDeviationDetector.GraphUpdateNeeded += () => SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "RunningMeanGraphUpdate");

            _runningMeanStandardDeviationDetector.RefreshDetectedValues +=
                () => CheckTheseMethods(new Collection<IDetectionMethod> { _runningMeanStandardDeviationDetector });

            _missingValuesDetector = new MissingValuesDetector { IsEnabled = true };
            _selectedMethod = _missingValuesDetector;

            var repeatedValuesDetector = new RepeatedValuesDetector();

            repeatedValuesDetector.RefreshDetectedValues +=
                () => CheckTheseMethods(new Collection<IDetectionMethod> { repeatedValuesDetector });

            _detectionMethods = new List<IDetectionMethod> { _missingValuesDetector, repeatedValuesDetector, _minMaxDetector, new ToHighRateOfChangeDetector(), _runningMeanStandardDeviationDetector };

            #endregion

            #region Set Up Behaviours

            var behaviourManager = new BehaviourManager { AllowMultipleEnabled = true };

            #region Zoom Behaviour
            _zoomBehaviour = new CustomZoomBehaviour { IsEnabled = true };
            _zoomBehaviour.ZoomRequested += (o, e) =>
                                                {
                                                    ZoomState z = new ZoomState(StartTime, EndTime, Range);
                                                    _previousZoom.Add(z);
                                                    StartTime = e.LowerX;
                                                    EndTime = e.UpperX;
                                                    Range = new DoubleRange(e.LowerY, e.UpperY);
                                                    foreach (var detectionMethod in _detectionMethods.Where(x => x.IsEnabled))
                                                    {
                                                        var itemsToKeep =
                                                            detectionMethod.ListBox.Items.Cast<ErroneousValue>().Where(
                                                                x => x.TimeStamp >= StartTime && x.TimeStamp <= EndTime)
                                                                .ToList();
                                                        detectionMethod.ListBox.Items.Clear();
                                                        itemsToKeep.ForEach(x => detectionMethod.ListBox.Items.Add(x));
                                                    }
                                                    foreach (var sensor in _sensorsToGraph)
                                                    {
                                                        sensor.SetUpperAndLowerBounds(StartTime, EndTime);
                                                    }
                                                    SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "Zoom");
                                                    ShowLastZoom = true;
                                                };
            _zoomBehaviour.ZoomResetRequested += o =>
                                                     {
                                                         _previousZoom.Clear();
                                                         foreach (var sensor in _sensorsToGraph)
                                                         {
                                                             sensor.RemoveBounds();
                                                         }
                                                         CalculateGraphedEndPoints();
                                                         SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "ZoomReset");
                                                         CalculateYAxis();
                                                         CheckTheseMethods(_detectionMethods.Where(x => x.IsEnabled));
                                                         ShowLastZoom = false;
                                                         _previousZoom.Clear();
                                                     };
            _zoomBehaviour.LastZoomRequested += (o, e) =>
            {
                if (ShowLastZoom == true)
                {
                    ZoomState z = _previousZoom.GetLast();
                    StartTime = z.StartTime;
                    EndTime = z.EndTime;
                    Range = z.Range;
                    foreach (var detectionMethod in _detectionMethods.Where(x => x.IsEnabled))
                    {
                        var itemsToKeep =
                            detectionMethod.ListBox.Items.Cast<ErroneousValue>().Where(
                                x => x.TimeStamp >= StartTime && x.TimeStamp <= EndTime)
                                .ToList();
                        detectionMethod.ListBox.Items.Clear();
                        itemsToKeep.ForEach(x => detectionMethod.ListBox.Items.Add(x));
                    }
                    foreach (var sensor in _sensorsToGraph)
                    {
                        sensor.SetUpperAndLowerBounds(StartTime, EndTime);
                    }
                    SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "Zoom");
                    if (_previousZoom.Count == 0)
                    {
                        ShowLastZoom = false;
                    }
                }

            };

            behaviourManager.Behaviours.Add(_zoomBehaviour);
            #endregion

            #region Background Behaviour
            _background = new Canvas { Visibility = Visibility.Collapsed };
            var backgroundBehaviour = new GraphBackgroundBehaviour(_background);
            behaviourManager.Behaviours.Add(backgroundBehaviour);
            #endregion

            #region Selection Behaviour

            _selectionBehaviour = new CustomSelectionBehaviour { IsEnabled = true };
            _selectionBehaviour.SelectionMade += (sender, args) =>
                                                     {
                                                         Selection = args;
                                                     };

            _selectionBehaviour.SelectionReset += sender =>
                                                      {
                                                          Selection = null;
                                                      };
            behaviourManager.Behaviours.Add(_selectionBehaviour);
            #endregion

            _dateAnnotator = new DateAnnotationBehaviour { IsEnabled = true };
            behaviourManager.Behaviours.Add(_dateAnnotator);

            _calibrationAnnotator = new CalibrationAnnotatorBehaviour(this) { IsEnabled = true };
            behaviourManager.Behaviours.Add(_calibrationAnnotator);

            behaviourManager.Behaviours.Add(new ChangesAnnotatorBehaviour(this) { IsEnabled = true });

            Behaviour = behaviourManager;

            #endregion

            PropertyChanged += (o, e) =>
                                   {
                                       if (e.PropertyName == "Selection")
                                           ActionsEnabled = Selection != null;
                                   };

            BuildDetectionMethodTabItems();

            var autoSaveTimer = new System.Timers.Timer();
            autoSaveTimer.Elapsed += (o, e) =>
                                         {
                                             if (CurrentDataset != null)
                                             {
                                                 Save();
                                             }
                                         };
            autoSaveTimer.AutoReset = true;
            autoSaveTimer.Interval = Properties.Settings.Default.AutoSaveTimerInterval;
            if (Properties.Settings.Default.AutoSaveTimerEnabled)
                autoSaveTimer.Start();

            Properties.Settings.Default.PropertyChanged += (o, e) =>
                                                               {
                                                                   switch (e.PropertyName)
                                                                   {
                                                                       case "AutoSaveTimerInterval":
                                                                           autoSaveTimer.Interval =
                                                                               Properties.Settings.Default.
                                                                                   AutoSaveTimerInterval;
                                                                           break;
                                                                       case "AutoSaveTimerEnabled":
                                                                           if (Properties.Settings.Default.AutoSaveTimerEnabled)
                                                                               autoSaveTimer.Start();
                                                                           else
                                                                               autoSaveTimer.Stop();
                                                                           break;
                                                                   }
                                                               };
        }
 public BelowMinValueDetector(MinMaxDetector owner)
 {
     _owner = owner;
 }
 public BelowMinValueDetector(MinMaxDetector owner)
 {
     _owner = owner;
 }
 public AboveMaxValueDetector(MinMaxDetector owner)
 {
     _owner = owner;
 }
 public AboveMaxValueDetector(MinMaxDetector owner)
 {
     _owner = owner;
 }