using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfVkontacteClient { /// /// Interaction logic for LoginWindow.xaml /// public partial class LoginWindow : Window { private string _sessionData; /// /// Данные сессии /// public string SessionData { get { return _sessionData; } } public LoginWindow(long appId, int settings) { InitializeComponent(); Uri uri = new Uri(String.Format("http://vkontakte.ru/login.php?app={0}&layout=popup&type=browser&settings={1}", appId, settings), UriKind.Absolute); webBrowser.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(webBrowser_Navigated); webBrowser.Navigate(uri); } void webBrowser_Navigated(object sender, System.Windows.Forms.WebBrowserNavigatedEventArgs e) { bool error = false; Uri new_page = e.Url; if (new_page.AbsolutePath.IndexOf("/api/login_success.html") != -1) { try { _sessionData = Uri.UnescapeDataString(new_page.Fragment.Split("=".ToCharArray())[1]); } catch (IndexOutOfRangeException) { error = true; MessageBox.Show("Login error", "Error occured in login", MessageBoxButton.OK, MessageBoxImage.Error); } this.DialogResult = error == true ? false : true; this.Close(); } else if (new_page.AbsolutePath.IndexOf("/api/login_failure.html") != -1) { this.DialogResult = false; this.Close(); } } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { GC.Collect(1, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); } } }