public async Task <Offer> GetOffer(OfferParameters parameters) { var request = _mapper.Map <T>(parameters); var result = await ProcessRequest(request); return(_mapper.Map <Offer>(result)); }
static async Task Main(string[] args) { var record = OfferParameters.Default(); var serializeObject = JsonConvert.SerializeObject(record); await File.WriteAllTextAsync("out.json", serializeObject); var text = File.ReadAllText("out.json"); var parameters = JsonConvert.DeserializeObject <OfferParameters>(text); Console.WriteLine(text); Console.WriteLine(parameters.MassOffersCacheInvalidationInterval.Seconds); }
static void Main(string[] args) { ConfigureDi(); var offerRequestParameters = new OfferParameters() { SourceAddress = "Toronto", DestinationAddress = "Ottawa", CartonDimensions = new string[] { "L30", "H45", "W60" } }; var offerProvider = _serviceProvider.GetService <OfferProvider>(); var bestOffer = offerProvider.FindBestOffer(offerRequestParameters).Result; Console.WriteLine($"Best offer has total of '{bestOffer.Quote}'"); Console.ReadKey(); }
public async Task <Offer> FindBestOffer(OfferParameters parameters) { var allCompanies = GetAllCompanies(); var tasks = new List <Task <Offer> >(); foreach (var company in allCompanies) { // get api depending on company type var api = _apiResolver(company.Type); // get task for receiving an offer var getOfferTask = api.GetOffer(parameters); tasks.Add(getOfferTask); } // once all offers loaded await Task.WhenAll(tasks); var offers = tasks.Select(x => x.Result).ToList(); return(offers.OrderBy(x => x.Quote).FirstOrDefault()); }
/// <summary> /// Initializes a new instance of the <see cref="Channel"/> class. /// </summary> /// <param name="multiplexingStream">The owning <see cref="Streams.MultiplexingStream"/>.</param> /// <param name="channelId">The party-qualified ID of the channel.</param> /// <param name="offerParameters">The parameters of the channel from the offering party.</param> /// <param name="channelOptions">The channel options. Should only be null if the channel is created in response to an offer that is not immediately accepted.</param> internal Channel(MultiplexingStream multiplexingStream, QualifiedChannelId channelId, OfferParameters offerParameters, ChannelOptions?channelOptions = null) { Requires.NotNull(multiplexingStream, nameof(multiplexingStream)); Requires.NotNull(offerParameters, nameof(offerParameters)); this.MultiplexingStream = multiplexingStream; this.channelId = channelId; this.OfferParams = offerParameters; switch (channelId.Source) { case ChannelSource.Local: this.localWindowSize = offerParameters.RemoteWindowSize; break; case ChannelSource.Remote: this.remoteWindowSize = offerParameters.RemoteWindowSize; break; case ChannelSource.Seeded: this.remoteWindowSize = offerParameters.RemoteWindowSize; this.localWindowSize = offerParameters.RemoteWindowSize; break; default: throw new NotSupportedException(); } if (channelOptions == null) { this.optionsAppliedTaskSource = new TaskCompletionSource <object?>(); } else { this.ApplyChannelOptions(channelOptions); } }
/// <summary> /// Initializes a new instance of the <see cref="Channel"/> class. /// </summary> /// <param name="multiplexingStream">The owning <see cref="Streams.MultiplexingStream"/>.</param> /// <param name="offeredLocally">A value indicating whether this channel originated locally (as opposed to remotely).</param> /// <param name="id">The ID of the channel.</param> /// <param name="offerParameters">The parameters of the channel from the offering party.</param> /// <param name="channelOptions">The channel options. Should only be null if the channel is created in response to an offer that is not immediately accepted.</param> internal Channel(MultiplexingStream multiplexingStream, bool offeredLocally, int id, OfferParameters offerParameters, ChannelOptions?channelOptions = null) { Requires.NotNull(multiplexingStream, nameof(multiplexingStream)); Requires.NotNull(offerParameters, nameof(offerParameters)); this.MultiplexingStream = multiplexingStream; this.offeredLocally = offeredLocally; this.Id = id; this.OfferParams = offerParameters; if (offeredLocally) { this.localWindowSize = offerParameters.RemoteWindowSize; } else { this.remoteWindowSize = offerParameters.RemoteWindowSize; } if (channelOptions == null) { this.optionsAppliedTaskSource = new TaskCompletionSource <object?>(); } else { this.ApplyChannelOptions(channelOptions); } }