public static void Load() { if (!string.IsNullOrEmpty(FilePath)) { try { using (FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(VendingMachineItems)); VendingMachineItems = (VendingMachineItems)xmlSerializer.Deserialize(fileStream); } } catch (Exception) { //We could add some extra details about this exception here, eg adding an error code or set an error message to display throw; } } }
static void ResetData() { VendingMachineItems vendingMachine = new VendingMachineItems(); vendingMachine.Items.Add(new VendingMachineItem("Coca-Cola", VendingMachineItemTypes.DRINK, 2.00f, 10, "A3")); vendingMachine.Items.Add(new VendingMachineItem("Gatorade", VendingMachineItemTypes.DRINK, 2.00f, 10, "A4")); vendingMachine.Items.Add(new VendingMachineItem("Vitamin Water", VendingMachineItemTypes.DRINK, 2.00f, 10, "A5")); vendingMachine.Items.Add(new VendingMachineItem("Granola Plus", VendingMachineItemTypes.HEALTHBAR, 1.75f, 10, "B3")); vendingMachine.Items.Add(new VendingMachineItem("Nature Valley", VendingMachineItemTypes.HEALTHBAR, 1.75f, 10, "B4")); vendingMachine.Items.Add(new VendingMachineItem("Oh HENRY", VendingMachineItemTypes.CANDYBAR, 2.25f, 10, "C2")); vendingMachine.Items.Add(new VendingMachineItem("Snickers", VendingMachineItemTypes.CANDYBAR, 2.25f, 10, "C3")); vendingMachine.Items.Add(new VendingMachineItem("Sun Chips", VendingMachineItemTypes.CHIPS, 2.50f, 10, "D4")); VendingMachineConfig.VendingMachineItems = vendingMachine; VendingMachineConfig.Save(); }