private List <AppEntity> ReadFromFile(string filePath) { using (var stream = new StreamReader(filePath)) { var jsonString = stream.ReadToEnd(); var jsonApps = new List <AppEntityJson>(); try { jsonApps = JsonConvert.DeserializeObject <List <AppEntityJson> >(jsonString); } catch (JsonReadException ex) { MessageBox.Show(ex.Message, ex.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); logger.Log(LogType.Error, ex.Message); } return(AppEntityJson.Convert(jsonApps)); } }
private void WriteToFile(string filePath, List <AppEntity> apps) { if (!File.Exists(filePath)) { File.Create(filePath); } var jsonApps = AppEntityJson.Convert(apps); using (var stream = new StreamWriter(filePath)) { try { stream.Write(JsonConvert.SerializeObject(jsonApps)); } catch (JsonWriteException ex) { MessageBox.Show(ex.Message, ex.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); logger.Log(LogType.Error, ex.Message); } } }