public LogEntryViewer(ILogEntryService logEntryService) { //build an observable filter var filter = this.WhenAnyValue(x => x.SearchText) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(BuildFilter); //filter, sort and populate reactive list. var shared = logEntryService.Items.Connect() .Transform(le => new LogEntryProxy(le)) .DelayRemove(TimeSpan.FromSeconds(0.75), proxy => proxy.FlagForRemove()) .Publish(); var loader = shared.Filter(filter) .Sort(SortExpressionComparer <LogEntryProxy> .Descending(le => le.TimeStamp).ThenByDescending(l => l.Key), SortOptions.UseBinarySearch) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out var data) .DisposeMany() .Subscribe(); Data = data; //aggregate total items var summariser = shared.QueryWhenChanged(items => { var debug = items.Count(le => le.Level == LogLevel.Debug); var info = items.Count(le => le.Level == LogLevel.Info); var warn = items.Count(le => le.Level == LogLevel.Warning); var error = items.Count(le => le.Level == LogLevel.Error); return(new LogEntrySummary(debug, info, warn, error)); }) .Subscribe(s => Summary = s); //manage user selection, delete items command var selectedItems = _selectionController.SelectedItems.Connect().Publish(); //Build a message from selected items _deleteItemsText = selectedItems.QueryWhenChanged(query => { if (query.Count == 0) { return("Select log entries to delete"); } if (query.Count == 1) { return("Delete selected log entry?"); } return($"Delete {query.Count} log entries?"); }) .ToProperty(this, viewmodel => viewmodel.DeleteItemsText, "Select log entries to delete"); //make a command out of selected items - enabling the command when there is a selection DeleteCommand = ReactiveCommand.Create(() => { var toRemove = _selectionController.SelectedItems.Items.Select(proxy => proxy.Original).ToArray(); _selectionController.Clear(); logEntryService.Remove(toRemove); }, selectedItems.QueryWhenChanged(query => query.Count > 0)); var connected = selectedItems.Connect(); var connectedItems = shared.Connect(); _cleanUp = Disposable.Create(() => { loader.Dispose(); connected.Dispose(); _deleteItemsText.Dispose(); DeleteCommand.Dispose(); _selectionController.Dispose(); summariser.Dispose(); connectedItems.Dispose(); }); }
public LogEntryViewer(ILogEntryService logEntryService) { _logEntryService = logEntryService; //build an observable filter var filter = this.WhenAnyValue(x => x.SearchText) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(BuildFilter); //filter, sort and populate reactive list. var loader = logEntryService.Items.Connect() .Transform(le => new LogEntryProxy(le)) .DelayRemove(TimeSpan.FromSeconds(0.75), proxy =>proxy.FlagForRemove()) .Filter(filter) .Sort(SortExpressionComparer<LogEntryProxy>.Descending(le=>le.TimeStamp).ThenByDescending(l => l.Key),SortOptions.UseBinarySearch) .ObserveOn(RxApp.MainThreadScheduler) .Bind(_data) .DisposeMany() .Subscribe(); //aggregate total items var summariser = logEntryService.Items.Connect() .QueryWhenChanged(items => { var debug = items.Count(le => le.Level == LogLevel.Debug); var info = items.Count(le => le.Level == LogLevel.Info); var warn = items.Count(le => le.Level == LogLevel.Warning); var error = items.Count(le => le.Level == LogLevel.Error); return new LogEntrySummary(debug, info, warn, error); }) .Subscribe(s => Summary = s); //manage user selection, delete items command var selectedItems = _selectionController.SelectedItems.Connect().Publish(); //Build a message from selected items _deleteItemsText = selectedItems.QueryWhenChanged(query => { if (query.Count == 0) return "Select log entries to delete"; if (query.Count == 1) return "Delete selected log entry?"; return string.Format("Delete {0} log entries?", query.Count); }) .ToProperty(this, viewmodel => viewmodel.DeleteItemsText, "Select log entries to delete"); //make a command out of selected items - enabling the command when there is a selection _deleteCommand = selectedItems .QueryWhenChanged(query => query.Count > 0) .ToCommand(); //Assign action when the command is invoked var commandInvoker = this.WhenAnyObservable(x => x.DeleteCommand) .ObserveOn(RxApp.TaskpoolScheduler) .Subscribe(_ => { var toRemove = _selectionController.SelectedItems.Items.Select(proxy => proxy.Original).ToArray(); _selectionController.Clear(); _logEntryService.Remove(toRemove); }); var connected = selectedItems.Connect(); _cleanUp= Disposable.Create(() => { loader.Dispose(); connected.Dispose(); _deleteItemsText.Dispose(); _deleteCommand.Dispose(); commandInvoker.Dispose(); _selectionController.Dispose(); summariser.Dispose(); }); }
public LogEntryViewer(ILogEntryService logEntryService) { _logEntryService = logEntryService; //apply filter when search text has changed var filterApplier = this.WhenAnyValue(x => x.SearchText) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(BuildFilter) .Subscribe(_filter.Change); //filter, sort and populate reactive list. var loader = logEntryService.Items.Connect() .Transform(le => new LogEntryProxy(le)) .DelayRemove(TimeSpan.FromSeconds(0.75), proxy => { proxy.FlagForRemove(); _selectionController.DeSelect(proxy); }) .Filter(_filter) .Sort(SortExpressionComparer <LogEntryProxy> .Descending(le => le.TimeStamp).ThenByDescending(l => l.Key), SortOptimisations.ComparesImmutableValuesOnly) .ObserveOn(RxApp.MainThreadScheduler) .Bind(_data) .DisposeMany() .Subscribe(); //aggregate total items var summariser = logEntryService.Items.Connect() .QueryWhenChanged(query => { var items = query.Items.ToList(); var debug = items.Count(le => le.Level == LogLevel.Debug); var info = items.Count(le => le.Level == LogLevel.Info); var warn = items.Count(le => le.Level == LogLevel.Warning); var error = items.Count(le => le.Level == LogLevel.Error); return(new LogEntrySummary(debug, info, warn, error)); }) .Subscribe(s => Summary = s); //manage user selection, delete items command var selectedItems = _selectionController.SelectedItems.Connect().Publish(); //Build a message from selected items _deleteItemsText = selectedItems.QueryWhenChanged(query => { if (query.Count == 0) { return("Select log entries to delete"); } if (query.Count == 1) { return("Delete selected log entry?"); } return(string.Format("Delete {0} log entries?", query.Count)); }) .ToProperty(this, viewmodel => viewmodel.DeleteItemsText, "Select log entries to delete"); //make a command out of selected items - enabling the command when there is a selection _deleteCommand = selectedItems .QueryWhenChanged(query => query.Count > 0) .ToCommand(); //Assign action when the command is invoked var commandInvoker = this.WhenAnyObservable(x => x.DeleteCommand) .Subscribe(_ => { var toRemove = _selectionController.SelectedItems.Items.Select(proxy => proxy.Key).ToArray(); _logEntryService.Remove(toRemove); }); var connected = selectedItems.Connect(); _cleanUp = Disposable.Create(() => { loader.Dispose(); filterApplier.Dispose(); _filter.Dispose(); connected.Dispose(); _deleteItemsText.Dispose(); _deleteCommand.Dispose(); commandInvoker.Dispose(); _selectionController.Dispose(); summariser.Dispose(); }); }
public LogEntryViewer(ILogEntryService logEntryService) { _logEntryService = logEntryService; //apply filter when search text has changed var filterApplier = this.WhenAnyValue(x => x.SearchText) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(BuildFilter) .Subscribe(_filter.Change); //filter, sort and populate reactive list. var loader = logEntryService.Items.Connect(_filter) .Transform(le => new LogEntryProxy(le)) .Sort(SortExpressionComparer <LogEntryProxy> .Descending(l => l.Key), SortOptimisations.ComparesImmutableValuesOnly) .ObserveOn(RxApp.MainThreadScheduler) .Bind(_data) .DisposeMany() .Subscribe(); //aggregate total items var summariser = logEntryService.Items.Connect() .QueryWhenChanged(query => { var items = query.Items.ToList(); var debug = items.Count(le => le.Level == LogLevel.Debug); var info = items.Count(le => le.Level == LogLevel.Info); var warn = items.Count(le => le.Level == LogLevel.Warning); var error = items.Count(le => le.Level == LogLevel.Error); return(new LogEntrySummary(debug, info, warn, error)); }) .Subscribe(s => Summary = s); //manage user selection, delete items command var selectedItems = _selection.Selected.ToObservableChangeSet().Transform(obj => (LogEntryProxy)obj).Publish(); //Build a message from selected items var selectedMessage = selectedItems .QueryWhenChanged(query => string.Format("{0} items selected.", query.Count)) .StartWith("0 items selected") .Subscribe(text => RemoveText = text); //covert stream into a cache so we can get a handle on items in thread safe manner. var selectedCache = selectedItems.AsObservableCache(); //make a command out of selected items - enabling command when there is a selection _deleteCommand = selectedItems .QueryWhenChanged(query => query.Count > 0) .ToCommand(); //Assign action when the command is invoked var commandInvoker = this.WhenAnyObservable(x => x.RemoveCommand) .Subscribe(x => _logEntryService.Remove(selectedCache.Items.Select(proxy => proxy.Key))); var connected = selectedItems.Connect(); _cleanUp = Disposable.Create(() => { loader.Dispose(); filterApplier.Dispose(); _filter.Dispose(); connected.Dispose(); selectedMessage.Dispose(); selectedCache.Dispose(); _selection.Dispose(); commandInvoker.Dispose(); summariser.Dispose(); }); }