Share via


Making a Balance Inquiry

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

To make a balance inquiry, select a user in the CurrentUser drop-down list, and then click Balance Inquiry. The current balance appears in the Balance text box in the main QuickStart window, as shown in Figure 1.

Ff649577.e41b5688-f230-49ba-9b85-15acbaaaf30e(en-us,PandP.10).png

Figure 1
Making a balance inquiry in the Policy Injection QuickStart

The following extract shows the code that runs when you click the Balance Inquiry button. It clears any existing text from the Exception text box in the main form, calls the GetCurrentBalance method of the BankAccount class, and places the return value into the Balance text box. If an error occurs, the code places the message into the Exception text box.

private void balanceInquiryButton_Click(object sender, EventArgs e)
{
  exceptionTextBox.Text = String.Empty;
  try
  {
    balanceTextBox.Text = bankAccount.GetCurrentBalance().ToString();
  }
  catch (Exception ex)
  {
    exceptionTextBox.Text = ex.Message;
  }
}
'Usage
Private Sub balanceInquiryButton_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles balanceInquiryButton.Click
  exceptionTextBox.Text = String.Empty
  Try
    balanceTextBox.Text = bankAccount.GetCurrentBalance().ToString()
  Catch ex As Exception
    exceptionTextBox.Text = ex.Message
  End Try
End Sub

Policies for the GetCurrentBalanceMethod

The configuration of the QuickStart causes the Policy Injection Application Block to create a handler pipeline containing the Logging Handler and the Authorization Handler for the GetCurrentBalance method.

Note

For an explanation about the QuickStart configuration, see The Windows Forms QuickStart.

If the currently selected user is Alice or Bob (as an Assistant, Bob can make balance inquiries but cannot deposit or withdraw funds), the GetCurrentBalance method call will succeed. The Policy Injection Application Block executes the Logging Handler and the Authorization Handler within the pipeline to the GetCurrentBalance method.

Effects of the Logging Handler

The Logging Handler appends two entries to the application's audit log file; one entry is appended before the GetCurrentBalance method executes and one entry is appended after it completes. With the exception of the method and parameter names, these entries are the same as those shown for the Deposit method in the topic Making a Deposit. You can click the View Log File button to see the entire contents of the application's audit log file.

The Logging Handler also writes a "Before" entry and an "After" entry containing the information from the call to the GetCurrentBalance method into the Application Event Log on the local computer.

Effects of the Authorization Handler

If the currently selected user is not Alice or Bob, the Authorization Handler will prevent the GetCurrentBalance method from executing, because the rules in the Security Application Block configuration authorize only Alice (as a Teller) and Bob (as an Assistant) to execute the GetCurrentBalance method. In this case, the Exception text box on the main form shows the message, "Authorization failed".