コード例 #1
0
        public void CCFE_FileHandlerTest()
        {
            //ARRANGE
            string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "/" + "UserSettings.txt";

            //ACT
            CCFE_FileHandler fileHandler = new CCFE_FileHandler(filePath);
            //check deep copy
            filePath = "AlternateValue";

            //ASSERT
            Assert.IsTrue(fileHandler.FileLocation.Equals(System.AppDomain.CurrentDomain.BaseDirectory + "/" + "UserSettings.txt"));
        }
コード例 #2
0
ファイル: CCFE_Default.cs プロジェクト: ccfe-capstone/ccfe
        public static List<CCFE_ConfigurationProperty> getCommentPropertyPairs(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.parseComments();
            }
            else //use hardcoded values
            {
                if (configurationVersion.Equals("1.0"))
                {
                    string property = "TriggerMode";
                    string comment =
                        "# TriggerMode\n" +
                        "# 0: Time (for systems without GPS only)\n" +
                        "# 1: Network\n" +
                        "# 2: MAVlink\n" +
                        "# 3: GPS Distance\n" +
                        "# 4: GPS Time\n" +
                        "# 5: GPS Overlap - Auto Detect Altitude\n" +
                        "# 6: GPS Overlap - Known Altitude\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "OverlapPercent";
                    comment =
                        "\n" +
                        "# --------- GPS Overlap Trigger Options ---------\n" +
                        "# Only used when TriggerMode is 5 or 6 (GPS Overlap - Auto Detect OR Known Altitude)\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "KnownHalAltitudeUnits";
                    comment =
                        "\n" +
                        "# Only used when TriggerMode is 6 (GPS Overlap - Known Altitude)\n" +
                        "# KnownAltitudeUnits options: feet, meters\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "KnownHalAltitude";
                    comment =
                        "";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "Time";
                    comment =
                        "\n" +
                        "# --------- Time Trigger Options ---------\n" +
                        "# Only used when TriggerMode is 0 or 4 (Time)\n" +
                        "# Time in seconds\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "Distance";
                    comment =
                        "\n" +
                        "# --------- GPS Distance Trigger Options ---------\n" +
                        "# Only used when TriggerMode is 3 (Distance)\n" +
                        "# Distance in meters\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "WaitForGpsFix";
                    comment =
                        "\n" +
                        "# --------- General GPS Options -------------------\n" +
                        "# Only used when TriggerMode is 3,4,5,6\n" +
                        "# Options: yes, no\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "Version";
                    comment =
                        "\n" +
                        "# Indicates version of this file, to know what fields are available\n" +
                        "# Minor number increments when new fields are added\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));
                }
                else //default to 1.0
                {
                    string property = "TriggerMode";
                    string comment =
                        "# TriggerMode\n" +
                        "# 0: Time (for systems without GPS only)\n" +
                        "# 1: Network\n" +
                        "# 2: MAVlink\n" +
                        "# 3: GPS Distance\n" +
                        "# 4: GPS Time\n" +
                        "# 5: GPS Overlap - Auto Detect Altitude\n" +
                        "# 6: GPS Overlap - Known Altitude\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "OverlapPercent";
                    comment =
                        "\n" +
                        "# --------- GPS Overlap Trigger Options ---------\n" +
                        "# Only used when TriggerMode is 5 or 6 (GPS Overlap - Auto Detect OR Known Altitude)\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "KnownHalAltitudeUnits";
                    comment =
                        "\n" +
                        "# Only used when TriggerMode is 6 (GPS Overlap - Known Altitude)\n" +
                        "# KnownAltitudeUnits options: feet, meters\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "KnownHalAltitude";
                    comment =
                        "";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "Time";
                    comment =
                        "\n" +
                        "# --------- Time Trigger Options ---------\n" +
                        "# Only used when TriggerMode is 0 or 4 (Time)\n" +
                        "# Time in seconds\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "Distance";
                    comment =
                        "\n" +
                        "# --------- GPS Distance Trigger Options ---------\n" +
                        "# Only used when TriggerMode is 3 (Distance)\n" +
                        "# Distance in meters\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "WaitForGpsFix";
                    comment =
                        "\n" +
                        "# --------- General GPS Options -------------------\n" +
                        "# Only used when TriggerMode is 3,4,5,6\n" +
                        "# Options: yes, no\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));

                    property = "Version";
                    comment =
                        "\n" +
                        "# Indicates version of this file, to know what fields are available\n" +
                        "# Minor number increments when new fields are added\n";
                    propertyList.Add(new CCFE_ConfigurationProperty(property, comment));
                }
            }

            return propertyList;
        }
