public List <Flights> getFlightsList(IMemoryCache cache, string queryString, string relativeTo) { //if those word exist in the request- return a list of a all the flights. bool syncAll = queryString.Contains("sync_all"); List <Flights> FlightList; Dictionary <string, FlightPlan> FlightPlanDictionary; //check if the dictionary exist in cache- if so, return a list of all the flights if (cache.TryGetValue("FlightPlanDictionary", out FlightPlanDictionary)) { FlightManager FlightManager = new FlightManager(); FlightPlanManager flightPlanManager = new FlightPlanManager(); List <string> FlightPlanListId = new List <string>(); if (!cache.TryGetValue("FlightPlanListId", out FlightPlanListId)) { FlightPlanListId = flightPlanManager.getFlightPlanListId(); cache.Set("FlightPlanListId", FlightPlanListId); } FlightList = FlightManager.createFlightList(FlightPlanDictionary, relativeTo, syncAll, FlightPlanListId); return(FlightList); } //else- return all external flights else if (syncAll) { ServerManager serverManager = new ServerManager(); FlightList = serverManager.externalFlightList(relativeTo); return(FlightList); } return(null); }
//return FlightPlan by Id public FlightPlan getFlightPlanById(IMemoryCache cache, string Id) { FlightPlan FlightPlan = null; IFlightManager FlightManager = new FlightManager(); if (cache.TryGetValue("FlightPlanDictionary", out FlightPlanDictionary)) { //Id = Id.Substring(1, Id.Length - 2); if (!FlightPlanDictionary.TryGetValue(Id, out FlightPlan)) { Console.WriteLine("error"); } } ServerManager serverManager = new ServerManager(); Dictionary <string, string> IdFromServer = serverManager.getIdFromServer(); string serverId; if (Id[0] == '{') { Id = Id.Substring(1, Id.Length - 2); } if (IdFromServer.TryGetValue(Id, out serverId)) { //get Flights plan from external server by id FlightPlan = serverManager.externalFlightPlanById(Id, serverId); } return(FlightPlan); }