本文整理汇总了C#中ReactiveCommand.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveCommand.Dispose方法的具体用法?C# ReactiveCommand.Dispose怎么用?C# ReactiveCommand.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveCommand
的用法示例。
在下文中一共展示了ReactiveCommand.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReactiveCommandAllFlow
public void ReactiveCommandAllFlow()
{
var testScheduler = new TestScheduler();
var @null = (object)null;
var recorder1 = testScheduler.CreateObserver<object>();
var recorder2 = testScheduler.CreateObserver<object>();
var cmd = new ReactiveCommand();
cmd.Subscribe(recorder1);
cmd.Subscribe(recorder2);
cmd.CanExecute().Is(true);
cmd.Execute(); testScheduler.AdvanceBy(10);
cmd.Execute(); testScheduler.AdvanceBy(10);
cmd.Execute(); testScheduler.AdvanceBy(10);
cmd.Dispose();
cmd.CanExecute().Is(false);
cmd.Dispose(); // dispose again
recorder1.Messages.Is(
OnNext(0, @null),
OnNext(10, @null),
OnNext(20, @null),
OnCompleted<object>(30));
recorder2.Messages.Is(
OnNext(0, @null),
OnNext(10, @null),
OnNext(20, @null),
OnCompleted<object>(30));
}
示例2: LogEntryViewer
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();
});
}