public void Execute() { var apple = new Product("Apple", Color.Green, Size.Small); var tree = new Product("Tree", Color.Green, Size.Large); var house = new Product("House", Color.Blue, Size.Large); Product[] products = { apple, tree, house }; var filtrMngr = new FilterManager <Product>(); Console.WriteLine("Green products (new):"); foreach (var p in filtrMngr.Filter(products, new ColorSpecification(Color.Green))) { Console.WriteLine($" - {p.Name} is green"); } Console.WriteLine("Large products"); foreach (var p in filtrMngr.Filter(products, new SizeSpecification(Size.Large))) { Console.WriteLine($" - {p.Name} is large"); } Console.WriteLine("Large blue items"); foreach (var p in filtrMngr.Filter(products, new AndSpecification <Product>( new ColorSpecification(Color.Blue), new SizeSpecification(Size.Large)))) { Console.WriteLine($" - {p.Name} is big and blue"); } }
// public void FindStocks() // { // Thread thread = new Thread(() => FindStocks(_settings.Filters)); // thread.Start(); // } private void FindStocks(List <Filter> filters) { // UpdateStatus($"Filtering stocks by {filters.Count} filters"); IEnumerable <StockInfo> stocks = FilterManager.Filter(filters); // UpdateStatus("Done"); Dispatcher.Invoke(() => { grid.Items.Clear(); foreach (StockInfo stock in stocks) { grid.Items.Add(stock); } }); }
private void FindStocks(List <Filter> filters) { //string[] symbols = StockUtils.AllSymbols.ToArray(); //List<StockInfo> stocks = new List<StockInfo>(); //Dispatcher.Invoke(() => LblLoadProgress.Content = "Downloading Data"); //foreach (IEnumerable<string> batch in StockUtils.Split(symbols, 500)) //{ // string url = $"http://finance.yahoo.com/d/quotes.csv?s={string.Join(",", batch)}&f={"sl1r"}"; // WebRequest request = WebRequest.Create(url); // request.Credentials = CredentialCache.DefaultCredentials; // WebResponse response = request.GetResponse(); // Stream stream = response.GetResponseStream(); // string res = new StreamReader(stream).ReadToEnd(); // string[] lines = res.Split('\n'); // stocks.AddRange( // lines.Take(lines.Length - 1) // .TakeWhile(line => line != null) // .Select(StockUtils.ParseCsvRow) // .Select( // vals => // new StockInfo() // { // Ticker = vals[0], // LastTradePrice = NumberUtils.parseDouble(vals[1]), // Pe = NumberUtils.parseDouble(vals[2]) // })); //} UpdateStatus($"Filtering stocks by {filters.Count} filters"); IEnumerable <StockInfo> stocks = FilterManager.Filter(filters); UpdateStatus("Done"); Dispatcher.Invoke(() => { // grid.DataContext = stocks; //grid.Items.Refresh(); grid.Items.Clear(); foreach (StockInfo stock in stocks) { grid.Items.Add(stock); } }); }