public List <Assignment> getCommercialJobs(AircraftItems allAircraft) { //TODO: input validation to make sure we only got aircraft that can have commercial (aka All-In Reserved) flights List <Assignment> result = new List <Assignment>(); //loop over each assignment foreach (Assignment assignment in Assignments) { //if the assignment aicraft id is zero then its not an all in assignment and we can short circuit this so no obj has to be created //check to see if the aicraft in the assignment is in the list of aircraft that were passed in if (allAircraft.AircraftList.Contains(new Aircraft(assignment.AircraftId))) { result.Add(assignment); } } return(result); }
/// <summary> /// Get all aircraft from FSE given the passed in make and model. /// </summary> /// <param name="makeModel">the airplane we want to query FSE for.</param> /// <returns>the AircraftItems which is a list of the aircraft in FSE that match the MakeModel. An empty list if there are no aircraft. Null if there was an error.</returns> public AircraftItems GetAircraftByMakeModel(string makeModel) { AircraftItems aircraftItems = null; //TODO: If we have recently made a requests to get the AircraftItems for this MakeModel, //just return that data instead of call FSE again if (!debugEnabled) { //TODO: We could use a constant for the query string here string url = FSEEndpoint + @"&query=aircraft&search=makemodel&makemodel=" + makeModel; //if we can make a request and a recent response for this make model doesnt exist, make a new request to FSE if (requestTracker.CanMakeRequest()) { FSEDataRequest request = new FSEDataRequest(FSEDataRequestType.Aircraft_By_MakeModel, url); requestTracker.AddRequest(request); XmlSerializer serializer = new XmlSerializer(typeof(AircraftItems)); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) { aircraftItems = (AircraftItems)serializer.Deserialize(stream); //since we got a response and were able to deserialize it, lets log it requestTracker.SaveRequest(request); } //TODO: logging for the response could go here } } else { //use static test data for AircraftItems string filePath = Environment.CurrentDirectory + "\\StaticFiles\\AircraftItems_AirbusA320_MSFS.xml"; XmlSerializer serializer = new XmlSerializer(typeof(AircraftItems)); using (FileStream fileStream = new FileStream(filePath, FileMode.Open)) { aircraftItems = (AircraftItems)serializer.Deserialize(fileStream); } } return(aircraftItems); }
private List <Assignment> getAllCommercialAssignments(string makeModel) { //TODO: input validation on makeModel, must only be makemodesl that have "commercial flights" aka assigned All-In assignments" //TODO: Make this return a assignment object? List <Assignment> availableAssignments = new List <Assignment>(); if (fseDataExport.requestTracker.remainingRequests() >= 2) { //Get the current list of all aicraft that match the Make and Model - Query FSE Data Feed' AircraftItems allAircraft = fseDataExport.GetAircraftByMakeModel(makeModel); //build the list of ICAO that have the plane we want List <string> AirportsWithMatchingPlane = new List <string>(); foreach (Aircraft aircraft in allAircraft.AircraftList) { //make sure the plane is not rented and is at a valid location //TODO: if we want to filter by locations we could do that here? if (aircraft.RentedBy.CompareTo("Not rented.") == 0 && aircraft.Location.Length == 4) { AirportsWithMatchingPlane.Add(aircraft.Location); } /* if a plane doest have 4 letters in the location then that plane is currently rented and/or flying * else * { * System.Console.WriteLine("plane has a location with only 3 letters in the icao: " + aircraft.Registration); * } */ } //Query FSE Data Feed for list of jobs from each ICAO that has makeModel - query = ICAO Jobs From IcaoJobsFrom ICAOAssignments = fseDataExport.GetIcaoJobsFrom(AirportsWithMatchingPlane); if (ICAOAssignments == null) { //there was some issue with getting the assignments //TODO: Handle this gracefully throw new Exception("Unable to retrieve assignments"); } else { availableAssignments = ICAOAssignments.getCommercialJobs(allAircraft); } } //TODO: refactor this so we dont need to use an if statement on the madeModel. This should be handled with inheritance //List<Assignment> availableAssignments = new List<Assignment>(); //if (ICAOAssignments == null) //{ // //there was some issue with getting the assignments // throw new Exception("Unable to retrieve assignments"); //} //else if (makeModel == "Boeing 737-800") //{ // availableAssignments = ICAOAssignments.get737Jobs(allAircraft); //} //else if (makeModel == "Boeing 747-400") //{ // availableAssignments = ICAOAssignments.get747Jobs(allAircraft); //} //else //{ // //some error has occured // throw new ArgumentException("makeModel is an invalid type", makeModel); //} return(availableAssignments); }