Beispiel #1
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            if (string.IsNullOrEmpty(_target))
            {
                throw new InvalidOperationException(Properties.Resources.CredentialEmptyTargetError);
            }

            UserName           = "";
            Password           = "";
            IsStoredCredential = false;

            if (RetrieveCredentialsFromApplicationInstanceCache())
            {
                IsStoredCredential = true;
                _confirmTarget     = Target;
                return(DialogResult.OK);
            }

            bool storedCredentials = false;

            if (ShowSaveCheckBox && RetrieveCredentials())
            {
                IsSaveChecked = true;
                if (!ShowUIForSavedCredentials)
                {
                    IsStoredCredential = true;
                    _confirmTarget     = Target;
                    return(DialogResult.OK);
                }
                storedCredentials = true;
            }

            IntPtr ownerHandle = owner == null?NativeMethods.GetActiveWindow() : owner.Handle;

            bool result;

            if (NativeMethods.IsWindowsVistaOrLater)
            {
                result = PromptForCredentialsCredUIWin(ownerHandle, storedCredentials);
            }
            else
            {
                result = PromptForCredentialsCredUI(ownerHandle, storedCredentials);
            }
            return(result ? DialogResult.OK : DialogResult.Cancel);
        }
 /// <summary>
 /// Displays the progress dialog as a modal dialog.
 /// </summary>
 /// <param name="owner">The window that owns the dialog.</param>
 /// <param name="argument">A parameter for use by the background operation to be executed in the <see cref="DoWork"/> event handler.</param>
 /// <remarks>
 /// <para>
 ///   The ShowDialog function for most .Net dialogs will not return until the dialog is closed. However,
 ///   the <see cref="ShowDialog()"/> function for the <see cref="ProgressDialog"/> class will return immediately.
 ///   The parent window will be disabled as with all modal dialogs.
 /// </para>
 /// <para>
 ///   Although this function returns immediately, you cannot use the UI thread to do any processing. The dialog
 ///   will not function correctly unless the UI thread continues to handle window messages, so that thread may
 ///   not be blocked by some other activity. All processing related to the progress dialog must be done in
 ///   the <see cref="DoWork"/> event handler.
 /// </para>
 /// <para>
 ///   The progress dialog's window will appear in the taskbar. This behaviour is also contrary to most .Net dialogs,
 ///   but is part of the underlying native progress dialog API so cannot be avoided.
 /// </para>
 /// <para>
 ///   When possible, it is recommended that you use a modeless dialog using the <see cref="Show()"/> function.
 /// </para>
 /// </remarks>
 /// <exception cref="InvalidOperationException">The animation specified in the <see cref="Animation"/> property
 /// could not be loaded, or the operation is already running.</exception>
 public void ShowDialog(IWin32Window owner, object argument)
 {
     RunProgressDialog(owner == null ? NativeMethods.GetActiveWindow() : owner.Handle, argument);
 }