Inheritance: System.Windows.DependencyObject
Example #1
0
        public void RequestCredentialsFor(string messagingServiceName, string suggestedUserName, IServiceInformation serviceInformation)
        {
            var username = "";
            var password = "";
            var savePassword = false;

            _Fiber.RunOnMainThread(() =>
                                       {
                                           var userCredentialsViewModel = new UserCredentialsViewModel()
                                                                              {
                                                                                  Caption = messagingServiceName + " Login",
                                                                                  UserName = suggestedUserName
                                                                              };

                                           var dialog = new UserCredentialsWindow
                                                            {
                                                                DataContext = userCredentialsViewModel
                                                            };
                                           var mainWindow = Application.Current.MainWindow;
                                           dialog.Owner = mainWindow;
                                           dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                                           dialog.ShowDialog();
                                           username = userCredentialsViewModel.UserName;
                                           password = userCredentialsViewModel.Password;
                                           savePassword = userCredentialsViewModel.SavePassword;
                                       });

            _CredentialsProvidedObserver.CredentialsProvided(new Credentials()
                                                         {
                                                             UserName = username,
                                                             Password = password,
                                                             ServiceInformation = serviceInformation,
                                                             IsPasswordCachingAllowed = savePassword
                                                         });
        }
        public Credentials GetCredentials(IServiceInformation serviceInformation)
        {
            var username = "";
            var password = "";

            var dispatcher = Dispatcher.FromThread(_mainThread);
            dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                                                             {
                                                                 var model = new UserCredentialsViewModel()
                                                                 {
                                                                     Caption = serviceInformation.ServiceName + " Login"
                                                                 };
                                                                 var dialog = new UserCredentialsWindow
                                                                     {
                                                                         DataContext = model
                                                                     };
                                                                 var mainWindow = Application.Current.MainWindow;
                                                                 dialog.Owner = mainWindow;
                                                                 dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                                                                 dialog.ShowDialog();
                                                                 username = model.UserName;
                                                                 password = model.Password;
                                                             }));

            return new Credentials()
                       {
                           UserName = username,
                           Password = password,
                           ServiceInformation = serviceInformation
                       };
        }