/// <summary> /// Gets the file from the filepath, validates the file, and converts it to the sense model /// </summary> /// <param name="filePath">File path for the sense_config.json file to be used to convert</param> /// <returns>SenseModel if successful or null if unsuccessful</returns> public SenseModel GetSenseModelFromFile(string filePath) { SenseModel model = null; string json = null; try { //read sense config file into string using (StreamReader sr = new StreamReader(filePath)) { json = sr.ReadToEnd(); } } catch (Exception e) { MessageBox.Show("The sense 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("Sense JSON file is empty. Please check that the sense config is correct.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); _log.Warn("Sense JSON file is empty after loading file."); return(model); } else { SchemaModel schemaModel = new SchemaModel(); if (ValidateJSON(json, schemaModel.GetSenseSchema())) { //if correct json format, write it into SenseModel try { model = JsonConvert.DeserializeObject <SenseModel>(json); } catch (Exception e) { MessageBox.Show("Could not convert sense config file. Please be sure that sense config file is correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); _log.Error(e); return(model); } } else { MessageBox.Show("Could not validate sense config file. Please be sure that sense config file is correct.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); _log.Warn("Could not validate sense config file."); return(model); } } return(model); }