//Event handler for Sign-In/Sign-Out button clicks.
private void buttonSignInOrOut_Click(object sender, EventArgs e)
{
//Check to see if the user is not currently authenticated.
if (!oID.IsAuthenticated)
{
try
{
//Try to authenticate the user by showing the Sign-In dialog window.
if (oID.Authenticate())
{
currentUserName = oID.UserName;
}
else
{
MessageBox.Show("Authentication failed");
}
}
catch (WLLogOnException wlex)
{
//Check to see if FlowUrl is defined.
if (wlex.FlowUrl != null)
{
//If FlowUrl is defined, direct user to the web page to correct the error.
MessageBox.Show(wlex.ErrorString + "Please go to " + wlex.FlowUrl.AbsoluteUri + "to correct the condition that caused the error");
}
else
{
//If FlowUrl is not defined, simply display the ErrorString.
MessageBox.Show(wlex.ErrorString);
}
}
}
else
{
//If user is authenticated, they intended to Sign-Out. Try signing the user out.
try
{
oID.CloseIdentityHandle();
currentUserName = "";
}
catch (WLLogOnException wlex)
{
//Check to see if FlowUrl is defined.
if (wlex.FlowUrl != null)
{
//If FlowUrl is defined, direct user to the web page to correct the error.
MessageBox.Show(wlex.ErrorString + "Please go to " + wlex.FlowUrl.AbsoluteUri + "to correct the condition that caused the error");
}
else
{
//If FlowUrl is not defined, simply display the ErrorString.
MessageBox.Show(wlex.ErrorString);
}
}
}
UpdateDisplay();
}