public bool saveProcesses(PSProcessCollection collection) { bool bRet = true; //ensure the directory exists try { if (!Directory.Exists(mAppDataDir)) { Directory.CreateDirectory(mAppDataDir); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error saving mapping to disk", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { BinaryFormatter formatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); formatter.Serialize(ms, collection); File.WriteAllBytes(mMapFilePath, ms.GetBuffer()); } catch (Exception ex) { bRet = false; } return(bRet); }
public PSProcessCollection loadProcesses() { PSProcessCollection ret = null; try { BinaryFormatter formatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(File.ReadAllBytes(mMapFilePath)); ret = (PSProcessCollection)formatter.Deserialize(ms); } catch (Exception ex) { ret = null; } return(ret); }
private void loadMappings() { PSDB db = new PSDB(); PSProcessCollection loadedData = db.loadProcesses(); if (null == loadedData) { if (System.IO.File.Exists(db.mMapFilePath)) { MessageBox.Show( "An error occured trying to load the saved mappings; this usually means corruption.", "Loading saved mapping", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { mProcesses = loadedData; } }
public frmAddMapping(PSProcessCollection existingProcesses) { InitializeComponent(); mExistingProcesses = existingProcesses; }