Пример #1
0
        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);
        }
Пример #2
0
        public IcaoJobsFrom GetIcaoJobsFrom(List <string> ICAOs)
        {
            //TODO: name this better. its really a list of all of the assignments that start at one of the ICAOs in the passed in list.
            IcaoJobsFrom availableJobs = null;

            if (!debugEnabled)
            {
                string allICAOs = "";

                if (ICAOs.Count == 0)
                {
                    //TODO: throw an error or maybe return null because there are no ICAOs to lookup jobs for
                }
                else if (ICAOs.Count == 1)
                {
                    //TODO: handle case where there is only one ICAO
                    //build an ICAO string with the one ICAO written out 3 times to get around the 3 ICAO min for this request
                }
                else
                {
                    foreach (string str in ICAOs)
                    {
                        allICAOs += str + "-";
                    }

                    //trim the last "-" off

                    allICAOs = allICAOs.Substring(0, allICAOs.Length - 1);
                }

                //if we can make a request right now
                if (requestTracker.CanMakeRequest())
                {
                    //build the request string with all of the icao
                    //TODO: We could use a constant for the query string here
                    string url = FSEEndpoint + @"&query=icao&search=jobsfrom&icaos=" + allICAOs;

                    FSEDataRequest request = new FSEDataRequest(FSEDataRequestType.ICAO_Jobs_From, url);
                    requestTracker.AddRequest(request);

                    XmlSerializer serializer = new XmlSerializer(typeof(IcaoJobsFrom));
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        using (Stream stream = response.GetResponseStream())
                        {
                            availableJobs = (IcaoJobsFrom)serializer.Deserialize(stream);
                            //since we got a response and were able to deserialize it, lets log it
                            requestTracker.SaveRequest(request);
                        }
                }
            }
            else
            {
                //use static test data
                string        filePath   = Environment.CurrentDirectory + "\\StaticFiles\\ICAOJobsFrom-KLBB.xml";
                XmlSerializer serializer = new XmlSerializer(typeof(IcaoJobsFrom));
                using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
                {
                    availableJobs = (IcaoJobsFrom)serializer.Deserialize(fileStream);
                }
            }
            return(availableJobs);
        }