private void Save() { var data = new PercentageData { Weight = weight, Percentage = percentage }; storage.SavePercentageData(exercise.ToString(), data); }
private void Load() { var defaultData = new PercentageData { Weight = 100, Percentage = 100 }; var data = storage.LoadPercentageData(exercise.ToString(), defaultData); weight = data.Weight; percentage = data.Percentage; }
public void SavePercentageData(string exerciseCategory, PercentageData data) { percentageStorage [exerciseCategory] = data; if (null != storage) { var stream = new MemoryStream(); percentageDataSerializer.WriteObject(stream, percentageStorage); stream.Position = 0; StreamReader reader = new StreamReader(stream); storage.WriteFile(JsonDataManager.PercentageFileName, reader.ReadToEnd()); } }
public PercentageData LoadPercentageData(string exerciseCategory, PercentageData defaultData) { try { var content = storage.ReadFile(JsonDataManager.PercentageFileName); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(content); writer.Flush(); stream.Position = 0; var obj = (Dictionary <string, PercentageData>)percentageDataSerializer.ReadObject(stream); if (null != obj) { percentageStorage = obj; } else { percentageStorage.Clear(); } return(percentageStorage [exerciseCategory]); } catch (Exception) { return(defaultData); } }