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