private static IObservable <ProxyModel> AddProxy( this ProxyPopupContext context, IProxyManager proxyManager) { var proxy = new TdApi.Proxy { Server = null, Port = 0, Type = new TdApi.ProxyType.ProxyTypeSocks5 { Username = null, Password = null } }; var proxyModel = ProxyModel.FromProxy(proxy); return(Observable.Return(proxyModel)); }
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; } })); }