Example #1
0
        private void ImportPilot(string[] record)
        {
            if (Competitions.Count() == 0)
            {
                throw new InvalidOperationException("Pilot import is not allowed when no competitions are defined");
            }

            var number = int.Parse(record[1]);

            Pilot pilot;

            if (Pilots.Any(p => p.Number == number))
            {
                pilot = Pilots.First(p => p.Number == number);
            }
            else
            {
                if (Tasks.Count() > 0)
                {
                    throw new InvalidOperationException("Cannot add pilots when there are tasks defined");
                }

                pilot = new Pilot()
                {
                    Number = number
                };
                Pilots.Add(pilot);
            }

            pilot.Name    = record[2].Trim();
            pilot.Country = (record.Length > 3) ? record[3].Trim() : "";
            pilot.Balloon = (record.Length > 4) ? record[4].Trim() : "";
        }
        //creates a number of pilots
        public static void CreatePilots(int count)
        {
            List <Town> towns = Towns.GetTowns();

            Random rnd = new Random();

            for (int i = 0; i < count; i++)
            {
                Town         town      = towns[rnd.Next(towns.Count)];
                DateTime     birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-Pilot.RetirementAge), GameObject.GetInstance().GameTime.AddYears(-23));
                PilotProfile profile   = new PilotProfile(Names.GetInstance().getRandomFirstName(), Names.GetInstance().getRandomLastName(), birthdate, town);

                Dictionary <Pilot.PilotRating, int> rankings = new Dictionary <Pilot.PilotRating, int>();
                rankings.Add(Pilot.PilotRating.A, 10);
                rankings.Add(Pilot.PilotRating.B, 20);
                rankings.Add(Pilot.PilotRating.C, 40);
                rankings.Add(Pilot.PilotRating.D, 20);
                rankings.Add(Pilot.PilotRating.E, 10);

                Pilot.PilotRating ranking = AIHelpers.GetRandomItem <Pilot.PilotRating>(rankings);

                int fromYear = Math.Min(GameObject.GetInstance().GameTime.Year - 1, birthdate.AddYears(23).Year);
                int toYear   = Math.Min(GameObject.GetInstance().GameTime.Year, birthdate.AddYears(Pilot.RetirementAge).Year);

                DateTime educationTime = MathHelpers.GetRandomDate(birthdate.AddYears(23), new DateTime(toYear, 1, 1));
                Pilot    pilot         = new Pilot(profile, educationTime, ranking);

                Pilots.AddPilot(pilot);
            }
        }
Example #3
0
 private async void BtnCreate_OnClick(object sender, RoutedEventArgs e)
 {
     Canvas.Visibility = Visibility.Collapsed;
     if (isCreate)
     {
         var pilot = ReadTextBoxesData();
         if (pilot != null)
         {
             try
             {
                 await Service.Create(pilot);
             }
             catch
             {
                 Info.Text = "Server error!";
             }
             lastId++;
             pilot.Id = lastId;
             Pilots.Add(pilot);
             isCreate = false;
             CreateInfo();
             Info.Text = "Choose new action!";
         }
     }
     else
     {
         CreateInfo();
         isCreate  = true;
         Info.Text = "Info : Input data and press 'Create' ";
     }
 }
Example #4
0
        private void GetNewCard()
        {
            int randomNumber = Rng.Next(3);

            if (randomNumber == 0)
            {
                if (!isInclusingPilots && (isInclusingUpgrades || isInclusingManeuvers))
                {
                    GetNewCard(); return;
                }
                currentRandomCard     = Pilots.GetRandomPilot();
                isShowingManeuverCard = false;
            }
            else if (randomNumber == 1)
            {
                if (!isInclusingManeuvers && (isInclusingPilots || isInclusingUpgrades))
                {
                    GetNewCard(); return;
                }
                currentRandomShip     = Ships.GetRandomShip();
                isShowingManeuverCard = true;
            }
            else
            {
                if (!isInclusingUpgrades && (isInclusingPilots || isInclusingManeuvers))
                {
                    GetNewCard(); return;
                }
                currentRandomCard     = Upgrades.GetRandomUpgrade();
                isShowingManeuverCard = false;
            }
        }
