private async void Proxy_Click(object sender, RoutedEventArgs e) { var dialog = new ProxyView(); dialog.Server = SettingsHelper.ProxyServer; dialog.Port = SettingsHelper.ProxyPort.ToString(); dialog.Username = SettingsHelper.ProxyUsername; dialog.Password = SettingsHelper.ProxyPassword; dialog.IsProxyEnabled = SettingsHelper.IsProxyEnabled; dialog.IsCallsProxyEnabled = SettingsHelper.IsCallsProxyEnabled; var enabled = SettingsHelper.IsProxyEnabled == true; var confirm = await dialog.ShowQueuedAsync(); if (confirm == ContentDialogResult.Primary) { SettingsHelper.ProxyServer = dialog.Server; SettingsHelper.ProxyPort = int.Parse(dialog.Port ?? "1080"); SettingsHelper.ProxyUsername = dialog.Username; SettingsHelper.ProxyPassword = dialog.Password; SettingsHelper.IsProxyEnabled = dialog.IsProxyEnabled; SettingsHelper.IsCallsProxyEnabled = dialog.IsCallsProxyEnabled; if (SettingsHelper.IsProxyEnabled || SettingsHelper.IsProxyEnabled != enabled) { UnigramContainer.Current.ResolveType <ITransportService>().Close(); UnigramContainer.Current.ResolveType <IMTProtoService>().PingAsync(TLLong.Random(), null); } } }
private async void ProxyExecute() { var dialog = new ProxyView(); dialog.Server = SettingsHelper.ProxyServer; dialog.Port = SettingsHelper.ProxyPort.ToString(); dialog.Username = SettingsHelper.ProxyUsername; dialog.Password = SettingsHelper.ProxyPassword; dialog.IsProxyEnabled = SettingsHelper.IsProxyEnabled; dialog.IsCallsProxyEnabled = SettingsHelper.IsCallsProxyEnabled; var enabled = SettingsHelper.IsProxyEnabled == true; var confirm = await dialog.ShowQueuedAsync(); if (confirm == ContentDialogResult.Primary) { SettingsHelper.ProxyServer = dialog.Server; SettingsHelper.ProxyPort = Extensions.TryParseOrDefault(dialog.Port, 1080); SettingsHelper.ProxyUsername = dialog.Username; SettingsHelper.ProxyPassword = dialog.Password; SettingsHelper.IsProxyEnabled = dialog.IsProxyEnabled; SettingsHelper.IsCallsProxyEnabled = dialog.IsCallsProxyEnabled; if (SettingsHelper.IsProxyEnabled || SettingsHelper.IsProxyEnabled != enabled) { UnigramContainer.Current.ResolveType <IMTProtoService>().ToggleProxy(); } } }
private async void AddExecute() { var dialog = new ProxyView(); var confirm = await dialog.ShowQueuedAsync(); if (confirm != ContentDialogResult.Primary) { return; } var response = await ProtoService.SendAsync(new AddProxy(dialog.Server, dialog.Port, false, dialog.Type)); if (response is Proxy proxy) { Items.Add(new ProxyViewModel(proxy)); } }
private async void ProxyExecute() { var proxy = ApplicationSettings.Current.Proxy; var dialog = new ProxyView(true); dialog.Server = proxy.Server; dialog.Port = proxy.Port.ToString(); dialog.Username = proxy.Username; dialog.Password = proxy.Password; dialog.IsProxyEnabled = proxy.IsEnabled; dialog.IsCallsProxyEnabled = proxy.IsCallsEnabled; var enabled = proxy.IsEnabled == true; var confirm = await dialog.ShowQueuedAsync(); if (confirm == ContentDialogResult.Primary) { var server = proxy.Server = dialog.Server ?? string.Empty; var port = proxy.Port = Extensions.TryParseOrDefault(dialog.Port, 1080); var username = proxy.Username = dialog.Username ?? string.Empty; var password = proxy.Password = dialog.Password ?? string.Empty; var newValue = proxy.IsEnabled = dialog.IsProxyEnabled; proxy.IsCallsEnabled = dialog.IsCallsProxyEnabled; if (newValue || newValue != enabled) { if (newValue) { ProtoService.Send(new SetProxy(new ProxySocks5(server, port, username, password))); } else { ProtoService.Send(new SetProxy(new ProxyEmpty())); } } } }
private async void EditExecute(ConnectionViewModel connection) { var dialog = new ProxyView(connection as ProxyViewModel); var confirm = await dialog.ShowQueuedAsync(); if (confirm != ContentDialogResult.Primary) { return; } var response = await ProtoService.SendAsync(new EditProxy(connection.Id, dialog.Server, dialog.Port, false, dialog.Type)); if (response is Proxy proxy) { var index = Items.IndexOf(connection); Items.Remove(connection); var edited = new ProxyViewModel(proxy); Items.Insert(index, edited); await UpdateAsync(edited); } Handle(ProtoService.GetConnectionState()); }