public IObservable<GameModel> GetGames(string rootPath) { if (string.IsNullOrEmpty(rootPath)) { rootPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\Samples")); ////rootPath = Path.Combine( //// Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), //// @"Documents\GitHub\TreatyOfBabel.NET\Samples"); } var games = new List<GameModel>(); // Use the Treaty of Babel helper to understand the files... var helper = App.TreatyHelper; var files = Directory.EnumerateFiles(rootPath, "*.*", SearchOption.AllDirectories); foreach (var file in files.Take(10)) { if (helper.IsTreatyFile(file)) { var game = new GameModel(file, rootPath); games.Add(game); ////if (games.Count >= 1) ////{ //// break; ////} } } return games.ToObservable(); }
public IObservable<GameModel> GetGames(string rootPath) { if (string.IsNullOrEmpty(rootPath) || !Directory.Exists(rootPath)) { return Observable.Empty<GameModel>(); } // iterate the path, looking for games... return Observable.Create<GameModel>((observer, cancel) => { var task = Task.Factory.StartNew(() => { // Use the Treaty of Babel helper to understand the files... var helper = App.TreatyHelper; var files = Directory.EnumerateFiles(rootPath, "*.*", SearchOption.AllDirectories); foreach (var file in files) { if (cancel.IsCancellationRequested) { break; } if (helper.IsTreatyFile(file)) { var game = new GameModel(file, rootPath); observer.OnNext(game); } } observer.OnCompleted(); }, cancel); return task; }); }