public ActionResult saveFlightData(string ip, int port, int perSecond, int numSeconds, string filename)
        {
            if (filename == "")
            {
                return(View("Error"));
            }
            WebSimulatorModel model = WebSimulatorModel.getInstance();

            if (!model.if_connected())
            {
                model.disconnect();
            }
            if (!model.connect(ip, port))
            {
                return(View("Error"));
            }
            model.saveModeOn();
            model.setFileName(filename);
            Tuple <double, double> position = model.getPosition();

            if (position == null)
            {
                model.disconnect();
                model.saveModeOff();
                return(View("Error"));
            }
            model.setFileName(filename);
            ViewBag.beginLon    = position.Item1;
            ViewBag.beginLat    = position.Item2;
            ViewBag.refreshRate = 1000 * perSecond;
            ViewBag.timeout     = (1000 * numSeconds) + 100; //give an extra tenth of a second
            return(View("SaveToFileView"));
        }
        public string writeSavedDetails()
        {
            WebSimulatorModel model = WebSimulatorModel.getInstance();

            if (!model.writeToFile())
            {
                return(ToXML("200,200")); //failure
            }
            return(ToXML("300,300"));     //success
        }
        public string getPositionFromFile()
        {
            WebSimulatorModel      model    = WebSimulatorModel.getInstance();
            Tuple <double, double> position = model.getPositionFromFile();

            if (position == null)
            {
                model.disconnect();
                return(ToXML("200,200")); //failure/end
            }
            return(ToXML(position.Item1.ToString() + "," + position.Item2.ToString()));
        }
        //loads flight data from database and presents them on map
        public ActionResult loadFlightData(string filename, int perSec)
        {
            WebSimulatorModel model = WebSimulatorModel.getInstance();

            if (!model.loadFlightDetails(filename))
            {
                return(View("Error"));
            }
            Tuple <double, double> position = model.getPositionFromFile();

            if (position == null)
            {
                return(View("Error"));
            }
            ViewBag.beginLon    = position.Item1;
            ViewBag.beginLat    = position.Item2;
            ViewBag.refreshRate = perSec;
            return(View("LoadedFromFileView"));
        }
        public ActionResult displayPosPerSec(string ip, int port, int sec)
        {
            WebSimulatorModel model = WebSimulatorModel.getInstance();

            if (!model.if_connected())
            {
                model.disconnect();
            }
            if (!model.connect(ip, port))
            {
                return(View("Error"));
            }
            Tuple <double, double> position = model.getPosition();

            if (position == null)
            {
                model.disconnect();
                return(View("Error"));
            }
            ViewBag.beginLon    = position.Item1;
            ViewBag.beginLat    = position.Item2;
            ViewBag.refreshRate = sec;
            return(View("FindRouteView"));
        }
        //gets current position of plane simulated of FlightGear and displays the position on the map
        public ActionResult displayPos(string ip, int port)
        {
            WebSimulatorModel model = WebSimulatorModel.getInstance();

            if (!model.if_connected())
            {
                model.disconnect();
            }
            if (!model.connect(ip, port))
            {
                return(View("Error"));
            }
            Tuple <double, double> position = model.getPosition();

            if (position == null)
            {
                model.disconnect();
                return(View("Error"));
            }
            //add lon and lat to the view beg in order to share it with the view.
            ViewBag.lon = position.Item1;
            ViewBag.lat = position.Item2;
            return(View("FindLocationView"));
        }