Example #5
0
        private async void BtnUpdate_OnClick(object sender, RoutedEventArgs e)
        {
            if (!isCreate)
            {
                var pilotInput = ReadTextBoxesData();
                if (pilotInput != null && _selectedPilot != null)
                {
                    try
                    {
                        await Service.Update(pilotInput, _selectedPilot.Id);
                    }
                    catch
                    {
                        Info.Text = "Server error!";
                    }

                    var itemIndex = Pilots.ToList().FindIndex(x => x.Id == _selectedPilot.Id);
                    var item      = Pilots.ToList().ElementAt(itemIndex);
                    Pilots.RemoveAt(itemIndex);
                    item    = pilotInput;
                    item.Id = _selectedPilot.Id;
                    Pilots.Insert(itemIndex, item);
                    TbId.Text    = "Pilot Id :" + item.Id;
                    TbFName.Text = "First name : " + item.FirstName;
                    TbLName.Text = "Last name : " + item.LastName;
                    TbBirth.Text = "Birth : " + item.DateOfBirth;
                    TbExp.Text   = "Experience : " + item.Experience;
                }
            }
        }
Example #6
0
        private void ImportCompetition(string[] record)
        {
            var shortName = record[2].Trim();

            Competition competition;

            if (Competitions.Any(c => c.ShortName == shortName))
            {
                competition = Competitions.First(c => c.ShortName == shortName);
            }
            else
            {
                if (Tasks.Count() > 0 || Pilots.Count() > 0)
                {
                    throw new InvalidOperationException("Competition import is not allowed when there are pilots or tasks defined");
                }

                competition = new Competition()
                {
                    ShortName = shortName
                };
                Competitions.Add(competition);
            }

            competition.Name = record[1].Trim();
        }
        public PagePilots()
        {
            this.AllPilots = Pilots.GetUnassignedPilots();
            this.Loaded   += PagePilots_Loaded;

            InitializeComponent();
        }
        public async void Delete(object sender, RoutedEventArgs e)
        {
            if (SaveButton.Visibility == Visibility.Visible)
            {
                SaveButton.Visibility = Visibility.Collapsed;
            }

            if (AddButton.Visibility == Visibility.Visible)
            {
                AddButton.Visibility = Visibility.Collapsed;
            }

            try
            {
                if (TextId.IsReadOnly)
                {
                    TextId.IsReadOnly = false;
                }

                await _service.Delete(SelectedPilot.Id.ToString());

                // refresh listView
                Pilots.Clear();
                foreach (var airplaneType in await _service.LoadData())
                {
                    Pilots.Add(airplaneType);
                }
            }
            catch (Exception)
            {
            }
        }
Example #9
0
 public async void DeletePilot()
 {
     if (await service.DeleteEntity(SelectedPilot.Id))
     {
         Pilots.Remove(Pilots.FirstOrDefault(c => c.Id == SelectedPilot.Id));
     }
 }
Example #10
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var result = await Service.GetAll();

            result.ForEach(x => Pilots.Add(x));
            lastId = Pilots.LastOrDefault().Id;
        }
