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); } } }
public AppEntity(AppEntityJson appJson) { AppName = appJson.AppName; ExecutePath = appJson.ExecutePath; IsLoggingActive = appJson.IsLoggingActive; Logger = new Logger(appJson.LoggerPath); PictureBox = new TransparentPictureBox() { Name = AppName, Image = Icon.ExtractAssociatedIcon(ExecutePath).ToBitmap(), }; if (appJson.IsSelected) { Select(); } else { Unselect(); } PictureBox.SizeMode = PictureBoxSizeMode.StretchImage; SetSize(PictureBox.Image.Size); }