private IDisposable BindProxies(IProxyManager proxyManager) { return(proxyManager.GetAllProxies() .SubscribeOn(TaskPoolScheduler.Default) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(proxies => { var models = proxies.Select(ProxyModel.FromProxy); Model.Proxies = new ObservableCollectionExtended <ProxyModel>(models); })); }
private void LoadProxies(IProxyManager proxyManager) { proxyManager.GetAllProxies() .SubscribeOn(TaskPoolScheduler.Default) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(proxies => { var models = proxies.Select(ProxyModel.FromProxy); Proxies = new List <ProxyModel>(models); }) .DisposeWith(_modelDisposable); }
private static IDisposable BindList( this ProxyPopupContext context, IProxyManager proxyManager) { return(proxyManager.GetAllProxies() .SubscribeOn(RxApp.TaskpoolScheduler) .ObserveOn(RxApp.MainThreadScheduler) .Accept(proxies => { var disabledProxy = ProxyModel.DisabledProxy(); disabledProxy.EnableCommand = context.EnableProxyCommand; var otherProxies = Enumerable.Select <TdApi.Proxy, ProxyModel>(proxies, p => { var proxyModel = ProxyModel.FromProxy(p); proxyModel.RemoveCommand = context.RemoveProxyCommand; proxyModel.EnableCommand = context.EnableProxyCommand; return proxyModel; }) .ToList(); context.Proxies = new ObservableCollectionExtended <ProxyModel>(); context.Proxies.Add(disabledProxy); context.Proxies.AddRange(otherProxies); if (context.SelectedProxy == null) { context.SelectedProxy = otherProxies.FirstOrDefault(p => p.IsEnabled) ?? disabledProxy; } if (!Enumerable.Any <TdApi.Proxy>(proxies, p => p.IsEnabled)) { disabledProxy.IsEnabled = true; } })); }