Esempio n. 1
0
        public void LoadConfiguration()
        {
            TextReader reader = null;

            try
            {
                configuration = new OneConfiguration();
                reader        = new StreamReader(ConfigurationFileName);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    //splits the string based on '=' sign, part after the equals is the value of the corresponding attribute
                    string[] components = line.Split('=');
                    if (components.Length != 2)
                    {
                        continue;
                    }
                    string key   = components[0];
                    string value = components[1];
                    //uses first part of string to know which attribute to change
                    if (key == "nominalSpeed")
                    {
                        if (int.TryParse(value, out int nominalSpeed))
                        {
                            configuration.NominalSpeed = nominalSpeed;
                        }
                    }
                    if (key == "NotifyFood")
                    {
                        if (int.TryParse(value, out int notifyFood))
                        {
                            configuration.NominalSpeed = notifyFood;
                        }
                    }
                    if (key == "NotifyPoo")
                    {
                        if (int.TryParse(value, out int notifyPoo))
                        {
                            configuration.NominalSpeed = notifyPoo;
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine(ConfigurationFileName + " does not exist. Using defaults.");
            }
            catch (Exception e)
            {
                Console.WriteLine("LoadConfiguration error: " + e.Message);
            }
            finally
            {
                //closes the reader
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Esempio n. 2
0
 public void ObtainDefaultConfiguration()
 {
     configuration = new OneConfiguration();
 }