public void ProcessStockInfoRequest(StockInfoRequest stockInfoRequest) { StockInfoResponse stockInfoResponse = new StockInfoResponse(stockInfoRequest.ConverterStream); stockInfoResponse.AdoptHeader(stockInfoRequest); foreach (StockInfoCriteria criteria in stockInfoRequest.Criteria) { List <StockProduct> matchingProduct; var articleCode = String.IsNullOrWhiteSpace(criteria.RobotArticleCode) ? criteria.PISArticleCode : criteria.RobotArticleCode; if (String.IsNullOrEmpty(articleCode)) { matchingProduct = new List <StockProduct>(this.stock.StockProductList.Values); } else { matchingProduct = new List <StockProduct> { this.stock.GetStockProduct(articleCode) }; } #warning to do test Tenant change foreach (StockProduct stockProduct in matchingProduct) { List <RobotPack> stockPackList = stockProduct.GetPackList( criteria.BatchNumber, criteria.ExternalID, criteria.MachineLocation, criteria.StockLocationID, 0, stockInfoRequest.TenantID); stockInfoResponse.Packs.AddRange(stockPackList); } } if (stockInfoRequest.Criteria.Count == 0) { // load all stock. foreach (KeyValuePair <string, StockProduct> stockProduct in this.stock.StockProductList) { stockInfoResponse.Packs.AddRange(stockProduct.Value.GetPackList(stockInfoRequest.TenantID)); } } // add article information stockInfoResponse.Articles.AddRange(this.BuildArticleList(stockInfoResponse.Packs, stockInfoRequest.IncludeArticleDetails)); if (!stockInfoRequest.IncludePacks) { stockInfoResponse.Packs.Clear(); } stockInfoResponse.ConverterStream.Write(stockInfoResponse); }
internal Task SendResponseAsync(StockInfoResponse response, CancellationToken cancellationToken = default) { return(this.SendResponseAsync(response, () => { return this.Dialog.SendResponseAsync(response, cancellationToken); })); }
internal void SendResponse(StockInfoResponse response) { this.SendResponse(response, () => { this.Dialog.SendResponse(response); }); }
public IStockInfoFinishedProcessState StartProcess(bool?includePacks, bool?includeArticleDetails, IEnumerable <StockInfoRequestCriteria>?criterias) { StockInfoRequest request = this.CreateRequest(includePacks, includeArticleDetails, criterias); StockInfoResponse response = this.SendRequest(request, () => { return(this.Dialog.SendRequest(request)); }); return(new StockInfoFinishedProcessState(request, response)); }
public async Task <IStockInfoFinishedProcessState> StartProcessAsync(bool?includePacks, bool?includeArticleDetails, IEnumerable <StockInfoRequestCriteria>?criterias, CancellationToken cancellationToken = default) { StockInfoRequest request = this.CreateRequest(includePacks, includeArticleDetails, criterias); StockInfoResponse response = await this.SendRequestAsync(request, () => { return(this.Dialog.SendRequestAsync(request, cancellationToken)); }).ConfigureAwait(continueOnCapturedContext: false); return(new StockInfoFinishedProcessState(request, response)); }
public void Send(StockInfoResponse response) { using var connection = _factory.CreateConnection(); using var channel = connection.CreateModel(); channel.QueueDeclare(queue: AppConstants.STOCK_MESSAGE_RESPONSE_Q, durable: false, exclusive: false, autoDelete: false, arguments: null); var responseJson = JsonConvert.SerializeObject(response); var body = Encoding.UTF8.GetBytes(responseJson); channel.BasicPublish(exchange: "", routingKey: AppConstants.STOCK_MESSAGE_RESPONSE_Q, basicProperties: null, body: body); }
public async Task <StockInfoResponse> GetStockInfo(string stockCode) { var response = new StockInfoResponse(); try { var stockUrl = $"https://stooq.com/q/l/?s={stockCode}&f=sd2t2ohlcv&h&e=csv"; using var client = new HttpClient(); var csvStream = await client.GetStreamAsync(stockUrl); response.StockInfo = GetStockInfo(csvStream); response.Success = true; } catch (Exception e) { Console.WriteLine("Error getting stock info {0}: {1}", stockCode, e.Message); } return(response); }
public StockInfoFinishedProcessState(StockInfoRequest request, StockInfoResponse response) { this.Request = request; this.Response = response; }
public Task SendResponseAsync(StockInfoResponse response, CancellationToken cancellationToken = default) { return(base.SendResponseAsync(response, cancellationToken)); }
public void SendResponse(StockInfoResponse response) { base.SendResponse(response); }