Exemple #1
0
        //allows the user to select the settings and begins the parsing
        public void fileSearch()
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                fileHandler = new CCFE_FileHandler(openFileDialog.FileName);
                configuration = new CCFE_Configuration(fileHandler.parse());

                loadConfiguration(configuration);
            }
        }
Exemple #2
0
        public static List<CCFE_ConfigurationProperty> getDefaultProperties(string configurationVersion)
        {
            List<CCFE_ConfigurationProperty> propertyList = new List<CCFE_ConfigurationProperty>();

            //check if default config file exists
            string fileLocation = AppDomain.CurrentDomain.BaseDirectory + "/config/" + configurationVersion + ".txt";
            if (File.Exists(fileLocation))
            {
                CCFE_FileHandler fileHandler = new CCFE_FileHandler(fileLocation);
                propertyList = fileHandler.parse();
            }
            else //use hardcoded values
            {
                if (configurationVersion.Equals("1.0"))
                {
                    propertyList.Add(new CCFE_ConfigurationProperty("TriggerMode", "5"));
                    propertyList.Add(new CCFE_ConfigurationProperty("OverlapPercent", "75"));
                    propertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitudeUnits", "feet"));
                    propertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitude", "400"));
                    propertyList.Add(new CCFE_ConfigurationProperty("Time", "3.8"));
                    propertyList.Add(new CCFE_ConfigurationProperty("Distance", "10"));
                    propertyList.Add(new CCFE_ConfigurationProperty("WaitForGpsFix", "yes"));
                    propertyList.Add(new CCFE_ConfigurationProperty("Version", configurationVersion));
                }
                else
                {
                    propertyList.Add(new CCFE_ConfigurationProperty("TriggerMode", "5"));
                    propertyList.Add(new CCFE_ConfigurationProperty("OverlapPercent", "75"));
                    propertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitudeUnits", "feet"));
                    propertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitude", "400"));
                    propertyList.Add(new CCFE_ConfigurationProperty("Time", "3.8"));
                    propertyList.Add(new CCFE_ConfigurationProperty("Distance", "10"));
                    propertyList.Add(new CCFE_ConfigurationProperty("WaitForGpsFix", "yes"));
                    propertyList.Add(new CCFE_ConfigurationProperty("Version", configurationVersion));
                }
            }

            return propertyList;
        }
        public void parseTest()
        {
            //ARRANGE
            CCFE_Configuration configuration = new CCFE_Configuration();

            string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "/" + "UserSettings.txt";
            //delete test file if one exists
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
            CCFE_FileHandler fileHandler = new CCFE_FileHandler(filePath);

            //make test file
            System.IO.File.WriteAllText(filePath, UserSettingsTestData);

            //ACT
            configuration.PropertyList = fileHandler.parse();

            //ASSERT
            //check if all properties are there
            Assert.IsTrue(configuration.PropertyList.Count == UserSettingsPropertyCount);
            //check if all properties have correct values
            foreach (CCFE_ConfigurationProperty property in configuration.PropertyList)
            {
                switch (property.Name)
                {
                    case "TriggerMode":
                        Assert.IsTrue(property.Value.Equals("5"));
                        break;
                    case "OverlapPercent":
                        Assert.IsTrue(property.Value.Equals("75"));
                        break;
                    case "KnownHalAltitudeUnits":
                        Assert.IsTrue(property.Value.Equals("feet"));
                        break;
                    case "KnownHalAltitude":
                        Assert.IsTrue(property.Value.Equals("400"));
                        break;
                    case "Time":
                        Assert.IsTrue(property.Value.Equals("3.8"));
                        break;
                    case "Distance":
                        Assert.IsTrue(property.Value.Equals("10"));
                        break;
                    case "WaitForGpsFix":
                        Assert.IsTrue(property.Value.Equals("yes"));
                        break;
                    case "Version":
                        Assert.IsTrue(property.Value.Equals("1.0"));
                        break;
                    default:
                        //unknown property, can't check, something parsed wrong
                        Assert.Fail();
                        break;
                }
            }

            //CLEANUP
            System.IO.File.Delete(filePath);
        }