コード例 #1
0
        /// <summary>
        /// Back-up method that will run each day at a certain time
        /// </summary>
        /// <param name="timeSpan">The time of the day the method will run</param>
        private static void StoreFlightDetailsHistory(object timeSpan)
        {
            //If the format of the invokation time is not correct the method will not run
            if (!TimeSpan.TryParse(timeSpan.ToString(), out TimeSpan ts))
            {
                _logger.Error("Time to backup flights details history is configured in wrong format");
                return;
            }

            //check how many seconds left till backup
            double secondsToGo = (ts - DateTime.Now.TimeOfDay).TotalSeconds;

            if (secondsToGo < 0)//if the seconds number is negative (meaning the tome is passed for today), add 24 hours
            {
                secondsToGo += (24 * 60 * 60);
            }

            Thread.Sleep(new TimeSpan(0, 0, (int)secondsToGo));//Sleeo till invokation time
            _logger.Debug($"Backup will start in {secondsToGo} seconds");

            while (true)//will run each 24 hours while the system us up
            {
                _logger.Info("Starting backup...");

                IFlightDAO flightDAO = new FlightDAOPGSQL();
                ITicketDAO ticketDAO = new TicketDAOPGSQL();
                IFlightsTicketsHistoryDAO flightsTicketsHistoryDAO = new FlightsTicketsHistoryDAOPGSQL();
                var flights_with_tickets = flightDAO.GetFlightsWithTicketsAfterLanding(3 * 60 * 60);//get all flight with tickets that landed 3+ hours ago inside dictionary
                int flights_count        = 0;
                int tickets_count        = 0;

                foreach (Flight flight in flights_with_tickets.Keys)                     //Run over all the keys (flights) in the dictionary
                {
                    flightsTicketsHistoryDAO.Add(flight, FlightStatus.Landed);           //Add the flight to history table

                    foreach (Ticket ticket in flights_with_tickets[flight])              //Run over all the tickets of the flight
                    {
                        if (ticket.Id != 0)                                              //If there is no tickets associated with the flight there will be one ticket with id, we don't want to add this ticket to the history
                        {
                            flightsTicketsHistoryDAO.Add(ticket, TicketStatus.Redeemed); //Add ticket to history table
                            ticketDAO.Remove(ticket);                                    //Remove the ticket from original table
                            tickets_count++;
                        }
                    }

                    flightDAO.Remove(flight);//Remove the flight from original table
                    flights_count++;
                }

                _logger.Info($"Backed up {flights_count} flights and {tickets_count} tickets");
                Thread.Sleep(new TimeSpan(24, 0, 0));
            }
        }
