public static ConnectionLimitationSettings Load(string path) { try { if (File.Exists(path)) { IFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { ConnectionLimitationSettings cls = (ConnectionLimitationSettings)formatter.Deserialize(stream); stream.Close(); MainBoard.WriteLine("Global connection preferences loaded!", System.Drawing.Color.Green); return(cls); } } MainBoard.WriteLine("No global connection preferences file exist. Creating default ones."); return(new ConnectionLimitationSettings()); } catch (Exception ex) { MainBoard.WriteLine("ERROR - Could not open file: " + ex.Message, System.Drawing.Color.Red); return(null); } }
public void SaveAs(string path) { try { IFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write)) { formatter.Serialize(stream, this); stream.Close(); } } catch (Exception ex) { MainBoard.WriteLine("ERROR - Could not save file: " + ex.Message, System.Drawing.Color.Red); } }