Beispiel #1
0
 /// <summary>
 /// Loads from file.
 /// </summary>
 /// <returns>The from file.</returns>
 /// <param name="filepath">Filepath.</param>
 public static Configuration LoadFromFile(string filepath)
 {
     try
     {
         var config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(filepath));
         CsvFileWriter.CopyFileToDir(filepath, OutputDirs.ExecTime);
         return(config);
     }
     catch (FileNotFoundException ex)
     {
         LogManager.Error($"Could not locate input file: {filepath}.  "
                          + "Please double check file name and path.",
                          ex, typeof(Configuration));
         return(new Configuration());
     }
     catch (JsonReaderException ex)
     {
         LogManager.Error("Could not parse configuration object from "
                          + $"input file: {filepath}.  Is input properly formatted?",
                          ex, typeof(Configuration));
         return(new Configuration());
     }
     catch (JsonSerializationException ex)
     {
         LogManager.Error("Error encountered while attempting to serialize "
                          + $"configuration object from input file: {filepath}.  "
                          + "Is input complete?",
                          ex, typeof(Configuration));
         return(new Configuration());
     }
 }