Exemplo n.º 1
0
        private void btWriteIcaoSQDB_Click(object sender, EventArgs e)
        {
            if (IDB.Count <= 0)
            {
                RTB.Text += $"ERROR - No Aircraft records found, load BaseStation first\n";
                return;
            }

            var    iw     = new AircraftsDB( );
            string folder = Path.Combine(@"D:\DUMPTEST", CSV_PATH);

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            RTB.Text += iw.CreateDB(Path.Combine(folder, "dump1090fa-aircrafts.sqb"));
            RTB.Text += iw.LoadDBfromIcao(IDB);
            RTB.Text += $"SQDB Icao ModeS file written (or not if prevously was an error...)\n";
        }
Exemplo n.º 2
0
        // Collect Aircraft data from various sources
        // Write into web aircraft database
        private static void DoAircraftJob()
        {
            if (!jobAircrafts)
            {
                return;
            }
            Console.WriteLine($"\nCreating aircraft database ..");

            // read FA db
            if (jobAircraftsFAin)
            {
                string folder = Path.Combine(inputDir, faDbDirName);
                Console.WriteLine($"Reading FA Json database folder file: {folder}");
                Console.WriteLine(icaoDbReader.ReadDb(ref IDB, folder));
                Console.WriteLine($"DONE - ICAO ModeS Database contains {IDB.Count} records\n");
            }

            // read BaseStation.sqb
            if (jobAircraftsBS)
            {
                string file = Path.Combine(inputDir, basestationFile);
                var    ir   = new BaseStationReader( );
                if (!ir.Connect(file))
                {
                    Console.WriteLine($"ERROR Reading BaseStation SQB database file: {file} - cannot open database");
                }
                else
                {
                    Console.WriteLine($"Reading BaseStation SQB database file: {file}");
                    Console.WriteLine(ir.ReadDb(ref IDB));
                    Console.WriteLine($"DONE - ICAO ModeS Database contains {IDB.Count} records\n");
                }
            }

            // read OSky aircrafts
            if (jobAircraftsCsv)
            {
                string file = Path.Combine(inputDir, icaoAcCsvFile);
                Console.WriteLine($"Reading ICAO Aircraft OpenSky CSV file: {file}");
                Console.WriteLine(icaoCsvOpenSkyReader.ReadDb(ref IDB, file));
                Console.WriteLine($"DONE - ICAO ModeS Database Database contains {IDB.Count} records\n");
            }

            // read manual additions
            if (jobAircraftsAddon)
            {
                string file = Path.Combine(inputDir, icaoAddFile);
                Console.WriteLine($"Reading ICAO Aircraft Addon CSV file: {file}");
                Console.WriteLine(icaoCsvAddonReader.ReadDb(ref IDB, file));
                Console.WriteLine($"DONE - ICAO ModeS Database Database contains {IDB.Count} records\n");
            }

            // Create now
            if (IDB.Count <= 0)
            {
                Console.WriteLine($"ERROR - No Aircraft records found, load populated BaseStation first\n");
                return;
            }
            var iw = new AircraftsDB( );

            Console.WriteLine(iw.CreateDB(Path.Combine(outputDir, aircraftsDBFile)));
            Console.WriteLine(iw.LoadDBfromIcao(IDB));
            Console.WriteLine($"SQDB ICAO ModeS file written (or not if previously was an error...)");
        }
