/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Browse Address Book" <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>OnMapiBrowse</b> invokes <see cref="MapiMail.Address"/> to show the Simple MAPI /// address book, allowing the user to select one or more "To" recipients as players. /// </para><para> /// On success, <b>OnMapiBrowse</b> sets the name and e-mail address of the selected <see /// cref="HumanPlayer"/> to the corresponding values of the first selected recipient, and /// sets the <see cref="DataChanged"/> flag if any data was changed. /// </para><para> /// <b>OnMapiBrowse</b> shows an error message if <see cref="MapiMail.Address"/> fails, and /// returns silently if the user cancelled the dialog.</para></remarks> private void OnMapiBrowse(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected human player, if any HumanPlayer human = SelectedHumanPlayer; if (human == null) { return; } MapiAddress[] entries = null; try { // let user select recipients entries = MapiMail.Address(); } 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; } // quit if no recipients selected if (entries == null || entries.Length == 0) { return; } // check for broken MAPI client if (!entries[0].Address.IsValidEmail()) { MessageBox.Show(this, Global.Strings.DialogMailInvalidMapi, Global.Strings.TitleMailInvalid, MessageBoxButton.OK, MessageBoxImage.Information); entries[0] = new MapiAddress(entries[0].Name, ""); } // broadcast data changes, if any if (human.Name != entries[0].Name || human.Email != entries[0].Address) { NameBox.Text = human.Name = entries[0].Name; human.Email = entries[0].Address; UpdatePlayers(); } }
private void OnAddressBook(object sender, RoutedEventArgs args) { args.Handled = true; try { MapiAddress[] recips = MapiMail.Address(); if (recips.Length > 0) { AddressBox.Text = StringUtility.Validate(recips[0].Address, recips[0].Name); } } catch (MapiException e) { MessageBox.Show(this, e.Message, "Simple MAPI Error", MessageBoxButton.OK, MessageBoxImage.Error); } }