/// <summary> /// Gets the stim sweep model from the stim sweep config /// </summary> /// <param name="filePath">File path to the stim sweep config file</param> /// <returns>StimSweep model if success or null if unsuccessful</returns> public StimSweepModel GetStimSweepModelFromFile(string filePath) { StimSweepModel model = null; string json = null; try { //read StimSweepModel config file into string using (StreamReader sr = new StreamReader(filePath)) { json = sr.ReadToEnd(); } } catch (Exception e) { MessageBox.Show("The StimSweep 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("StimSweep JSON file is empty. Please check that the StimSweep config is correct.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); _log.Warn("StimSweep JSON file is empty after loading file."); return(model); } else { SchemaModel schemaModel = new SchemaModel(); if (ValidateJSON(json, schemaModel.GetStimSweepSchema())) { //if correct json format, write it into master switchModel try { model = JsonConvert.DeserializeObject <StimSweepModel>(json); } catch (Exception e) { MessageBox.Show("Could not convert StimSweep config file. Please be sure that StimSweep config file is correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); _log.Error(e); return(model); } } else { MessageBox.Show("Could not validate StimSweep config file. Please be sure that StimSweep config file is correct.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); _log.Warn("Could not validate StimSweep config file."); return(model); } } return(model); }