Ejemplo n.º 1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Find" <see cref="Button"/>.
        /// </summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnMapiFind</b> invokes <see cref="MapiMail.ResolveName"/> to retrieve the Simple MAPI
        /// address book data for the player name shown in the "Name" text box.
        /// </para><para>
        /// On success, <b>OnMapiFind</b> sets the name and e-mail address of the selected <see
        /// cref="HumanPlayer"/> to the retrieved name and e-mail address, and sets the <see
        /// cref="DataChanged"/> flag if any data was changed.
        /// </para><para>
        /// <b>OnMapiFind</b> shows an error message if <see cref="MapiMail.ResolveName"/> fails,
        /// and returns silently if the user cancelled any dialog that was shown.</para></remarks>

        private void OnMapiFind(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected human player, if any
            HumanPlayer human = SelectedHumanPlayer;

            if (human == null)
            {
                return;
            }

            // do nothing if name is empty
            if (NameBox.Text.Length == 0)
            {
                return;
            }

            MapiAddress resolved;

            try {
                // ask Simple MAPI to resolve player name
                resolved = MapiMail.ResolveName(NameBox.Text);
            }
            catch (MapiException e) {
                // show error message unless user cancelled
                if (e.Code != MapiException.Abort)
                {
                    MessageDialog.Show(this,
                                       Global.Strings.DialogMailErrorMapi, Global.Strings.TitleMailErrorMapi,
                                       e, MessageBoxButton.OK, Images.Warning);
                }
                return;
            }

            // check for broken MAPI client
            if (!resolved.Address.IsValidEmail())
            {
                MessageBox.Show(this,
                                Global.Strings.DialogMailInvalidMapi, Global.Strings.TitleMailInvalid,
                                MessageBoxButton.OK, MessageBoxImage.Information);

                resolved = new MapiAddress(resolved.Name, "");
            }

            // broadcast data changes, if any
            if (human.Name != resolved.Name || human.Email != resolved.Address)
            {
                NameBox.Text = human.Name = resolved.Name;
                human.Email  = resolved.Address;
                UpdatePlayers();
            }
        }
Ejemplo n.º 2
0
 private void OnResolveName(object sender, RoutedEventArgs args)
 {
     args.Handled = true;
     try {
         MapiAddress recip = MapiMail.ResolveName(AddressBox.Text);
         AddressBox.Text = StringUtility.Validate(recip.Address, recip.Name);
     }
     catch (MapiException e) {
         MessageBox.Show(this, e.Message, "Simple MAPI Error",
                         MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }