private static void DoSignInInUIThread(string url, Action<IdentityManager.Credential, Exception> callback, IdentityManager.GenerateTokenOptions generateTokenOptions
#if !SILVERLIGHT
, IdentityManager.AuthenticationType authenticationType = IdentityManager.AuthenticationType.Token
#endif
)
{
// In SL and WPF : Create the ChildWindow that contains the SignInDialog
#if SILVERLIGHT
ChildWindow childWindow = new ChildWindow();
DependencyProperty titleProperty = ChildWindow.TitleProperty;
#else
var childWindow = new Window
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
WindowStyle = WindowStyle.ToolWindow,
SizeToContent = SizeToContent.WidthAndHeight,
ResizeMode = ResizeMode.NoResize,
WindowState = WindowState.Normal
};
if (Application.Current != null && Application.Current.MainWindow != null)
{
try
{
childWindow.Owner = Application.Current.MainWindow;
}
catch (Exception)
{
// May fire an exception when used inside an excel or powerpoint addins
}
}
DependencyProperty titleProperty = Window.TitleProperty;
#endif
// Create the SignInDialog with the parameters given as arguments
var signInDialog = new SignInDialog
{
Url = url,
Callback = (credential, error) =>
{
childWindow.Close();
callback(credential, error);
},
GenerateTokenOptions = generateTokenOptions,
IsActive = true,
Width = 300,
#if !SILVERLIGHT
_authenticationType = authenticationType
#endif
};
childWindow.Content = signInDialog;
// Bind the Title so the ChildWindow Title is the SignInDialog title (taht will be initialized later)
Binding binding = new Binding("Title") { Source = signInDialog };
childWindow.SetBinding(titleProperty, binding);
childWindow.Closed += (s, e) => signInDialog.IsActive = false; // be sure the SignInDialog is deactivated (i.e. Callback executed once) when closing the childwindow using the X
// Show the window
#if SILVERLIGHT
childWindow.Show();
#else
childWindow.ShowDialog();
#endif
}