private void AttemptToLoginAsync()
        {
            this.Focus();

            if (!ValidateUserName())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUserName, usernameTextBox);
                return;
            }

            if (!ValidatePassword())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingPassword, passwordPasswordBox);
                return;
            }
            string username = usernameTextBox.Text;
            string password = passwordPasswordBox.Password;
            string url      = Constants.WORDPRESS_XMLRPC_URL;

            rpc            = new GetUsersBlogsRPC(url, username, password);
            rpc.Completed += OnGetUsersBlogsCompleted;
            rpc.ExecuteAsync();

            ApplicationBar.IsVisible = false;
            App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.LoggingIn);
        }
コード例 #2
0
        private void AttemptToLoginAsync()
        {
            this.Focus();

            if (!ValidateUrl(urlTextBox.Text))
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox);
                return;
            }

            if (!ValidateUserName())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUserName, usernameTextBox);
                return;
            }

            if (!ValidatePassword())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingPassword, passwordPasswordBox);
                return;
            }

            string username = usernameTextBox.Text;
            string password = passwordPasswordBox.Password;

            string url = urlTextBox.Text.Trim();

            if (url.EndsWith("/"))
            {
                url = url.Substring(0, url.Length - 1);                    //remove the trailing slash
            }
            if (url.EndsWith("/wp-admin"))
            {
                url = url.Replace("/wp-admin", "");
            }
            if (!url.EndsWith("/xmlrpc.php"))
            {
                url = url + "/xmlrpc.php";
            }

            this.DebugLog("XML-RPC URL: " + url);

            if (!ValidateUrl(url))
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox);
                return;
            }

            rpc            = new GetUsersBlogsRPC(url, username, password);
            rpc.Completed += OnGetUsersBlogsCompleted;
            rpc.ExecuteAsync();

            useRecoveryFunctions     = true;
            ApplicationBar.IsVisible = false; //hide the application bar
            App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.LoggingIn);
        }
        private void OnGetUsersBlogsCompleted(object sender, XMLRPCCompletedEventArgs <Blog> args)
        {
            GetUsersBlogsRPC rpc = sender as GetUsersBlogsRPC;

            rpc.Completed           -= OnGetUsersBlogsCompleted;
            ApplicationBar.IsVisible = true;
            App.WaitIndicationService.KillSpinner();

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                if (1 == args.Items.Count)
                {
                    if (!(DataService.Current.Blogs.Any(b => b.Xmlrpc == args.Items[0].Xmlrpc)))
                    {
                        DataService.Current.AddBlogToStore(args.Items[0]);
                        PushNotificationsHelper.Instance.sendBlogsList();
                    }
                    NavigationService.Navigate(new Uri("/BlogsPage.xaml", UriKind.Relative));
                }
                else
                {
                    ShowBlogSelectionControl(args.Items);
                }
            }
            else
            {
                Exception currentException = args.Error;
                if (currentException is XmlRPCException && (currentException as XmlRPCException).FaultCode == 403) //username or password error
                {
                    UIThread.Invoke(() =>
                    {
                        MessageBox.Show(_localizedStrings.Prompts.UsernameOrPasswordError);
                    });
                }
                else
                {
                    this.HandleException(args.Error);
                }
            }
        }
        private void AttemptToLoginAsync()
        {
            this.Focus();

            if (!ValidateUserName())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUserName, usernameTextBox);
                return;
            }

            if (!ValidatePassword())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingPassword, passwordPasswordBox);
                return;
            }
            string username = usernameTextBox.Text;
            string password = passwordPasswordBox.Password;
            string url = Constants.WORDPRESS_XMLRPC_URL;

            rpc = new GetUsersBlogsRPC(url, username, password);
            rpc.Completed += OnGetUsersBlogsCompleted;
            rpc.ExecuteAsync();

            ApplicationBar.IsVisible = false;
            App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.LoggingIn);
        }
        private void AttemptToLoginAsync()
        {
            this.Focus();

            if (!ValidateUrl(urlTextBox.Text))
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox);
                return;
            }

            if (!ValidateUserName())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUserName, usernameTextBox);
                return;
            }

            if (!ValidatePassword())
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingPassword, passwordPasswordBox);
                return;
            }

            string username = usernameTextBox.Text;
            string password = passwordPasswordBox.Password;
                             
            string url = urlTextBox.Text.Trim();
            if (url.EndsWith("/")) url = url.Substring(0, url.Length - 1); //remove the trailing slash
            if (url.EndsWith("/wp-admin")) url = url.Replace("/wp-admin", "");
            if (!url.EndsWith("/xmlrpc.php")) url = url + "/xmlrpc.php";

            this.DebugLog("XML-RPC URL: " + url);

            if (!ValidateUrl(url))
            {
                PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox);
                return;
            }

            rpc = new GetUsersBlogsRPC(url, username, password);
            rpc.Completed += OnGetUsersBlogsCompleted;
            rpc.ExecuteAsync();

            useRecoveryFunctions = true;
            ApplicationBar.IsVisible = false; //hide the application bar 
            App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.LoggingIn);
        }
        void downloadRSDdocumentCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            rsdWebClient.DownloadStringCompleted -= downloadRSDdocumentCompleted;

            string apiLink = null;
            
            if (e.Error == null)
            {
                try
                {
                    string rsdDocumentString = e.Result;
                    //clean the junk b4 the xml preamble.
                    if (!rsdDocumentString.StartsWith("<?xml"))
                    {
                        //clean the junk b4 the xml preamble
                        this.DebugLog("cleaning the junk before the xml preamble");
                        int indexOfFirstLt = rsdDocumentString.IndexOf("<?xml");
                        if (indexOfFirstLt > -1)
                            rsdDocumentString = rsdDocumentString.Substring(indexOfFirstLt);
                    }
                    
                    try
                    {
                        XDocument xDoc = XDocument.Parse(rsdDocumentString, LoadOptions.None);
                        foreach (XElement apiElement in xDoc.Descendants())
                        {
                            if (apiElement.Name.LocalName == "api")
                                if (apiElement.Attribute("name").Value == "WordPress")
                                {
                                    apiLink = apiElement.Attribute("apiLink").Value;
                                }
                        }
                    }
                    catch (Exception) { }

                    if (apiLink == null || !ValidateUrl(apiLink))
                    {
                        apiLink = null;
                        //try to use RegExp
                        String pattern = @"<api\s*?name=\""WordPress\"".*?apiLink=\""(.*?)\""";
                        Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                        if (regex.IsMatch(rsdDocumentString))
                        {
                            Match firstMatch = regex.Match(rsdDocumentString);
                            rsdDocumentString = rsdDocumentString.Substring(firstMatch.Index, firstMatch.Length);
                            rsdDocumentString = rsdDocumentString.Substring(rsdDocumentString.IndexOf("apiLink=\""));
                            rsdDocumentString = rsdDocumentString.Replace("apiLink=\"", "");
                            rsdDocumentString = rsdDocumentString.Substring(0, rsdDocumentString.IndexOf("\""));

                            if (ValidateUrl(rsdDocumentString))
                                apiLink = rsdDocumentString;
                        }
                    }
                }
                catch (Exception) { }
            }

            if (apiLink != null)
            {
                //restart getUserBlogs with this URL
                string username = usernameTextBox.Text;
                string password = passwordPasswordBox.Password;
                rpc = new GetUsersBlogsRPC(apiLink, username, password);
                rpc.Completed += OnGetUsersBlogsCompleted;
                rpc.ExecuteAsync();
            }
            else
                this.showErrorMsgOnRecovery(null); //No match or error. Show "no WP site found at this URL..."
        }
コード例 #7
0
        void downloadRSDdocumentCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            rsdWebClient.DownloadStringCompleted -= downloadRSDdocumentCompleted;

            string apiLink = null;

            if (e.Error == null)
            {
                try
                {
                    string rsdDocumentString = e.Result;
                    //clean the junk b4 the xml preamble.
                    if (!rsdDocumentString.StartsWith("<?xml"))
                    {
                        //clean the junk b4 the xml preamble
                        this.DebugLog("cleaning the junk before the xml preamble");
                        int indexOfFirstLt = rsdDocumentString.IndexOf("<?xml");
                        if (indexOfFirstLt > -1)
                        {
                            rsdDocumentString = rsdDocumentString.Substring(indexOfFirstLt);
                        }
                    }

                    try
                    {
                        XDocument xDoc = XDocument.Parse(rsdDocumentString, LoadOptions.None);
                        foreach (XElement apiElement in xDoc.Descendants())
                        {
                            if (apiElement.Name.LocalName == "api")
                            {
                                if (apiElement.Attribute("name").Value == "WordPress")
                                {
                                    apiLink = apiElement.Attribute("apiLink").Value;
                                }
                            }
                        }
                    }
                    catch (Exception) { }

                    if (apiLink == null || !ValidateUrl(apiLink))
                    {
                        apiLink = null;
                        //try to use RegExp
                        String pattern = @"<api\s*?name=\""WordPress\"".*?apiLink=\""(.*?)\""";
                        Regex  regex   = new Regex(pattern, RegexOptions.IgnoreCase);
                        if (regex.IsMatch(rsdDocumentString))
                        {
                            Match firstMatch = regex.Match(rsdDocumentString);
                            rsdDocumentString = rsdDocumentString.Substring(firstMatch.Index, firstMatch.Length);
                            rsdDocumentString = rsdDocumentString.Substring(rsdDocumentString.IndexOf("apiLink=\""));
                            rsdDocumentString = rsdDocumentString.Replace("apiLink=\"", "");
                            rsdDocumentString = rsdDocumentString.Substring(0, rsdDocumentString.IndexOf("\""));

                            if (ValidateUrl(rsdDocumentString))
                            {
                                apiLink = rsdDocumentString;
                            }
                        }
                    }
                }
                catch (Exception) { }
            }

            if (apiLink != null)
            {
                //restart getUserBlogs with this URL
                string username = usernameTextBox.Text;
                string password = passwordPasswordBox.Password;
                rpc            = new GetUsersBlogsRPC(apiLink, username, password);
                rpc.Completed += OnGetUsersBlogsCompleted;
                rpc.ExecuteAsync();
            }
            else
            {
                this.showErrorMsgOnRecovery(null); //No match or error. Show "no WP site found at this URL..."
            }
        }
コード例 #8
0
        private void OnGetUsersBlogsCompleted(object sender, XMLRPCCompletedEventArgs <Blog> args)
        {
            GetUsersBlogsRPC rpc = sender as GetUsersBlogsRPC;

            rpc.Completed -= OnGetUsersBlogsCompleted;

            if (args.Cancelled)
            {
            }
            else if (null == args.Error)
            {
                App.WaitIndicationService.KillSpinner();
                ApplicationBar.IsVisible = true;

                if (0 == args.Items.Count)
                {
                    this.HandleException(null, _localizedStrings.PageTitles.CheckTheUrl, string.Format(_localizedStrings.Messages.NoBlogsFoundAtThisURL, rpc.Url));
                }
                else if (1 == args.Items.Count)
                {
                    if (!(DataService.Current.Blogs.Any(b => b.Xmlrpc == args.Items[0].Xmlrpc)))
                    {
                        DataService.Current.AddBlogToStore(args.Items[0]);
                        PushNotificationsHelper.Instance.sendBlogsList();
                    }
                    NavigationService.Navigate(new Uri("/BlogsPage.xaml", UriKind.Relative));
                }
                else
                {
                    ShowBlogSelectionControl(args.Items);
                }
            }
            else
            {
                if (useRecoveryFunctions && !(args.Error is WordPress.Model.NoConnectionException) && !(args.Error is XmlRPCException)) //do not use the recovery function if the connection is not available
                {
                    useRecoveryFunctions = false;                                                                                       //set this to false, since the recovery functions will be used only once.
                    startRecoveryfunctions();
                }
                else
                {
                    App.WaitIndicationService.KillSpinner();
                    ApplicationBar.IsVisible = true;
                    Exception currentException = args.Error;
                    if (currentException is NotSupportedException || currentException is XmlRPCParserException || currentException is ArgumentNullException)
                    {
                        this.HandleException(currentException, _localizedStrings.PageTitles.CheckTheUrl, _localizedStrings.Messages.CheckTheUrl);
                        UIThread.Invoke(() =>
                        {
                            urlTextBox.Focus();
                        });
                        return;
                    }
                    else if (currentException is XmlRPCException && (currentException as XmlRPCException).FaultCode == 403) //username or password error
                    {
                        UIThread.Invoke(() =>
                        {
                            MessageBox.Show(_localizedStrings.Prompts.UsernameOrPasswordError);
                        });
                    }
                    else
                    {
                        this.HandleException(args.Error);
                    }
                }
            }
        }