/// <summary> /// This function is delegated by the Client Query service. /// it will iterate all sellers and make the appropriate client requested /// query, returns search results to the client /// </summary> /// <param name="src">Source of flight</param> /// <param name="dst">Destination of flight</param> /// <param name="date">Date of flight</param> /// <returns>Flights from all sellers which match the input criterias</returns> public QueryResultFlights QueryFlights(string src, string dst, string date) { Console.WriteLine("FlightSearchServer: " + dst + " " + src + " " + date); try // Sanitize date { DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture); } catch (Exception) { throw new FlightSearchServerBadDate(); } QueryResultFlights flights = new QueryResultFlights(); foreach (var seller in sellers.Keys) { FlightQuery fq = new FlightQuery(); fq.src = src; fq.dst = dst; fq.date = DateTime.Parse(date); using (new OperationContextScope((IContextChannel)sellers[seller])) { try { Flights sellerFlights = sellers[seller].GetFlights(fq); // DEAL WITH EXCEPTIONS HERE foreach (var sellerFlight in sellerFlights) { QueryResultFlight f1 = (QueryResultFlight)sellerFlight; f1.name = seller; flights.Add(f1); } } catch (FaultException e) { Console.WriteLine("Seller {0} failed with {1}, ignoring.", seller, e.Reason.ToString()); } catch (Exception e) { Console.WriteLine("Seller {0} {1} malfunction: \n{2}", seller, "search", e.Message.ToString()); ITicketSellingQueryService victim; sellers.TryRemove(seller, out victim); } } } flights.Sort(); return(flights); }
/// <summary> /// client flights search query handler /// This function will call the business logic singleton to fetch Flights /// from all sellers, convert them to the appropriate container and return /// them to the client. /// </summary> /// <param name="src">Source of the flight</param> /// <param name="dst">Destination of the flight</param> /// <param name="date">Reuired date</param> /// <returns>List of flights ordered as requested</returns> public QueryResultFlights GetFlights(string src, string dst, string date) { Console.WriteLine("ClientQueryService: " + dst + " " + src + " " + date); QueryResultFlights flights = null; try { flights = FlightSearchLogic.Instance.QueryFlights(src, dst, date); } catch (FlightSearchServerException e) { WebOperationContext.Current.OutgoingResponse.StatusCode = e.StatusCode; //e.StatusCode; // System.Net.HttpStatusCode.NotFound; WebOperationContext.Current.OutgoingResponse.StatusDescription = e.StatusDescription; } catch (Exception e) { WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound(e.Message); } return(flights); }