Example #11
0
        //creates a number of pilots
        public static void CreatePilots(int count)
        {
            List <Town> towns = Towns.GetTowns();

            Random rnd = new Random();

            for (int i = 0; i < count; i++)
            {
                Town     town      = towns[rnd.Next(towns.Count)];
                DateTime birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-Pilot.RetirementAge), GameObject.GetInstance().GameTime.AddYears(-23));

                PilotProfile profile = new PilotProfile(Names.GetInstance().getRandomFirstName(town.Country), Names.GetInstance().getRandomLastName(town.Country), birthdate, town);

                PilotRating rating = GetPilotRating();

                int fromYear = Math.Min(GameObject.GetInstance().GameTime.Year - 1, birthdate.AddYears(23).Year);
                int toYear   = Math.Min(GameObject.GetInstance().GameTime.Year, birthdate.AddYears(Pilot.RetirementAge).Year);

                DateTime educationTime = MathHelpers.GetRandomDate(birthdate.AddYears(23), new DateTime(toYear, 1, 1));
                Pilot    pilot         = new Pilot(profile, educationTime, rating);

                pilot.Aircrafts = GetPilotAircrafts(pilot);

                Pilots.AddPilot(pilot);
            }
        }
Example #12
0
    public static Pilots getPilots(string xmlToLoad)
    {
        string        filePath   = Path.Combine(Application.streamingAssetsPath, xmlToLoad);
        XmlSerializer serializer = new XmlSerializer(typeof(Pilots));
        Pilots        result     = (Pilots)serializer.Deserialize(new XmlTextReader(filePath));

        return(result);
    }
Example #13
0
        private async void Create()
        {
            var created = await airportConnector.PilotEndpoint.Create(newPilot);

            Pilots.Add(created);
            newPilot = new Pilot();
            RaisePropertyChanged(() => Pilots);
            RaisePropertyChanged(() => NewPilot);
        }
Example #14
0
        private async void FillPilotsCollection()
        {
            var temp = await service.GetEntities();

            foreach (var item in temp)
            {
                Pilots.Add(item);
            }
        }
Example #15
0
        //shows the list of pilots
        private void showPilots()
        {
            lbPilots.Items.Clear();

            foreach (Pilot pilot in Pilots.GetUnassignedPilots().OrderByDescending(p => p.Profile.Age))
            {
                lbPilots.Items.Add(pilot);
            }
        }
 public void AddPilot(Build build)
 {
     ClearState();
     pilotsRadioButton.IsChecked = true;
     isAddingPilot   = true;
     this.build      = build;
     pilots          = Pilots.GetPilots(build);
     pilotsToDisplay = pilots.ToList();
 }
Example #17
0
        public PagePilots()
        {
            this.AllPilots = new ObservableCollection <Pilot>();
            Pilots.GetUnassignedPilots().ForEach(p => this.AllPilots.Add(p));

            this.Loaded += PagePilots_Loaded;

            InitializeComponent();
        }
Example #18
0
        public void ResetPilots()
        {
            Pilots.Clear();
            foreach (var p in Event.Instance.Pilots)
                Pilots.Add(p);

            RaisePropertyChanged("Pilots");
            RaisePropertyChanged("Status");
        }
 public void SwapPilot(Build build, UniquePilot pilotToSwap)
 {
     ClearState();
     this.pilotToSwap            = pilotToSwap;
     pilotsRadioButton.IsChecked = true;
     isSwappingPilot             = true;
     this.build      = build;
     pilots          = Pilots.GetPilots(build, pilotToSwap);
     pilotsToDisplay = pilots.ToList();
 }
Example #20
0
        public DataBaseService()
        {
            // get race events from file. Each line represents a race event
            _raceEvents = getRaceEvents();

            // create our repositories from  the race events.
            // This is a reasonable way to do this since we don't have a structured database
            Races          = FactoryRaces(_raceEvents);
            Pilots         = FactoryPilots(_raceEvents);
            PilotRaceStats = FactoryRacePilotStats(_raceEvents, Races.GetAll(), Pilots.GetAll());
        }
Example #21
0
 public async void UpdatePilot()
 {
     if (await service.UpdateEntity(SelectedPilot.Id, SelectedPilot))
     {
         var tempPilot = Pilots.FirstOrDefault(c => c.Id == SelectedPilot.Id);
         tempPilot.FirstName  = SelectedPilot.FirstName;
         tempPilot.LastName   = SelectedPilot.LastName;
         tempPilot.Birthday   = SelectedPilot.Birthday;
         tempPilot.Experience = SelectedPilot.Experience;
     }
 }
