/// <summary> /// Method that reads the .xml file to get the serialized <seealso cref="Models.HomeItem"/> and load it into the class attribute /// </summary> public void LoadHomePage() { if (File.Exists(HOME_PATH)) { Stream stream = File.Open(HOME_PATH, FileMode.Open); SoapFormatter formatter = new SoapFormatter(); try { CurrentHomePage = (Models.HomeItem)formatter.Deserialize(stream); } catch (Exception e) { CurrentHomePage = new Models.HomeItem(DEFAULT_HOME); } stream.Close(); } else { Stream stream = File.Open(HOME_PATH, FileMode.Create); stream.Close(); CurrentHomePage = new Models.HomeItem(DEFAULT_HOME); } if (this.CurrentHomePage == null) { throw new Exceptions.InvalidValuedVariableException("CurrentHomePage has not been correctly loaded."); } }
/// <summary> /// Method that given a URL address string, will change the <seealso cref="Controllers.HomePageController.CurrentHomePage"/> attribute /// </summary> /// <param name="address"></param> public void ChangeHomePage(string address) { if (address == null) { throw new Exceptions.InvalidValuedVariableException("Address to add cannot be null."); } Models.HomeItem NewHomePage = new Models.HomeItem(address); this.CurrentHomePage = NewHomePage; this.SaveHomePage(); }