protected override void OnActivate() { base.OnActivate(); _proxyConfig = _transportService.GetProxyConfig() as TLProxyConfig76; if (_proxyConfig != null) { _isEnabled = _proxyConfig.IsEnabled.Value; _useForCalls = _proxyConfig.UseForCalls.Value; var now = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now); Items.Clear(); for (var i = 0; i < _proxyConfig.Items.Count; i++) { var item = _proxyConfig.Items[i]; item.IsSelected = i == _proxyConfig.SelectedIndex.Value; Items.Add(item); if (CheckProxy(item)) { item.Status = ProxyStatus.Connecting; item.Ping = null; _proxyChecker.CheckAsync(item, 10.0, (proxyItem, ping) => Execute.BeginOnUIThread(() => { proxyItem.Proxy.CheckTime = now; proxyItem.Proxy.Ping = ping; proxyItem.Proxy.Status = item.Ping != null ? ProxyStatus.Available : ProxyStatus.Unavailable; Set(_proxyConfig); })); } } } _transportService.TransportConnected += OnTransportConnected; _transportService.TransportConnecting += OnTransportConnecting; }
public void Done() { var proxyConfig = _transportService.GetProxyConfig() as TLProxyConfig76 ?? TLProxyConfigBase.Empty as TLProxyConfig76; if (proxyConfig == null) { return; } if (!IsDoneEnabled) { return; } if (IsSocks5Proxy) { TLSocks5Proxy proxy = null; // new proxy if (_proxy == null) { proxy = new TLSocks5Proxy { CustomFlags = new TLLong(0) }; proxy.Server = new TLString(Server); var port = 0; proxy.Port = int.TryParse(Port, out port) ? new TLInt(port) : new TLInt(0); proxy.Username = new TLString(Username); proxy.Password = new TLString(Password); _proxy = proxy; proxyConfig.Items.Add(_proxy); proxyConfig.SelectedIndex = new TLInt(proxyConfig.Items.IndexOf(_proxy)); proxyConfig.IsEnabled = TLBool.True; _transportService.SetProxyConfig(proxyConfig); _transportService.Close(); MTProtoService.PingAsync(TLLong.Random(), result => { }); EventAggregator.Publish(new ProxyChangedEventArgs(proxyConfig)); NavigationService.GoBack(); return; } proxy = _proxy as TLSocks5Proxy; // change type if (proxy == null) { proxy = new TLSocks5Proxy { CustomFlags = new TLLong(0) }; proxy.Server = new TLString(Server); var port = 0; proxy.Port = int.TryParse(Port, out port) ? new TLInt(port) : new TLInt(0); proxy.Username = new TLString(Username); proxy.Password = new TLString(Password); _proxy = proxy; proxyConfig.Items.Add(_proxy); proxyConfig.SelectedIndex = new TLInt(proxyConfig.Items.IndexOf(_proxy)); _transportService.SetProxyConfig(proxyConfig); _transportService.Close(); MTProtoService.PingAsync(TLLong.Random(), result => { }); EventAggregator.Publish(new ProxyChangedEventArgs(proxyConfig)); NavigationService.GoBack(); return; } // same type else { proxy.Server = new TLString(Server); var port = 0; proxy.Port = int.TryParse(Port, out port) ? new TLInt(port) : new TLInt(0); proxy.Username = new TLString(Username); proxy.Password = new TLString(Password); _proxy = proxy; if (proxyConfig.SelectedIndex.Value == proxyConfig.Items.IndexOf(_proxy)) { _transportService.SetProxyConfig(proxyConfig); _transportService.Close(); MTProtoService.PingAsync(TLLong.Random(), result => { }); } EventAggregator.Publish(new ProxyChangedEventArgs(proxyConfig)); NavigationService.GoBack(); return; } } else { TLMTProtoProxy proxy = null; // new proxy if (_proxy == null) { proxy = new TLMTProtoProxy { CustomFlags = new TLLong(0) }; proxy.Server = new TLString(Server); var port = 0; proxy.Port = int.TryParse(Port, out port) ? new TLInt(port) : new TLInt(0); proxy.Secret = new TLString(Secret); _proxy = proxy; proxyConfig.Items.Add(_proxy); proxyConfig.SelectedIndex = new TLInt(proxyConfig.Items.IndexOf(_proxy)); proxyConfig.IsEnabled = TLBool.True; _transportService.SetProxyConfig(proxyConfig); _transportService.Close(); MTProtoService.PingAsync(TLLong.Random(), result => { }); EventAggregator.Publish(new ProxyChangedEventArgs(proxyConfig)); NavigationService.GoBack(); return; } proxy = _proxy as TLMTProtoProxy; // change type if (proxy == null) { proxy = new TLMTProtoProxy { CustomFlags = new TLLong(0) }; proxy.Server = new TLString(Server); var port = 0; proxy.Port = int.TryParse(Port, out port) ? new TLInt(port) : new TLInt(0); proxy.Secret = new TLString(Secret); _proxy = proxy; proxyConfig.Items.Add(_proxy); proxyConfig.SelectedIndex = new TLInt(proxyConfig.Items.IndexOf(_proxy)); _transportService.SetProxyConfig(proxyConfig); _transportService.Close(); MTProtoService.PingAsync(TLLong.Random(), result => { }); EventAggregator.Publish(new ProxyChangedEventArgs(proxyConfig)); NavigationService.GoBack(); return; } // same type else { proxy.Server = new TLString(Server); var port = 0; proxy.Port = int.TryParse(Port, out port) ? new TLInt(port) : new TLInt(0); proxy.Secret = new TLString(Secret); _proxy = proxy; if (proxyConfig.SelectedIndex.Value == proxyConfig.Items.IndexOf(_proxy)) { _transportService.SetProxyConfig(proxyConfig); _transportService.Close(); MTProtoService.PingAsync(TLLong.Random(), result => { }); } EventAggregator.Publish(new ProxyChangedEventArgs(proxyConfig)); NavigationService.GoBack(); return; } } }
public SettingsViewModel(ITransportService transportService, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { eventAggregator.Subscribe(this); TransportService = transportService; SuppressUpdateStatus = true; //tombstoning if (stateService.CurrentContact == null) { ShellViewModel.Navigate(NavigationService); return; } UpdateProxySubtitle(TransportService.GetProxyConfig()); CurrentItem = stateService.CurrentContact; stateService.CurrentContact = null; _allStickers = StateService.GetAllStickers() as TLAllStickers29; _masks = StateService.GetMasks() as TLAllStickers29; _featuredStickers = StateService.GetFeaturedStickers(); if (_featuredStickers != null) { UpdateSets(_featuredStickers, _featuredStickers.Unread); } UpdateStickersSubtitle(_featuredStickers, _allStickers, _masks); StateService.GetNotifySettingsAsync( settings => { _saveIncomingPhotos = settings.SaveIncomingPhotos; _invisibleMode = settings.InvisibleMode; #if DISABLE_INVISIBLEMODE _invisibleMode = false; #endif BeginOnUIThread(() => { NotifyOfPropertyChange(() => SaveIncomingPhotos); NotifyOfPropertyChange(() => InvisibleMode); }); }); if (CurrentItem == null || CurrentItem.NotifySettings == null) { BeginOnThreadPool(() => { MTProtoService.GetFullUserAsync(new TLInputUserSelf(), userFull => { CurrentItem = userFull.User; BeginOnUIThread(() => { var user = CurrentItem as TLUser66; if (user != null) { user.NotifyOfPropertyChange(() => user.About); } }); }); }); } }