private void LoadAlarms(string alarmsFilePath) { if (!File.Exists(alarmsFilePath)) { _logger.Error($"Failed to load file alarms file '{alarmsFilePath}'..."); return; } var alarmData = File.ReadAllText(alarmsFilePath); if (string.IsNullOrEmpty(alarmData)) { _logger.Error($"Failed to load '{alarmsFilePath}', file is empty..."); return; } Alarms = JsonStringSerializer.Deserialize <AlarmList>(alarmData); if (Alarms == null) { _logger.Error($"Failed to deserialize the alarms file '{alarmsFilePath}', make sure you don't have any json syntax errors."); return; } foreach (var item in Alarms) { item.Value.ForEach(x => x.ParseGeofenceFile()); } }
/// <summary> /// Loads the configuration file from the specified path. /// </summary> /// <param name="filePath">The full file path.</param> /// <returns>Returns the deserialized Config object.</returns> public static Config Load(string filePath) { try { var data = File.ReadAllText(filePath); //return XmlStringSerializer.Deserialize<Config>(data); return(JsonStringSerializer.Deserialize <Config>(data)); } catch (Exception ex) { Utils.LogError(ex); } return(null); }
/// <summary> /// Loads the configuration file from the specified path. /// </summary> /// <param name="filePath">The full file path.</param> /// <returns>Returns the deserialized Config object.</returns> public static Database Load(string filePath) { try { if (File.Exists(filePath)) { var data = File.ReadAllText(filePath); //return XmlStringSerializer.Deserialize<Database>(data); return(JsonStringSerializer.Deserialize <Database>(data)); } } catch (Exception ex) { Console.WriteLine($"LoadConfig: {ex}"); } return(new Database()); }
public Database() { Reminders = new ConcurrentDictionary <ulong, List <Reminder> >(); Subscriptions = new List <Subscription <Pokemon> >(); var pokemonDb = Path.Combine(DataFolderName, PokemonDatabaseFileName); if (File.Exists(pokemonDb)) { var pokeDb = File.ReadAllText(pokemonDb); if (!string.IsNullOrEmpty(pokeDb)) { Pokemon = JsonStringSerializer.Deserialize <Dictionary <string, PokemonInfo> >(pokeDb); } } var movesetDb = Path.Combine(DataFolderName, MovesetDatabaseFileName); if (File.Exists(movesetDb)) { var movesDb = File.ReadAllText(movesetDb); if (!string.IsNullOrEmpty(movesDb)) { Movesets = JsonStringSerializer.Deserialize <Dictionary <string, Moveset> >(movesDb); } } var cpMultipliersDb = Path.Combine(DataFolderName, CpMultipliersFileName); if (File.Exists(cpMultipliersDb)) { var multipliersDb = File.ReadAllText(cpMultipliersDb); if (!string.IsNullOrEmpty(multipliersDb)) { CpMultipliers = JsonStringSerializer.Deserialize <Dictionary <string, double> >(multipliersDb); } } }
public void DeserializeEmptyStringToNull() { IStringSerializer serializer = new JsonStringSerializer(); Assert.IsNull(serializer.Deserialize <object>(string.Empty)); }
public void DeserializeNullStringToNull() { IStringSerializer serializer = new JsonStringSerializer(); Assert.IsNull(serializer.Deserialize <object>(null)); }