Exemple #1
0
        /// <summary>
        /// Add a list of paths to the db.
        /// </summary>
        /// <param name="position">The position we are using for this paths.</param>
        /// <param name="pathList">A list of paths.</param>
        /// <returns>A list of all paths that made trouble.</returns>
        public List<AirportPushBackPath> AddPathByList(List<AirportPushBackPath> pathList)
        {
            // The return list with error path objects. Hope it will always be null.
            List<AirportPushBackPath> errorPath = new List<AirportPushBackPath>();

            using (var db = new YapbtDbEntities())
            {
                foreach (var path in pathList)
                {
                    try
                    {
                        // Add the new path.
                        AirportPushBackPath newPath = new AirportPushBackPath();
                        newPath = path;
                        db.AirportPushBackPath.Add(newPath);

                        // TODO bulk inserts?
                        db.SaveChanges();
                    }
                    catch (System.Exception)
                    {
                        // unable to store it into the db. Add it to the list for an error message.
                        errorPath.Add(path);
                    }
                }
            }

            return errorPath;
        }
Exemple #2
0
        /// <summary>
        /// Add a new airport variation.
        /// </summary>
        /// <param name="variationName">The name of the airport variation.</param>
        /// <param name="airport">      The airport it will reference to.</param>
        /// <returns>True variation added to db; False something went wrong.</returns>
        public bool AddNewVariation(string variationName, Airport airport)
        {
            // Use the YapbtDbEntities to store the data.
            using (var db = new YapbtDbEntities())
            {
                try
                {
                    // Create a new variation, add the data and safe it.
                    AirportVariations variation = new AirportVariations();

                    variation.Airport = airport;
                    variation.variationname = variationName;
                    variation.cts = DateTime.Now;

                    // Add the new variation to the db.
                    db.AirportVariations.Add(variation);
                    db.SaveChanges();

                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Remove all points belonging to a single pushback path.
        /// </summary>
        /// <param name="pushBackPath">The pushback path we are looking for.</param>
        /// <returns>True allright; False something went wrong.</returns>
        public bool RemovePushbackPoint(AirportPushBackPath pushBackPath)
        {
            try
            {
                using (var db = new YapbtDbEntities())
                {
                    // Find a list of all points, which belongs to this path.
                    var points = db.AirportPushPoints.Where(c => c.AirportPushBackPath == pushBackPath).ToList();

                    // If any point was found, remove it.
                    if (points.Any())
                    {
                        points.ForEach(delegate (AirportPushPoints point)
                        {
                            db.AirportPushPoints.Remove(point);
                            db.SaveChanges();
                        });
                    }

                    return true;
                }
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }
Exemple #4
0
        /// <summary>
        /// Set the config value
        /// </summary>
        /// <param name="needle">The configuration part.</param>
        /// <param name="value">The new value.</param>
        /// <returns>Return an error code.</returns>
        public ReturnCodes.Codes SetConfig(string needle, string value)
        {
            using (var db = new YapbtDbEntities())
            {
                try
                {
                    var item = db.Configuration.Where(c => c.Setting == needle).FirstOrDefault();
                    item.Value = value;
                    db.SaveChanges();

                    return ReturnCodes.Codes.Ok;

                }
                catch (Exception ex)
                {
                    return ReturnCodes.Codes.Error;
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Remove all pushback paths belonging to a position.
        /// </summary>
        /// <param name="position">The position it will lookup for.</param>
        /// <returns>True everything was ok; False something went wrong.</returns>
        public bool RemoveAllPushbackPathOfPosition(AirportPositions position)
        {
            using (var db = new YapbtDbEntities())
            {
                Point point = new Point();

                // Find all pushback paths belonging to the position.
                var pushBackPath = db.AirportPushBackPath.Where(c => c.positionid == position.positionid).ToList();

                // If any path was found.
                if (pushBackPath.Any())
                {
                    // For each path remove the positions and the path.
                    pushBackPath.ForEach(delegate (AirportPushBackPath pushpath)
                    {
                        point.RemovePushbackPoint(pushpath);
                        db.AirportPushBackPath.Remove(pushpath);
                        db.SaveChanges();
                    });
                }

                return true;
            }
        }
Exemple #6
0
        /// <summary>
        /// Remove all positions of an variation.
        /// </summary>
        /// <param name="variation">
        /// The airport variation. With this object, it will lookup for all positions.
        /// </param>
        /// <returns>True everything went well; False something went wrong.</returns>
        public bool RemoveAllPositions(AirportVariations variation)
        {
            using (var db = new YapbtDbEntities())
            {
                Path path = new Path();

                // Find a list of all positions, which belongs to this variation.
                var position = db.AirportPositions.Where(c => c.variationid == variation.variationid).ToList();

                // If any position is available.
                if (position.Any())
                {
                    // For each position, remove all pushback path and remove the position.
                    position.ForEach(delegate (AirportPositions pos)
                    {
                        path.RemoveAllPushbackPathOfPosition(pos);
                        db.AirportPositions.Remove(pos);
                        db.SaveChanges();
                    });
                }

                return true;
            }
        }
Exemple #7
0
        /// <summary>
        /// Saving all parking positions of the bgl file into the db.
        /// </summary>
        /// <returns>Returns a code about the status.</returns>
        public ReturnCodes.Codes StoreParkingPos()
        {
            // Load the xml file.
            XDocument xmlDoc = XDocument.Load(this.fields.outputFilePath);

            IEnumerable<XElement> ParkingPositions = null;

            try
            {
                // Get all parking positions.
                ParkingPositions =
                            from el in xmlDoc
                            .Descendants("FSData")
                            .Descendants("Airport")
                            .Descendants("TaxiwayParking")
                            select el;
            }
            catch (Exception)
            {
                // Something went wrong, returning an error code.
                return ReturnCodes.Codes.XmlError;
            }

            try
            {
                using (var db = new YapbtDbEntities())
                {
                    // Reading all xml elements add the data to an object and save into the sqlite db.
                    foreach (XElement ParkingPosition in ParkingPositions)
                    {
                        TempParking parking = new TempParking();

                        parking.Index = Convert.ToInt64(ParkingPosition.Attribute("index").Value);
                        parking.Name = ParkingPosition.Attribute("name").Value;
                        parking.Number = Convert.ToInt64(ParkingPosition.Attribute("number").Value);

                        // Converting the latitude and longitude to string and double to avoid
                        // system culture problems.
                        string txt = ParkingPosition.Attribute("lat").Value.ToString(CultureInfo.InvariantCulture);

                        //back to a double
                        parking.Latitude = double.Parse(txt, CultureInfo.InvariantCulture);

                        txt = ParkingPosition.Attribute("lon").Value.ToString(CultureInfo.InvariantCulture);

                        //back to a double
                        parking.Longitude = double.Parse(txt, CultureInfo.InvariantCulture);

                        db.TempParking.Add(parking);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                // Something went wrong, returning an error code.
                return ReturnCodes.Codes.ImportError;
            }

            return ReturnCodes.Codes.ImportOk;
        }
Exemple #8
0
        /// <summary>
        /// Saving all taxiways of the bgl file into the db.
        /// </summary>
        /// <returns>Returns a code about the status.</returns>
        public ReturnCodes.Codes StoreTaxiway()
        {
            // Load the xml file.
            XDocument xmlDoc = XDocument.Load(this.fields.outputFilePath);

            IEnumerable<XElement> TaxiwayPaths = null;

            try
            {
                // Get all taxiway paths.
                TaxiwayPaths =
                            from el in xmlDoc
                            .Descendants("FSData")
                            .Descendants("Airport")
                            .Descendants("TaxiwayPath")
                            select el;
            }
            catch (Exception)
            {
                // Something went wrong, returning an error code.
                return ReturnCodes.Codes.XmlError;
            }

            try
            {
                using (var db = new YapbtDbEntities())
                {
                    // Reading all xml elements add the data to an object and save into the sqlite db.
                    foreach (XElement TaxiwayPath in TaxiwayPaths)
                    {
                        var path = new TempTaxiway();

                        path.FromPoint = Convert.ToInt64(TaxiwayPath.Attribute("start").Value);
                        path.ToPoint = Convert.ToInt64(TaxiwayPath.Attribute("end").Value);

                        db.TempTaxiway.Add(path);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                // Something went wrong, returning an error code.
                return ReturnCodes.Codes.ImportError;
            }

            return ReturnCodes.Codes.ImportOk;
        }
Exemple #9
0
        /// <summary>
        /// Saving all points of the bgl file into the db.
        /// </summary>
        /// <returns>Returns a code about the status.</returns>
        public ReturnCodes.Codes StorePoints()
        {
            // Load the xml file.
            XDocument xmlDoc = XDocument.Load(this.fields.outputFilePath);

            IEnumerable<XElement> TaxiwayPoints = null;

            try
            {
                // Get all taxiway points.
                TaxiwayPoints =
                            from el in xmlDoc
                            .Descendants("FSData")
                            .Descendants("Airport")
                            .Descendants("TaxiwayPoint")
                            select el;
            }
            catch (Exception)
            {
                return ReturnCodes.Codes.XmlError;
            }

            try
            {
                using (var db = new YapbtDbEntities())
                {
                    foreach (XElement TaxiPoint in TaxiwayPoints)
                    {
                        var point = new TempPoint();

                        point.Index = Convert.ToInt64(TaxiPoint.Attribute("index").Value);

                        // Converting the latitude and longitude to string and double to avoid
                        // system culture problems.
                        string txt = TaxiPoint.Attribute("lat").Value.ToString(CultureInfo.InvariantCulture);

                        //back to a double
                        point.Latitude = double.Parse(txt, CultureInfo.InvariantCulture);

                        txt = TaxiPoint.Attribute("lon").Value.ToString(CultureInfo.InvariantCulture);

                        //back to a double
                        point.Longitude = double.Parse(txt, CultureInfo.InvariantCulture);

                        db.TempPoint.Add(point);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                return ReturnCodes.Codes.ImportError;
            }

            return ReturnCodes.Codes.ImportOk;
        }
Exemple #10
0
        static void AddVariation(string variationName, Airport airport, YapbtDbEntities db)
        {
            // Create a new variation, add the data and safe it.
            AirportVariations variation = new AirportVariations();

            variation.Airport = airport;
            variation.variationname = variationName;
            variation.cts = DateTime.Now;

            // Add the new variation to the db.
            db.AirportVariations.Add(variation);
            db.SaveChanges();
        }
Exemple #11
0
        /// <summary>
        /// Delete a variation and all necessary data (positions, paths).
        /// </summary>
        /// <param name="variation">The variation to delete.</param>
        /// <returns>True variation was delted; False not able.</returns>
        public bool DeleteVariation(AirportVariations variation)
        {
            using (var db = new YapbtDbEntities())
            {
                Position position = new Position();

                //TODO Remove Pushbackpath and positions.
                position.RemoveAllPositions(variation);

                db.AirportVariations.Remove(variation);
                db.SaveChanges();

                return true;
            }
        }
Exemple #12
0
        /// <summary>
        /// Remove a single pushback point.
        /// </summary>
        /// <param name="pushBackPoint">The single pushback point we are looking for.</param>
        /// <returns>True point deleted; False something went wrong.</returns>
        public bool RemovePushbackPoint(AirportPushPoints pushBackPoint)
        {
            try
            {
                // Checking if the point is set.
                if (pushBackPoint != null)
                {
                    using (var db = new YapbtDbEntities())
                    {
                        // Remove the pushback point.
                        db.AirportPushPoints.Remove(pushBackPoint);
                        db.SaveChanges();

                        return true;
                    }
                }

                return false;
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }