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