public static bool Load(string filename, Magazine m) { BinaryFormatter binFormat = new BinaryFormatter(); try { FileStream s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None); m = (Magazine)binFormat.Deserialize(s); s.Close(); } catch (Exception ex) { Console.WriteLine(ex); return(false); } return(true); }
public static bool Save(string filename, Magazine m) { BinaryFormatter binFormat = new BinaryFormatter(); try { FileStream s = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None); binFormat.Serialize(s, m); s.Close(); } catch (Exception ex) { Console.WriteLine(ex); return(false); } return(true); }
public static Magazine DeepCopy(Magazine m) { MemoryStream s = new MemoryStream(); BinaryFormatter formater = new BinaryFormatter(); try { formater.Serialize(s, m); s.Position = 0; return((Magazine)formater.Deserialize(s)); } catch (Exception ex) { throw ex; } finally { s.Close(); } }
public override object DeepCopy() { Magazine obj = new Magazine(Title, Shedule, Release, Edition); Article[] a = new Article[ArticlesList.Count]; for (int i = 0; i < ArticlesList.Count; i++) { a[i] = new Article((ArticlesList[i]).Author, (ArticlesList[i]).Title, (ArticlesList[i]).Rating); } obj.AddArticles(a); Person[] p = new Person[Editors.Count]; for (int i = 0; i < Editors.Count; i++) { p[i] = new Person((Editors[i]).Name, (Editors[i]).Surname, (Editors[i]).Birthday); } obj.AddEditors(p); return(obj); }