public static void RefreshTable(StockCollection stockCollection, V_GetStockPriceDelegate getStockPrice, ListView listViewStocks)
        {
            var stockValues   = V_StockValuator.GetStockValues(stockCollection, getStockPrice);
            var lineInfos     = V_Formatter.GetLineInfos(stockValues);
            var listViewItems = lineInfos.Select(CreateListViewItem).ToArray();

            listViewStocks.Items.Clear();
            listViewStocks.Items.AddRange(listViewItems);
        }
        private static IEnumerable <M_StockWithPrice> AddPriceToStock(StockCollection stockCollection)
        {
            StockPriceLoader stockPriceLoader = new StockPriceLoader();

            return(stockCollection.EnumerateStocks()
                   .Select(stock => new M_StockWithPrice()
            {
                Stock = stock, Price = stockPriceLoader.Load(stock.Ticker)
            }));
        }
        public static void RefreshTable(E_IStocksStore stocksStore, M_IStockDisplayTable stockDisplayTable)
        {
            StockCollection stockCollection = stocksStore.LoadStocks();

            IEnumerable <M_StockWithPrice> stocksWithPrice = AddPriceToStock(stockCollection);

            IEnumerable <M_StockWithPriceAndValue> stocksWithPriceAndValue = CalculateGainAndCurrentValue(stocksWithPrice);

            M_StockWithPriceAndValue total = CalculateTotalCurrentValueAndGain(stocksWithPriceAndValue);

            List <M_StockDisplayData> displayLines = FormatDataForDisplay(stocksWithPriceAndValue, total);

            stockDisplayTable.Render(displayLines);
        }
Ejemplo n.º 4
0
        public Form1(StocksStore stocksStore, GainModel gainModel, V_GetStockPriceDelegate getStockPrice)
        {
            _stocksStore = stocksStore;
            InitializeComponent();

            _stocksRepository         = stocksStore;
            _gainModel                = gainModel;
            _getStockPrice            = getStockPrice;
            _stockCollection          = stocksStore.LoadStocks();
            _stockCollection.Changed += (sender, e) => V_StockProcessor.RefreshTable(_stockCollection, _getStockPrice, _listViewStocks);
            _stockCollection.Changed += (sender, e) => SaveStocks();

            V_StockProcessor.RefreshTable(_stockCollection, _getStockPrice, _listViewStocks);
        }