/// <summary> /// Static method to create a DACPPairingDatabase and try and load XML /// file from disk located at EXENAME.xml in the same directory. /// </summary> /// <returns>a DACPPairingDatabase object</returns> public static DACPPairingDatabase Initialize(DACPServer dacpServer) { Console.WriteLine("Initializing DACPPairingDatabase"); DACPPairingDatabase database = new DACPPairingDatabase(); database.Server = dacpServer; string fileName = database.GetFileName(); if (File.Exists(fileName)) { Console.WriteLine("Deserializing XML file: {0}", fileName); try { DACPPairingDatabaseSerializer serializer = new DACPPairingDatabaseSerializer(); //XmlSerializer serializer = new XmlSerializer(CLAZZ_TYPE); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { database = (DACPPairingDatabase)serializer.Deserialize(stream); database.Server = dacpServer; } } catch (Exception ex) { Console.WriteLine("XML Exception", ex); database = new DACPPairingDatabase(); database.Server = dacpServer; } } return(database); }
/// <summary> /// Saves the current database to disk. /// </summary> public void Store() { try { string fileName = this.GetFileName(); Console.WriteLine("Serializing XML file: {0}", fileName); DACPPairingDatabaseSerializer serializer = new DACPPairingDatabaseSerializer(); // XmlSerializer serializer = new XmlSerializer(CLAZZ_TYPE); using (StreamWriter stream = new StreamWriter(fileName)) { serializer.Serialize(stream, this); } } catch (Exception ex) { Console.WriteLine("XML Exception", ex); throw ex; } }