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