コード例 #3
0
ファイル: CCFE_Default.cs プロジェクト: ccfe-capstone/ccfe
        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;
        }
コード例 #4
0
ファイル: MainWindow.cs プロジェクト: ccfe-capstone/ccfe
        //checks to see if either of the filehandler or configuration objects have been created
        //meaning a new file has been made or a file location was set
        public bool checkSave()
        {
            //sanitize inputs to eliminate possible blanks
            double knownHalAltitude;
            double triggerPeriod;
            double triggerDistance;
            bool kHA;
            bool tP;
            bool tD;

            kHA = Double.TryParse(knownHalAltitudeValue.Text, out knownHalAltitude);
            tP = Double.TryParse(triggerPeriodValue.Text, out triggerPeriod);
            tD = Double.TryParse(triggerDistanceValue.Text, out triggerDistance);

            if (!kHA || !tP || !tD)
            {
                String message = "The following settings were left blank:\n\n";
                if (!kHA)
                {
                    message += "Known Hal Altitude\n";
                }
                if (!tP)
                {
                    message += "Trigger Period\n";
                }
                if (!tD)
                {
                    message += "Trigger Distance\n";
                }
                message += "\nProceed with these values set to 0?";
                if (MessageBox.Show(message, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                {
                    return false;
                }
                else
                {
                    if (!kHA)
                    {
                        knownHalAltitudeValue.Text = "0";
                    }
                    if (!tP)
                    {
                        triggerPeriodValue.Text = "0";
                    }
                    if (!tD)
                    {
                        triggerDistanceValue.Text = "0";
                    }
                }
            }

            if (configuration == null || fileHandler == null)
            {
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    fileHandler = new CCFE_FileHandler(saveFileDialog.FileName);
                    configuration = new CCFE_Configuration(versionToolStripMenuItem.Text);
                }
                //they canceled or input something wrong
                else
                {
                    return false;
                }
            }
            return true;
        }
コード例 #5
0
ファイル: MainWindow.cs プロジェクト: ccfe-capstone/ccfe
 private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (saveFileDialog.ShowDialog() == DialogResult.OK)
     {
         fileHandler = new CCFE_FileHandler(saveFileDialog.FileName);
         if (checkSave())
         {
             saveConfiguration();
         }
     }
 }
コード例 #6
0
ファイル: MainWindow.cs プロジェクト: ccfe-capstone/ccfe
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     fileHandler = null;
     newConfiguration(versionToolStripMenuItem.Text);
     loadConfiguration(configuration);
     MessageBox.Show("A new Configuration page has been created");
 }
コード例 #7
0
ファイル: MainWindow.cs プロジェクト: ccfe-capstone/ccfe
        //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);
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public void saveTest()
        {
            //ARRANGE
            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);

            CCFE_Configuration configuration = new CCFE_Configuration();
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("TriggerMode", "5"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("OverlapPercent", "75"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitudeUnits", "feet"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitude", "400"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("Time", "3.8"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("Distance", "10"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("WaitForGpsFix", "yes"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("Version", "1.0"));

            //ACT
            fileHandler.save(configuration);

            //ASSERT
            //check if file was created
            Assert.IsTrue(System.IO.File.Exists(filePath));
            //check if file was saved with correct data
            Assert.IsTrue(System.IO.File.ReadAllText(filePath).Equals(UserSettingsTestData));

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