Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t want anybody to do the program for me. I just need a straight answer on

ID: 3622011 • Letter: I

Question

I don't want anybody to do the program for me. I just need a straight answer on how to read from a config file. how to store its contents to an array. How to read the array in creating a menu. and how to edit it. Also how to write to a log. Just give an example of each thing, and comment on what each part does.

basically how to do these things in the context of this programming assignment

 

 

1) There are two (2) configuration files for the vending machine. You will have to
read each configuration in. You will use arrays to store the data, and work with it.
One contains information about the machine, the other about the products.
2) The user will deposit money first and then order a product. They should not be able
to order a product more expensive than their money already deposited. They may add
more money when they wish and get their change (unused money) when they want.
3) As the machine operates, it keeps a log (in a file) of what is happening.
4) As the machine sells products, the inventory for those products is adjusted. If the
inventory of a particular product goes below its low-inventory threshold, that product
should have a low-inventory note next to it in the menu. If it is sold out, it is not shown
on the menu.

Explanation / Answer

Three Config File Reading Examples : Type 1 - Regular configuration file settings Type 2 - Section that uses nodes and the IConfigurationSectionHandler interface Type 3 – Section that uses attributes and a class that inherits from ConfigurationSection c:File2.txt 1234 Whatever!! // Must add a reference to System.Configuration assembly for the project. using System.Configuration; namespace MultiConfigSections { public partial class MultiConfigSectionsForm : Form { public MultiConfigSectionsForm() { InitializeComponent(); } /// /// Basic setting retriever. /// private void btnGetSetting1_Click(object sender, EventArgs e) { txtFileLocation.Text = ConfigurationManager.AppSettings[SettingField.Field1.ToString()] as string; txtUserId.Text = ConfigurationManager.AppSettings[SettingField.UserId.ToString()] as string; txtSomethingElse.Text = ConfigurationManager.AppSettings[SettingField.Field3.ToString()] as string; } /// /// Retrieve section with the section path. /// private void btnGetSettings2_Click(object sender, EventArgs e) { SettingType settingType = SettingType.Type2; string fileLocation = GetImportSetting(settingType, SettingField.Field1); string userId = GetImportSetting(settingType, SettingField.Field2); string somethingElse = GetImportSetting(settingType, SettingField.Field3); txtFileLocation.Text = fileLocation; txtUserId.Text = userId; txtSomethingElse.Text = somethingElse; } /// /// Retrieve settings using the class in one call to the ConfigurationManager class. /// private void btnGetSettings3_Click(object sender, EventArgs e) { // Read a specific config file or just default to the current EXE. // Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // multConfigurationSectionHandler = configuration.Sections[SettingType.Type2.ToString()] as MultConfigurationSectionHandler; MultConfigurationSectionHandler3 multConfigurationSectionHandler2 = ConfigurationManager.GetSection(SettingType.Type3.ToString()) as MultConfigurationSectionHandler3; if (null != multConfigurationSectionHandler2) { txtFileLocation.Text = multConfigurationSectionHandler2.FileLocation; txtUserId.Text = multConfigurationSectionHandler2.UserId; txtSomethingElse.Text = multConfigurationSectionHandler2.SomethingElse; } } /// /// Return a single setting. /// private string GetImportSetting(SettingType settingType, SettingField settingField) { string ret = string.Empty; string sectionName = string.Format("{0}/{1}", settingType.ToString(), settingField.ToString()); // The .Net 1.1 Method: // ret = ConfigurationSettings.GetConfig(sectionName) as string; // The .Net 2.0 Method: ret = ConfigurationManager.GetSection(sectionName) as string; return ret; } } /// /// Group Types. /// public enum SettingType { Type2, Type3, } /// /// Field Types. /// public enum SettingField { Field1, Field2, Field3, FileLocation, UserId, SomethingElse } /// /// Configuration class. This cannot be an inner class. /// class MultConfigurationSectionHandler2 : IConfigurationSectionHandler { public object Create(object parent, object configContext, System.Xml.XmlNode section) { object ret = null; if (section.Name == SettingField.Field1.ToString() || section.Name == SettingField.Field2.ToString() || section.Name == SettingField.Field3.ToString()) ret = section.ChildNodes[0].Value; return ret; } } /// /// Configuration class. This cannot be an inner class. /// class MultConfigurationSectionHandler3 : ConfigurationSection { [ConfigurationProperty("FileLocation")] // Must Match XML Case public string FileLocation { get { return this["FileLocation"] as string; } set { this["FileLocation"] = value; } } [ConfigurationProperty("UserId")] public string UserId { get { return this["UserId"] as string; } set { this["UserId"] = value; } } [ConfigurationProperty("SomethingElse")] public string SomethingElse { get { return this["SomethingElse"] as string; } set { this["SomethingElse"] = value; } } } }