// Public methods.
 /// <summary>
 /// Opens the modal dialog to select a PlanetLab person.
 /// </summary>
 /// <param name="owner">The window owner.</param>
 /// <param name="username">The username of the selected account.</param>
 /// <returns>The dialog result.</returns>
 public DialogResult ShowDialog(IWin32Window owner, string username, PlList<PlPerson> persons)
 {
     // Reset the result.
     this.Result = null;
     // Refresh the results list.
     this.control.Refresh(username, persons);
     // Show the dialog.
     return base.ShowDialog(owner);
 }
        // Public methods.
        /// <summary>
        /// Refreshes the control with the specified list of PlanetLab persons.
        /// </summary>
        /// <param name="username">The account username.</param>
        /// <param name="persons">The persons list.</param>
        public void Refresh(string username, PlList<PlPerson> persons)
        {
            // Set the control default state.
            this.buttonSelect.Enabled = false;
            this.buttonProperties.Enabled = false;

            // Set the username.
            this.textBoxUsername.Text = username;

            // Clear the persons list.
            this.listView.Items.Clear();

            // Set the list of persons.
            persons.Lock();
            try
            {
                foreach (PlPerson person in persons)
                {
                    if (person.Id.HasValue)
                    {
                        ListViewItem item = new ListViewItem(new string[] {
                                person.Id.Value.ToString(),
                                person.FirstName,
                                person.LastName,
                                person.IsEnabled.HasValue ? person.IsEnabled.Value ? "Yes" : "No" : "Unknown",
                                person.Phone,
                                person.Email,
                                person.Url
                            });
                        item.ImageIndex = 0;
                        item.Tag = person;
                        this.listView.Items.Add(item);
                    }
                }
            }
            finally
            {
                persons.Unlock();
            }
        }
 /// <summary>
 /// Saves the current credentials.
 /// </summary>
 /// <param name="persons">The list of persons corresponding to the current credentials.</param>
 /// <param name="person">The selected person.</param>
 private void OnSaveCredentials(PlList<PlPerson> persons, PlPerson person)
 {
     // Save the credentials.
     this.crawler.PlanetLab.SaveCredentials(
         this.textBoxUsername.Text,
         this.textBoxPassword.SecureText,
         persons,
         person.Id ?? -1
         );
 }
Exemplo n.º 4
0
 /// <summary>
 /// Saves the PlanetLab credentials.
 /// </summary>
 /// <param name="username">The PlanetLab username.</param>
 /// <param name="password">The PlanetLab persons.</param>
 /// <param name="persons">The list of person accounts associated with the previous credentials.</param>
 /// <param name="person">The default person account ID.</param>
 public void SaveCredentials(string username, SecureString password, PlList<PlPerson> persons, int person)
 {
     // Save the username.
     DotNetApi.Windows.RegistryExtensions.SetString(this.root, "UserName", username);
     CrawlerConfig.Static.PlanetLabUsername = username;
     // Save the password.
     DotNetApi.Windows.RegistryExtensions.SetSecureString(this.root, "Password", password, ApplicationConfig.CryptoKey, ApplicationConfig.CryptoIV);
     CrawlerConfig.Static.PlanetLabPassword = password;
     // Save the persons.
     persons.Lock();
     try { this.LocalPersons.CopyFrom(persons); }
     finally { persons.Unlock(); }
     try { this.LocalPersons.SaveToFile(this.LocalPersonsFileName); }
     catch { }
     // Save the person.
     DotNetApi.Windows.RegistryExtensions.SetInteger(this.root, "PersonId", person);
     CrawlerConfig.Static.PlanetLabPersonId = person;
 }
        /// <summary>
        /// A method called when completing a PlanetLab request.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="state">The request state.</param>
        protected override void OnRequestResult(XmlRpcResponse response, RequestState state)
        {
            // Enable the validation button.
            this.OnChanged(this, EventArgs.Empty);
            // If the request has not failed.
            if ((null == response.Fault) && (null != response.Value))
            {
                try
                {
                    // Create a new persons list.
                    PlList<PlPerson> persons = new PlList<PlPerson>();
                    // Get the list of PlanetLab persons for the given response.
                    persons.Update(response.Value as XmlRpcArray);

                    // Check the number of persons returned in the response.
                    if (persons.Count == 1)
                    {
                        // If the number of persons is one, set it as the current person.
                        this.OnSetPerson(persons[0]);
                        // Save the credentials.
                        this.OnSaveCredentials(persons, persons[0]);
                    }
                    else if (persons.Count > 1)
                    {
                        // Show the select person dialog.
                        if (this.formSelectPerson.ShowDialog(this, this.textBoxUsername.Text, persons) == DialogResult.OK)
                        {
                            // Set the selected person as the current person.
                            this.OnSetPerson(this.formSelectPerson.Result);
                            // Save the credentials.
                            this.OnSaveCredentials(persons, this.formSelectPerson.Result);
                        }
                        else
                        {
                            // If a list was not selected, clear the selection.
                            this.OnSetPerson(UserState.NotSelected);
                        }
                    }
                    else
                    {
                        // If no results were returned, clear the selection.
                        this.OnSetPerson(UserState.Failed);
                    }
                }
                catch
                {
                    // If an error ocurred, clear the selection.
                    this.OnSetPerson(UserState.Failed);
                }
            }
            // Call the base class method.
            base.OnRequestResult(response, state);
        }