public void Setup()
        {
            _reader = new CSVReader(Path.Combine(Common.TestDataPath, "lakeTutira120120110648_extra_small.csv"));
            _ds = new Dataset(_s, _reader.ReadSensors());
            var sensorVariables = SensorVariable.CreateSensorVariablesFromSensors(_ds.Sensors);
            foreach (var sensor in _ds.Sensors)
            {
                sensor.Owner = _ds;
                sensor.Variable = sensorVariables.FirstOrDefault(x => x.Sensor == sensor);
            }

            _eval = new FormulaEvaluator(_ds.Sensors);
        }
        /// <summary>
        /// starts an import of data
        /// </summary>
        /// <param name="filename">filepath of data file</param>
        public void Import(string filename)
        {
            DisableFeatures();
            var result = new List<Sensor>();

            ShowProgressArea = true;
            ProgressIndeterminate = false;
            ProgressValue = 0;

            var reader = new CSVReader(filename);

            reader.ProgressChanged += (sender, args) =>
                                          {
                                              ProgressValue = args.Progress;
                                              WaitEventString =
                                                  string.Format("Importing from {0} {1}%",
                                                                filename,
                                                                ProgressValue);
                                          };
            try
            {
                result = reader.ReadSensors(null, CurrentDataset);
            }
            catch (Exception ex)
            {
                Common.ShowMessageBoxWithException("Failed Import", "Bad File Format", false, true, ex);
                result = null;
            }

            if (result == null)
            {
                ShowProgressArea = false;
                EnableFeatures();
                return;
            }

            var sensors = (List<Sensor>)result;

            if (CurrentDataset.Sensors == null || CurrentDataset.Sensors.Count == 0)
            {
                CurrentDataset.Sensors = sensors;
                CurrentDataset.HighestYearLoaded = NumberOfDataChunks() - 1;
            }
            else
            {
                var askUser =
                    _container.GetInstance(typeof(SpecifyValueViewModel),
                                           "SpecifyValueViewModel") as
                    SpecifyValueViewModel;

                if (askUser == null)
                {
                    Common.ShowMessageBox("EPIC FAIL", "RUN AROUND WITH NO REASON",
                                          false, true);
                    return;
                }

                askUser.ComboBoxItems = new List<string> { "Keep old values", "Keep new values" };
                askUser.Text = "Keep old values";
                askUser.ShowComboBox = true;
                askUser.Message = "How do you want to handle overlapping points. Note this will also overwrite empty or missing values within the overlaping period";
                askUser.CanEditComboBox = false;
                askUser.ComboBoxSelectedIndex = 0;
                askUser.Title = "Importing";

                _windowManager.ShowDialog(askUser);

                var keepOldValues = askUser.ComboBoxSelectedIndex == 0;

                var sensorMatchView =
                    _container.GetInstance(typeof(MatchToExistingSensorsViewModel),
                                           "MatchToExistingSensorsViewModel") as
                    MatchToExistingSensorsViewModel;

                if (sensorMatchView == null)
                    return;

                sensorMatchView.ExistingSensors = CurrentDataset.Sensors;
                sensorMatchView.NewSensors = sensors;

                _windowManager.ShowDialog(sensorMatchView);

                var orderedTimestamps = sensors.SelectMany(x => x.CurrentState.Values).Select(x => x.Key).Distinct().ToArray();
                var firstTimestamp = orderedTimestamps.Min();
                var lastTimestamp = orderedTimestamps.Max();
                orderedTimestamps = new DateTime[0];
                var highestYear = NumberOfDataChunks() - 1;

                var firstNewYear = firstTimestamp.Year - CurrentDataset.StartYear.Year;

                if (firstNewYear < CurrentDataset.LowestYearLoaded)
                {
                    CurrentDataset.LoadInSensorData(firstNewYear < 0 ?
                           Enumerable.Range(0, CurrentDataset.LowestYearLoaded).ToArray()
                         : Enumerable.Range(firstNewYear, CurrentDataset.LowestYearLoaded - firstNewYear).ToArray(), true);
                }

                var lastNewYear = lastTimestamp.Year - CurrentDataset.StartYear.Year;
                var reason = ChangeReason.AddNewChangeReason("[Importer] Imported new values on " + DateTime.Now);
                if (lastNewYear > CurrentDataset.HighestYearLoaded)
                {
                    CurrentDataset.LoadInSensorData(lastNewYear > highestYear ?
                        Enumerable.Range(CurrentDataset.HighestYearLoaded + 1, highestYear - CurrentDataset.HighestYearLoaded).ToArray()
                      : Enumerable.Range(CurrentDataset.HighestYearLoaded + 1, lastNewYear - CurrentDataset.HighestYearLoaded).ToArray(), true);
                }

                foreach (var newSensor in sensors)
                {
                    var match =
                        sensorMatchView.SensorLinks.FirstOrDefault(
                            x => x.MatchingSensor == newSensor);
                    if (match == null)
                    {
                        Debug.WriteLine("Adding new sensor");
                        CurrentDataset.Sensors.Add(newSensor);
                    }
                    else
                    {
                        var matchingSensor =
                            CurrentDataset.Sensors.FirstOrDefault(
                                x => x == match.ExistingSensor);

                        if (matchingSensor == null)
                        {
                            Debug.WriteLine(
                                "Failed to find the sensor again, embarrasing!");
                            continue;
                        }

                        Debug.WriteLine("Merging sensors");
                        //Otherwise clone the current state
                        var newState = matchingSensor.CurrentState.Clone();
                        //Check to see if values are inserted
                        var insertedValues = false;

                        //And add values for any new dates we want
                        foreach (var value in newSensor.CurrentState.Values.Where(value =>
                                    !keepOldValues || !(matchingSensor.CurrentState.Values.ContainsKey(value.Key) || matchingSensor.RawData.Values.ContainsKey(value.Key))))
                        {
                            newState.Values[value.Key] = value.Value;
                            if (matchingSensor.CurrentState.Values.ContainsKey(value.Key) || matchingSensor.RawData.Values.ContainsKey(value.Key))
                                newState.AddToChanges(value.Key, reason.ID);
                            matchingSensor.RawData.Values[value.Key] = value.Value;
                            insertedValues = true;
                        }

                        if (insertedValues)
                        {
                            //Give a reason
                            newState.Reason = reason;
                            //Insert new state
                            matchingSensor.AddState(newState);
                            matchingSensor.ClearUndoStates();
                            EventLogger.LogSensorInfo(CurrentDataset,
                                                      matchingSensor.Name,
                                                      "Added values from new import");
                        }
                    }
                }
                CurrentDataset.CalculateDataSetValues();
                if (CurrentDataset.HighestYearLoaded == highestYear)
                    CurrentDataset.HighestYearLoaded = NumberOfDataChunks() - 1;
            }

            UpdateGUI();

            if (Sensors.FirstOrDefault(x => x.Variable == null) != null)
            {
                var sensorVariables = SensorVariable.CreateSensorVariablesFromSensors(Sensors);
                foreach (var sensor in Sensors)
                {
                    sensor.Variable = sensorVariables.FirstOrDefault(x => x.Sensor == sensor);
                }
            }
            _evaluator = new FormulaEvaluator(Sensors);
            _dateAnnotator.DataInterval = CurrentDataset.DataInterval;

            ShowProgressArea = false;
            EnableFeatures();
            NotifyOfPropertyChange(() => LowestYearLoadedOptions);
            NotifyOfPropertyChange(() => HighestYearLoadedOptions);
            NotifyOfPropertyChange(() => LowestYearLoaded);
            NotifyOfPropertyChange(() => HighestYearLoaded);

            CurrentDataset.SaveToFile();
        }