/// <summary> /// Initializes a new instance of the <see cref="QueryContext"/> class. /// </summary> /// <param name="filters">query filters</param> /// <param name="client">the client</param> /// <param name="otherClients">other clients</param> /// <param name="sort">deas sort</param> /// <param name="userLocation">user location</param> /// <param name="userData">user data</param> /// <param name="inputFlights">input flights</param> /// <param name="parentEventId">parent event id</param> public QueryContext(QueryFilters filters = null, Client client = null, IEnumerable <Client> otherClients = null, DealsSort?sort = null, UserLocation userLocation = null, UserData userData = null, IEnumerable <string> inputFlights = null, Guid?parentEventId = null) { Filters = filters ?? new QueryFilters(); Sort = sort ?? DealsSort.Relevance; UserLocation = userLocation; UserData = userData ?? new UserData(); Client = client ?? new Client(Client.IdUnknown, Client.AppUnknown); OtherClients = otherClients ?? Enumerable.Empty <Client>(); InputFlights = inputFlights; AssignFlightKey(); Ranking = new QueryRanking(Client, Filters, FlightKey); EventId = Guid.NewGuid(); ParentEventId = parentEventId == null ? EventId : parentEventId.Value; }
/// <summary> /// Assigns Flight.Key /// </summary> private void AssignFlightKey() { var userId = GetUserPrimaryIdInfo().Id; // try to get deals server flight key from input list var flightKey = InputFlights != null?InputFlights.FirstOrDefault(_ => _.StartsWith(Flight.KeyPrefix, true, CultureInfo.InvariantCulture)) : null; if (flightKey != null) { // get flight key from flight dictionary by full key match Flight flight; if (!Flight.List.TryGetValue(flightKey, out flight)) { // get flight key from flight dictionary by partial key match (take most recent version) flight = Flight.List.Where(_ => _.Key.StartsWith(flightKey, true, CultureInfo.InvariantCulture)).OrderByDescending(_ => _.Value.Version).FirstOrDefault().Value; } if (flight != null) { flightKey = flight.Key; //// Check whether client-flight combination is valid; var pcfps = QueryRanking.GetPlacementCfps(Client, flightKey, false); if (pcfps != null) { // if client-flight combination is valid - remove from input list to avoid duplicate logging InputFlights = InputFlights.Where(_ => _.ToLower() != flightKey.ToLower()).ToList(); } else { // if client-flight combination is not valid set key to null flightKey = null; } } else { // if not present in index set key to null flightKey = null; } } FlightKey = flightKey ?? ClientFlightAllocation.GetFlightKey(Client.Key, userId); }