/// <summary>
        /// Reads the config file and gets the total amount of time to run
        /// </summary>
        /// <returns>time in seconds for total montage</returns>
        private int GetTotalTimeForMontage(MontageModel localMontageModel)
        {
            //Go through the files
            //Add the total amount of time for the whole thing and save in local variable to get use later
            int totalTimeForMontage = 0;

            foreach (MontageFile fileInfo in localMontageModel.MontageFiles)
            {
                totalTimeForMontage += fileInfo.TimeToRunInSeconds;
            }
            return(totalTimeForMontage);
        }
        /// <summary>
        /// Gets the montage model from the montage config
        /// </summary>
        /// <param name="filePath">File path to the montage config file</param>
        /// <returns>Montage model if success or null if unsuccessful</returns>
        public MontageModel GetMontageModelFromFile(string filePath)
        {
            MontageModel model = null;
            string       json  = null;

            try
            {
                //read MontageModel config file into string
                using (StreamReader sr = new StreamReader(filePath))
                {
                    json = sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("The montage config file could not be read from the file. Please check that it exists.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                _log.Error(e);
                return(model);
            }
            if (string.IsNullOrEmpty(json))
            {
                MessageBox.Show("Montage JSON file is empty. Please check that the Montage config is correct.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                _log.Warn("Montage JSON file is empty after loading file.");
                return(model);
            }
            else
            {
                SchemaModel schemaModel = new SchemaModel();
                if (ValidateJSON(json, schemaModel.GetMontageSchema()))
                {
                    //if correct json format, write it into master switchModel
                    try
                    {
                        model = JsonConvert.DeserializeObject <MontageModel>(json);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Could not convert montage config file. Please be sure that montage config file is correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        _log.Error(e);
                        return(model);
                    }
                }
                else
                {
                    MessageBox.Show("Could not validate montage config file. Please be sure that montage config file is correct.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    _log.Warn("Could not validate montage config file.");
                    return(model);
                }
            }
            return(model);
        }
        public MontageViewModel(ref SummitSystem theSummitLeft, ref SummitSystem theSummitRight, ILog _log, AppModel appModel)
        {
            this.theSummitLeft  = theSummitLeft;
            this.theSummitRight = theSummitRight;
            this.isBilateral    = appModel.Bilateral;
            this._log           = _log;
            this.appModel       = appModel;
            IsMontageEnabled    = true;

            summitSensing      = new SummitSensing(_log);
            jSONService        = new JSONService(_log);
            stimParameterLeft  = new StimParameterModel("", "", "", "", null);
            stimParameterRight = new StimParameterModel("", "", "", "", null);

            montageModel = jSONService.GetMontageModelFromFile(MONTAGE_FILEPATH);
            if (montageModel == null)
            {
                MessageBox.Show("The montage config file could not be read from the file. Please check that it exists.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            montageSweepConfigListLeft = montageSweepConfigListRight = LoadSenseJSONFilesForMontage(MONTAGE_BASEFILEPATH, MONTAGE_FILETYPE, montageModel);
            if (montageSweepConfigListLeft == null || montageSweepConfigListRight == null)
            {
                IsMontageEnabled = false;
                return;
            }

            //Get total time left and total time for montage. Display on progress bar
            timeLeftForMontage = totalTimeForMontage = GetTotalTimeForMontage(montageModel);
            TimeSpan time = TimeSpan.FromSeconds(timeLeftForMontage);
            //here backslash is must to tell that colon is
            //not the part of format, it just a character that we want in output
            string str = time.ToString(@"hh\:mm\:ss");

            MontageTimeTextBox  = "Total Montage Time: " + str;
            InstructionsTextBox = montageModel?.Instructions;
        }
        /// <summary>
        /// Method that loads all of the sense config files based on what was loaded from montage config file
        /// </summary>
        /// <returns>List of sense models if successful and null if unsuccessful</returns>
        private List <SenseModel> LoadSenseJSONFilesForMontage(string baseFilepath, string filetype, MontageModel localMontageModel)
        {
            List <SenseModel> localList = new List <SenseModel>();

            foreach (MontageFile montageFileObject in localMontageModel.MontageFiles)
            {
                string     filepath  = baseFilepath + montageFileObject.Filename + filetype;
                SenseModel tempModel = jSONService.GetSenseModelFromFile(filepath);
                if (tempModel != null)
                {
                    localList.Add(tempModel);
                }
                else
                {
                    MessageBox.Show("The sense config file: " + montageFileObject.Filename + " could not be loaded up correctly.  Please try montage again", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }
            }
            return(localList);
        }