//Load a namecollection from json file public static NameCollection Load(string path) { string data; try { data = File.ReadAllText(path); } catch (Exception e) { Console.WriteLine("Could not load File: '{0}' due to {1}", path, e.Message); throw; } var nameCollection = new NameCollection(); try { nameCollection = JsonConvert.DeserializeObject <NameCollection>(data); } catch (Exception e) { Console.WriteLine("Could not Deserialize File: '{0}' due to {1}", path, e.Message); throw; } return(nameCollection); }
private static NameCollection ReadNameCollection(string filePath) { //Use Path to get proper filesystem path for input try { filePath = Path.GetFullPath(filePath); } catch (Exception) { Console.WriteLine("Invalid Path to input file: {0}", filePath); return(null); } //Check if input file is real. if (!File.Exists(filePath)) { Console.WriteLine("File does not exist: {0}", filePath); return(null); } var fileExtension = Path.GetExtension(filePath); //Check its an input file we understand if (fileExtension != ".json") { Console.WriteLine("Name replacement file not json."); } var nameCollection = new NameCollection(); try { nameCollection = NameCollection.Load(filePath); } catch (Exception) { Console.WriteLine("Could not parse '{0}'.", filePath); return(null); } return(nameCollection); }