コード例 #2
0
        private FlightCenterSystem()
        {
            Thread thread = new Thread(() =>
            {
                FlightDAOPGSQL flightDAOPGSQL = new FlightDAOPGSQL();
                TicketDAOPGSQL ticketDAOPGSQL = new TicketDAOPGSQL();
                while (true)
                {
                    try
                    {
                        if (DateTime.Now.TimeOfDay == AppConfig.Instance.WakingUpTime.TimeOfDay)
                        {
                            DateTime date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                                         DateTime.Now.Hour - 3, DateTime.Now.Minute, DateTime.Now.Second);
                            IList <Flight> flights = flightDAOPGSQL.GetOldFlights(date);
                            foreach (Flight flight in flights)
                            {
                                IList <Ticket> tickets = ticketDAOPGSQL.GetTicketsByFlight(flight);
                                foreach (Ticket ticket in tickets)
                                {
                                    ticketDAOPGSQL.Add_To_Tickets_History(ticket);
                                    ticketDAOPGSQL.Remove(ticket);
                                }
                                flightDAOPGSQL.Add_to_flights_history(flight);
                                flightDAOPGSQL.Remove(flight);
                            }
                            log.Info($"Old flights and ticket were transformed to archive at {DateTime.Now.Date}");
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error($"Could not transform old tickets and flights to the archive: {ex.Message}");
                    }
                }
            });

            thread.Start();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            TestDbConnection();
            //CountryDAOPGSQL countryDAOPGSQL = new CountryDAOPGSQL();

            //Country countryDominicana = new Country
            //{
            //    Name = "Dominicana"
            //};

            //countryDAOPGSQL.Add(countryDominicana);



            ////var countries = countryDAOPGSQL.GetAll();

            ////foreach (var c in countries)
            ////{
            ////    var id = ((dynamic)c).Id;
            ////    var name = ((dynamic)c).Name;

            ////    Console.WriteLine($"{id} {name}");
            ////}

            //Console.WriteLine(countryDAOPGSQL.Get(6));

            //countryDAOPGSQL.Remove(countryDominicana);

            ////countryDAOPGSQL.Update(countryDominicana);

            //var countries = countryDAOPGSQL.GetAll();

            //foreach (var c in countries)
            //{

            //admin.Add(admin1);       //    var id = ((dynamic)c).Id;
            //    var name = ((dynamic)c).Name;

            //    Console.WriteLine($"{id} {name}");
            //}



            //UserDAOPGSQL user = new UserDAOPGSQL();
            //AdminDAOPGSQL admin = new AdminDAOPGSQL();
            //DeleteAllData();
            //User manager2 = new User
            //{
            //    Username = "******",
            //    Password = "******",
            //    Email = "*****@*****.**",
            //    User_Role = 3
            //};
            //user.Add(manager2);



            //var u = user.GetByUserName("manager2");

            //long id = u.Id;

            //Console.WriteLine(id);

            //Admin admin1 = new Admin("Mary", "Mill", 1, id);


            UserDAOPGSQL user = new UserDAOPGSQL();
            //AdminDAOPGSQL admin = new AdminDAOPGSQL();
            CustomerDAOPGSQL       customerDAOPGSQL       = new CustomerDAOPGSQL();
            FlightDAOPGSQL         flightDAOPGSQL         = new FlightDAOPGSQL();
            AirlineCompanyDAOPGSQL airlineCompanyDAOPGSQL = new AirlineCompanyDAOPGSQL();
            CountryDAOPGSQL        countryDAOPGSQL        = new CountryDAOPGSQL();

            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;
            //DeleteAllData();


            //LoginToken<Admin> token = new LoginToken<Admin>(


            //    );
            //token.User.UserName = FlightCenterConfig.ADMIN_NAME;
            //token.User.Password = FlightCenterConfig.ADMIN_PASSWORD;

            //User user0 = new User
            //{
            //    Username = "******",
            //    Password = "******",
            //    Email = "*****@*****.**",
            //    User_Role = 1
            //};
            //user.Add(user0);

            //var uA = user.GetByUserName("Airline");
            //long idA = uA.Id;


            //AirlineCompany airline = new AirlineCompany
            //{
            //    Name = "AirlineCompany1",
            //    Country_Id = 1,
            //    User_Id = (int)idA
            //};
            //airlineCompanyDAOPGSQL.Add(airline);

            //var a = airlineCompanyDAOPGSQL.GetAirlineByUserame("Airline");
            //Console.WriteLine("aurline: " + a);
            //long a_id = a.Id;

            //Flight flight = new Flight
            //{
            //    Airline_Company_Id = (long)a_id,
            //    Origin_Country_Id = 1,
            //    Destination_Country_Id = 2,
            //    Departure_Time = new DateTime(2021, 05, 09, 12, 00, 00),
            //    Landing_Time = new DateTime(2021, 05, 09, 18, 00, 00),
            //    Tickets_Remaining = 100
            //};
            //flightDAOPGSQL.Add(flight);

            //User user1 = new User
            //{
            //    Username = "******",
            //    Password = "******",
            //    Email = "*****@*****.**",
            //    User_Role = 1
            //};
            //user.Add(user1);

            //var u = user.GetByUserName("Customer");
            //long id = u.Id;

            //Customer customer = new Customer()
            //{
            //    First_Name = "name",
            //    Last_Name = "lNAme",
            //    Address = "Adress",
            //    Phone_No = "Phone",
            //    Credit_Card_No = "Card",
            //    User_Id = id
            //};

            //loginService.TryAdminLogin(FlightCenterConfig.ADMIN_NAME, FlightCenterConfig.ADMIN_PASSWORD, out LoginToken<Admin> tokenAdmin);
            //LoggedInAdministratorFacade facadeAdmin = FlightsCenterSystem.GetInstance().GetFacade<Admin>(tokenAdmin) as LoggedInAdministratorFacade;

            //facadeAdmin.CreateNewCustomer(tokenAdmin, customer);
            //Customer c = facadeAdmin.GetAllCustomers(tokenAdmin)[0];
            //// facadeAdmin.CreateNewCustomer(tokenAdmin, customer);


            //LoginToken<Customer> tokenCustomer = new LoginToken<Customer>()
            //{
            //    User = c
            //};
            //loginService.TryCustomerLogin("Customer", "c112", out tokenCustomer);
            //Customer customer1 = customerDAOPGSQL.GetCustomerByUserName("Customer");
            // loginService.TryCustomerLogin ("Customer", "c112", out tokenCustomer);


            //LoggedInCustomerFacade fasadeCustomer = FlightsCenterSystem.GetInstance().GetFacade(tokenCustomer) as LoggedInCustomerFacade;
            //var myFlight = flightDAOPGSQL.GetAll()[0];
            //Ticket t = fasadeCustomer.PurchaseTicket(tokenCustomer, myFlight);
            // Console.WriteLine(tokenCustomer);
            // Console.WriteLine(customer1.Password);
            // Console.WriteLine(c.U);


            // User manager2 = new User
            // {
            //     Username = "******",
            //     Password = "******",
            //     Email = "*****@*****.**",
            //     User_Role = 3
            // };


            // //User manager3 = new User
            // //{
            // //    Username = "******",
            // //    Password = "******",
            // //    Email = "*****@*****.**",
            // //    User_Role = 3
            // //};

            // user.Add(manager2);
            // //user.Add(manager3);


            // var u = user.GetByUserName("manager2");

            //// var u3 = user.GetByUserName("manager3");

            // long id = u.Id;
            // Admin admin1 = new Admin
            // {
            //     First_Name = "Mary",
            //     Last_Name = "Mill",
            //     Level = 3,
            //     User_id = id
            // };



            // //long id3 = u3.Id;
            // //Admin adminLevel1 = new Admin
            // //{
            // //    First_Name = "Parry",
            // //    Last_Name = "Mill",
            // //    Level = 1,
            // //    User_id = id3
            // //};



            //  admin.Add(admin1);


            //var list = admin.GetAll();
            //list.RemoveAt(0);
            //facadeAdminLevel3.RemoveAdmin(tokenAdminLevel3, list[0]);
            //list = admin.GetAll();

            //list.Remove(admin1);
            //list = admin.GetAll();
            //Console.WriteLine(list.Count);

            // Console.WriteLine(token.User.UserName);


            //customerDAOPGSQL.Add(customer);
            //facadeAdmin.CreateNewCustomer(token, customer);
            //var list = facadeAdmin.GetAllCustomers(token);

            //Console.WriteLine(list.Count);



            // var l_cust = facadeAdmin.GetAllCustomers(token);

            //Console.WriteLine(l_cust[1]);

            //AirlineCompany airline = new AirlineCompany
            //{
            //    Name = "AirlineCompany1",
            //    Country_Id = 1,
            //    User_Id = (int)id
            //};
            //airlineCompanyDAOPGSQL.Add(airline);

            //var a = airlineCompanyDAOPGSQL.GetAirlineByUserame("airline1");
            //Console.WriteLine("aurline: " + a);
            //long a_id = a.Id;

            //Flight flight = new Flight
            //{
            //    Airline_Company_Id = (long)a_id,
            //    Origin_Country_Id = 1,
            //    Destination_Country_Id = 2,
            //    Departure_Time = new DateTime(2021, 05, 09, 12, 00, 00),
            //    Landing_Time = new DateTime(2021, 05, 09, 18, 00, 00),
            //    Tickets_Remaining = 100
            //};
            //flightDAOPGSQL.Add(flight);

            //var f_list = flightDAOPGSQL.GetAll();
            //var f = facade.GetFlightsByDestinationCountry(2);

            //Console.WriteLine(f[0].Id);
            //Console.WriteLine(f[0].Landing_Time);
            //Console.WriteLine(f[0].NameOfOriginCountry);
        }