Example #22
0
        static void InitializePilots()
        {
            #region Create Pilots Object or Instances
            Pilots pilot1 = new Pilots()
            {
                Name           = "Emmanuel",
                ID             = 564,
                Experience     = 11,
                Marital_Status = false
            };
            Pilots pilot2 = new Pilots();
            pilot2.Experience     = 6;
            pilot2.Name           = "Peter";
            pilot2.Marital_Status = true;
            Pilots pilot3 = new Pilots(23, "Jamiu", 13, null);
            #endregion

            #region Assemble TOtal List Of Pilots
            // Create A LIst Of Pilots

            List <Pilots> P = new List <Pilots>();
            P.Add(pilot1);
            P.Add(pilot2);
            P.Add(pilot3);
            // Pilots.Promoteworker(P); // This Has an Hard Coded Logic and its not flexible, especially if this a framework that assist other developers promote thier workers

            // Initializing My Delegate
            #endregion

            #region Delegate Call, Logic And Function Call (In a Real life Framework, I can ensure this or this would be done by the tird party calling my code)
            Pilots.IsPromotable isPromotable = new Pilots.IsPromotable(PromoteWorker);

            //This is Now The User Utilized Function That Ensures the Kind Of lOgic That is Needed for Thier bussiness

            bool PromoteWorker(Pilots pilots)
            {
                //The Logic

                if (pilots.Experience >= 10)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            Pilots.PromotePilots(P, isPromotable);

            #endregion

            //Function Call
        }
Example #23
0
 private void extractIds()
 {
     foreach (Uri filmUri in FilmUris)
     {
         Films.Add(extractId(filmUri));
     }
     foreach (Uri pilotUri in PilotUris)
     {
         Pilots.Add(extractId(pilotUri));
     }
 }
Example #24
0
        public async Task Search()
        {
            Pilots.Clear();

            List <Pilot> tempPilots = await PilotService.GetAll();

            foreach (var item in tempPilots)
            {
                Pilots.Add(item);
            }
        }
Example #25
0
        public bool RemovePilot(Guid id)
        {
            if (!Pilots.ContainsKey(id))
            {
                return(false);
            }

            Pilots[id].Dispose();
            Pilots.Remove(id);
            NotifySquadronChanges();
            return(true);
        }
Example #26
0
        private async void AddPilot()
        {
            try
            {
                var result = await _service.AddAsync(SelectedPilot);

                Pilots.Insert(0, result);
            }
            catch (System.InvalidOperationException ex)
            {
                await _dialogService.ShowMessage(ex.Message, "Error");
            }
        }
Example #27
0
        private async void DeletePilot()
        {
            try
            {
                await _service.DeleteAsync(SelectedPilot.Id);

                Pilots.Remove(SelectedPilot);
            }
            catch (System.InvalidOperationException ex)
            {
                await _dialogService.ShowMessage(ex.Message, "Error");
            }
        }
Example #28
0
    private Pilots SetUsablePilot(int id)
    {
        Pilots temp = null;

        foreach (Pilots pilot in pilots)
        {
            if (pilot.ID == id)
            {
                temp = pilot;
            }
        }
        return(temp);
    }
Example #29
0
 private async void BtnDelete_OnClick(object sender, RoutedEventArgs e)
 {
     Canvas.Visibility = Visibility.Visible;
     try
     {
         await Service.Delete(_selectedPilot.Id);
     }
     catch
     {
         Info.Text = "Server error!";
     }
     Pilots.Remove(_selectedPilot);
 }
Example #30
0
    public Pilots GetEquipPilot()
    {
        Pilots temp = null;

        foreach (Pilots pilot in PilotsCollection)
        {
            if (pilot.ID == PlayerPrefs.GetInt("CurrentPilot"))
            {
                temp = pilot;
            }
        }
        return(temp);
    }