private void Save() { var data = new MaxWeightData { Repeats = repeats, Weight = weight }; storage.SaveMaxWeightData(exercise.ToString(), data); }
private void Load() { var defaultData = new MaxWeightData { Repeats = 1, Weight = 100 }; var data = storage.LoadMaxWeightData(exercise.ToString(), defaultData); weight = data.Weight; repeats = data.Repeats; }
public void SaveMaxWeightData(string exerciseCategory, MaxWeightData data) { maxWeightStorage [exerciseCategory] = data; if (null != storage) { var stream = new MemoryStream(); maxWeightDataSerializer.WriteObject(stream, maxWeightStorage); stream.Position = 0; var reader = new StreamReader(stream); storage.WriteFile(JsonDataManager.MaxWeightFileName, reader.ReadToEnd()); } }
public MaxWeightData LoadMaxWeightData(string exerciseCategory, MaxWeightData defaultData) { try { var content = storage.ReadFile(JsonDataManager.MaxWeightFileName); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(content); writer.Flush(); stream.Position = 0; var obj = (Dictionary <string, MaxWeightData>)maxWeightDataSerializer.ReadObject(stream); if (null != obj) { maxWeightStorage = obj; } else { maxWeightStorage.Clear(); } return(maxWeightStorage [exerciseCategory]); } catch (Exception) { return(defaultData); } }