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