/// <summary> /// Update LineInfos items to have same length as 'lines' /// </summary> /// <param name="newcount">count of 'lines' - same should be a length of LineInfos</param> public void UpdateLineInfos(int newcount) { // here is a speed optimization - if we have already more items in 'LineInfos' than in 'lines' - do nothing if (LineInfos.Count >= newcount) { // we dont need to remove items from this list - data is same for all items except field 'startY' // but even this field will be same for same indexes, so we can leave already calculated items as is //Debug.WriteLine("UpdateLineInfos skiped newcount = " + newcount); return; } int charHeight = CharHeight; LineInfos.Capacity = newcount; int paddingTop = Paddings.Top; // add items to LineInfos to enshure length is same as 'lines' has for (int i = LineInfos.Count; i < newcount; i++) { int startY = i * charHeight + paddingTop; LineInfos.Add(new LineInfo(startY)); } }
public async Task MainLoop(CancellationToken token) { try { Products = await Api.Controller.GetProducts(); LineInfos = Api.Controller.getLstLine(); } catch { //MessageBox.Show("Fail To start, Please run app again"); } while (true) { try { token.ThrowIfCancellationRequested(); var List_UnconfirmOrder = await Api.Controller.getLstOrderNotFinishAsync(); if (List_UnconfirmOrder != null) { if (UnconfirmOrders.Count > 0) { var MaxID = UnconfirmOrders.Max(x => x.OrderID); var NewOrder = List_UnconfirmOrder.Where(x => x.OrderID > MaxID).ToList(); NewOrder.ForEach(x => { x.LineInfo = LineInfos.Where(z => z.LineInfoID == x.LineInfoID).FirstOrDefault(); x.Product = Products.Where(z => z.ProductID == x.ProductID).FirstOrDefault(); UnconfirmOrders.Add(x); }); List <Order> ConfirmedOrder = new List <Order>(); foreach (Order Order in UnconfirmOrders) { if (List_UnconfirmOrder.Where(x => x.OrderID == Order.OrderID).FirstOrDefault() == null) { ConfirmedOrder.Add(Order); } } if (ConfirmedOrder.Count > 0) { ConfirmedOrder.ForEach(x => UnconfirmOrders.Remove(x)); } } else { List_UnconfirmOrder.ForEach(x => { x.LineInfo = LineInfos.Where(z => z.LineInfoID == x.LineInfoID).FirstOrDefault(); x.Product = Products.Where(z => z.ProductID == x.ProductID).FirstOrDefault(); UnconfirmOrders.Add(x); }); } } } catch { return; } await Task.Delay(1000); } }