Exemplo n.º 3
0
        public bool DbFetchSheduller()
        {
            var BaseLocation = _Configuration["LocationsList:BaseLocation"];
            var LocationList = _Configuration.GetSection("LocationsList:ToLocations").GetChildren().Select(x => x.Value).ToArray();

            foreach (var item in LocationList)
            {
                DateTime DateStart = DateTime.Now;
                DateTime DateStop  = DateStart.AddDays(330);

                for (DateTime DateRunning = DateStart; DateRunning.Date < DateStop.Date; DateRunning = DateRunning.AddDays(1))
                {
                    FlightOfferSearchRQ     FlightOfferSearchRQ     = new FlightOfferSearchRQ();
                    OriginLocationCode      OriginLocationCode      = new OriginLocationCode();
                    DestinationLocationCode DestinationLocationCode = new DestinationLocationCode();
                    Pax Pax = new Pax();

                    OriginLocationCode.DepartureDate = DateRunning;
                    OriginLocationCode.IataCode      = BaseLocation;

                    DestinationLocationCode.IataCode = item;

                    FlightOfferSearchRQ.TravelClass  = "";
                    FlightOfferSearchRQ.NonStop      = true;
                    FlightOfferSearchRQ.CurrencyCode = "";

                    Pax.Adult = 1;

                    var SearchString = "flight-offers?originLocationCode=" + OriginLocationCode.IataCode + "&destinationLocationCode=" + DestinationLocationCode.IataCode + "&departureDate=" + OriginLocationCode.DepartureDate.ToString("yyyy-MM-dd") + "&adults=" + Pax.Adult + "&nonStop=" + FlightOfferSearchRQ.NonStop.ToString().ToLower() + "&max=250";

                    FlightOffersSearchRS FlightOffersSearchRS = _ISearchConnecterCaller.FlightOffersSearch(SearchString);

                    if (FlightOffersSearchRS == null)
                    {
                        int i = 0;
                        while (FlightOffersSearchRS == null && i < 3)
                        {
                            System.Threading.Thread.Sleep(1000);
                            FlightOffersSearchRS = _ISearchConnecterCaller.FlightOffersSearch(SearchString);
                            i++;
                        }
                    }

                    try
                    {
                        FlightOffersSearchDB FlightOffersSearchDBObj = new FlightOffersSearchDB();
                        MetaDB         MetaDBObj         = new MetaDB();
                        List <DatumDB> DatumDBList       = new List <DatumDB>();
                        DictionariesDB DictionariesDBObj = new DictionariesDB();

                        MetaDBObj.links = FlightOffersSearchRS.meta.links;
                        MetaDBObj.count = FlightOffersSearchRS.meta.count;
                        FlightOffersSearchDBObj.meta = MetaDBObj;

                        foreach (var Data in FlightOffersSearchRS.data)
                        {
                            DatumDB DatumDBObj = new DatumDB();
                            DatumDBObj.type   = Data.type;
                            DatumDBObj.id     = Data.id;
                            DatumDBObj.source = Data.source;
                            DatumDBObj.instantTicketingRequired = Data.instantTicketingRequired;
                            DatumDBObj.nonHomogeneous           = Data.nonHomogeneous;
                            DatumDBObj.oneWay                = Data.oneWay;
                            DatumDBObj.lastTicketingDate     = Data.lastTicketingDate;
                            DatumDBObj.numberOfBookableSeats = Data.numberOfBookableSeats;

                            List <ItineraryDB> ItineraryDBList = new List <ItineraryDB>();
                            foreach (var Itineraries in Data.itineraries)
                            {
                                ItineraryDB ItineraryDBObj = new ItineraryDB();
                                ItineraryDBObj.duration = Itineraries.duration;
                                List <SegmentDB> SegmentDBList = new List <SegmentDB>();

                                foreach (var Segments in Itineraries.segments)
                                {
                                    SegmentDB SegmentDBObj = new SegmentDB();
                                    SegmentDBObj.carrierCode     = Segments.carrierCode;
                                    SegmentDBObj.number          = Segments.number;
                                    SegmentDBObj.duration        = Segments.duration;
                                    SegmentDBObj.id              = Segments.id;
                                    SegmentDBObj.numberOfStops   = Segments.numberOfStops;
                                    SegmentDBObj.blacklistedInEU = Segments.blacklistedInEU;

                                    DepartureDB DepartureDBObj = new DepartureDB();
                                    DepartureDBObj.iataCode = Segments.departure.iataCode;
                                    DepartureDBObj.terminal = Segments.departure.terminal;
                                    DepartureDBObj.at       = Segments.departure.at;

                                    SegmentDBObj.departure = DepartureDBObj;

                                    ArrivalDB ArrivalDBObj = new ArrivalDB();
                                    ArrivalDBObj.iataCode = Segments.arrival.iataCode;
                                    ArrivalDBObj.terminal = Segments.arrival.terminal;
                                    ArrivalDBObj.at       = Segments.arrival.at;

                                    SegmentDBObj.arrival = ArrivalDBObj;

                                    AircraftDB AircraftDBObj = new AircraftDB();
                                    AircraftDBObj.code = Segments.aircraft.code;

                                    SegmentDBObj.aircraft = AircraftDBObj;

                                    OperatingDB OperatingDBObj = new OperatingDB();
                                    OperatingDBObj.carrierCode = Segments.operating.carrierCode;

                                    SegmentDBObj.operating = OperatingDBObj;

                                    SegmentDBList.Add(SegmentDBObj);
                                }
                                ItineraryDBObj.segments = SegmentDBList;
                                ItineraryDBList.Add(ItineraryDBObj);
                            }
                            DatumDBObj.itineraries = ItineraryDBList;

                            PriceDB PriceDBObj = new PriceDB();
                            PriceDBObj.currency   = Data.price.currency;
                            PriceDBObj.total      = Data.price.total;
                            PriceDBObj.@base      = Data.price.@base;
                            PriceDBObj.grandTotal = Data.price.grandTotal;

                            List <FeeDB> FeesDBList = new List <FeeDB>();
                            foreach (var Fees in Data.price.fees)
                            {
                                FeeDB FeesDB = new FeeDB();
                                FeesDB.amount = Fees.amount;
                                FeesDB.type   = Fees.type;
                                FeesDBList.Add(FeesDB);
                            }
                            PriceDBObj.fees = FeesDBList;

                            DatumDBObj.price = PriceDBObj;

                            PricingOptionsDB PricingOptionsDBobj = new PricingOptionsDB();
                            PricingOptionsDBobj.includedCheckedBagsOnly = Data.pricingOptions.includedCheckedBagsOnly;

                            foreach (var Fare in Data.pricingOptions.fareType)
                            {
                                PricingOptionsDBobj.fareType += Fare + ",";
                            }

                            DatumDBObj.pricingOptions = PricingOptionsDBobj;

                            foreach (var validatingAirlineCodes in Data.validatingAirlineCodes)
                            {
                                DatumDBObj.validatingAirlineCodes += validatingAirlineCodes + ",";
                            }

                            List <TravelerPricingDB> TravelerPricingDBList = new List <TravelerPricingDB>();
                            foreach (var TravelerPricings in Data.travelerPricings)
                            {
                                TravelerPricingDB TravelerPricingDBObj = new TravelerPricingDB();
                                TravelerPricingDBObj.travelerId   = TravelerPricings.travelerId;
                                TravelerPricingDBObj.fareOption   = TravelerPricings.fareOption;
                                TravelerPricingDBObj.travelerType = TravelerPricings.travelerType;

                                TravelPriceDB TravelPriceDBObj = new TravelPriceDB();
                                TravelPriceDBObj.currency  = TravelerPricings.price.currency;
                                TravelPriceDBObj.total     = TravelerPricings.price.total;
                                TravelPriceDBObj.@base     = TravelerPricings.price.@base;
                                TravelerPricingDBObj.price = TravelPriceDBObj;

                                List <FareDetailsBySegmentDB> FareDetailsBySegmentDBList = new List <FareDetailsBySegmentDB>();
                                foreach (var FareDetailsBySegment in TravelerPricings.fareDetailsBySegment)
                                {
                                    FareDetailsBySegmentDB FareDetailsBySegmentDBObj = new FareDetailsBySegmentDB();
                                    FareDetailsBySegmentDBObj.cabin     = FareDetailsBySegment.cabin;
                                    FareDetailsBySegmentDBObj.segmentId = FareDetailsBySegment.segmentId;
                                    FareDetailsBySegmentDBObj.fareBasis = FareDetailsBySegment.fareBasis;
                                    FareDetailsBySegmentDBObj.@class    = FareDetailsBySegment.@class;

                                    IncludedCheckedBagsDB IncludedCheckedBagsDBObj = new IncludedCheckedBagsDB();
                                    IncludedCheckedBagsDBObj.weight     = FareDetailsBySegment.includedCheckedBags.weight;
                                    IncludedCheckedBagsDBObj.weightUnit = FareDetailsBySegment.includedCheckedBags.weightUnit;

                                    FareDetailsBySegmentDBObj.includedCheckedBags = IncludedCheckedBagsDBObj;
                                    FareDetailsBySegmentDBList.Add(FareDetailsBySegmentDBObj);
                                }

                                TravelerPricingDBObj.fareDetailsBySegment = FareDetailsBySegmentDBList;
                                TravelerPricingDBList.Add(TravelerPricingDBObj);
                            }
                            DatumDBObj.travelerPricings = TravelerPricingDBList;
                            DatumDBList.Add(DatumDBObj);
                        }

                        FlightOffersSearchDBObj.data = DatumDBList;
                        DictionariesDB     DictionariesDBObjI = new DictionariesDB();
                        List <AircraftsDB> AircraftsDBList    = new List <AircraftsDB>();
                        List <CurenciesDB> CurenciesDBList    = new List <CurenciesDB>();
                        List <CarriersDB>  CarriersDBList     = new List <CarriersDB>();

                        foreach (KeyValuePair <string, string> entry in FlightOffersSearchRS.dictionaries.Aircraft)
                        {
                            AircraftsDB AircraftsDBObj = new AircraftsDB();
                            AircraftsDBObj.Details = entry.Key + "_ " + entry.Value;
                            AircraftsDBList.Add(AircraftsDBObj);
                        }

                        DictionariesDBObjI.Aircraft = AircraftsDBList;

                        foreach (KeyValuePair <string, string> entry in FlightOffersSearchRS.dictionaries.Currencies)
                        {
                            CurenciesDB CurenciesDBObj = new CurenciesDB();
                            CurenciesDBObj.Details = entry.Key + "_ " + entry.Value;
                            CurenciesDBList.Add(CurenciesDBObj);
                        }

                        DictionariesDBObjI.Currencies = CurenciesDBList;


                        foreach (KeyValuePair <string, string> entry in FlightOffersSearchRS.dictionaries.Carriers)
                        {
                            CarriersDB CarriersDBObj = new CarriersDB();
                            CarriersDBObj.Details = entry.Key + " _ " + entry.Value;
                            CarriersDBList.Add(CarriersDBObj);
                        }
                        DictionariesDBObjI.Carriers          = CarriersDBList;
                        FlightOffersSearchDBObj.dictionaries = DictionariesDBObjI;

                        _DatabaseContext.Add <FlightOffersSearchDB>(FlightOffersSearchDBObj);
                        _DatabaseContext.SaveChanges();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            return(true);
        }