public bool Prompt()
        {
            var prompt = new VistaPrompt();
            prompt.Title = "Mingle Authentication";
            prompt.GenericCredentials = true;
            prompt.ShowSaveCheckBox = true;

            if (!string.IsNullOrEmpty(Username))
            {
                prompt.Username = Username;
            }

            if (prompt.ShowDialog() == DialogResult.OK)
            {
                Username = prompt.Username;
                Password = prompt.Password;

                if (prompt.SaveChecked)
                {
                    Save();
                }

                return true;
            }

            return false;
        }
示例#2
0
        private async Task <bool> Reload()
        {
            try
            {
                var systemServices = await Task.Run(() => ServiceController.GetServices(machineHostname));

                services.Clear();

                foreach (var model in systemServices.Select(service => new ServiceViewModel(service)))
                {
                    services.Add(model);
                }

                await PerformBackgroundOperation(x => x.Refresh(ServiceViewModel.RefreshData.DisplayName, ServiceViewModel.RefreshData.ServiceName, ServiceViewModel.RefreshData.Status, ServiceViewModel.RefreshData.Startup));

                PopulateFilteredDataview();
                SetTitle();
                return(true);
            }
            catch (Exception e) when(ExceptionIsAccessDenied(e))
            {
                var prompt = new CredentialManagement.VistaPrompt
                {
                    Title   = "Access denied",
                    Message = $"Enter administator credentials for {machineHostname}"
                };

                if (prompt.ShowDialog() == CredentialManagement.DialogResult.OK)
                {
                    StartNewProcess(prompt);
                    return(false);
                }

                Disconnect();
                MessageBox.Show($@"Unable to retrieve the services from {toolStripConnectToTextBox.Text}.{Environment.NewLine}Message: {e.Message}", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception e)
            {
                Disconnect();
                MessageBox.Show($@"Unable to retrieve the services from {toolStripConnectToTextBox.Text}.{Environment.NewLine}Message: {e.Message}", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
示例#3
0
        public static System.Net.NetworkCredential GetCredential(string serverip)
        {
            System.Net.NetworkCredential credentials = null;
            BaseCredentialsPrompt prompt = null;
            if (IsWinVistaOrHigher())
            {
                prompt = new VistaPrompt();
                Console.WriteLine("win7");
            }
            else
            {
                prompt = new XPPrompt() { Target = serverip };

                Console.WriteLine("xp");
            }
            prompt.SaveChecked = true;
            prompt.ShowSaveCheckBox = true;
            prompt.Title = @"指定已授权的 域(计算机)\用户";
            try
            {
                if (prompt.ShowDialog() == DialogResult.OK)
                {
                    credentials = new System.Net.NetworkCredential(prompt.Username, prompt.SecurePassword);
                    if (prompt.SaveChecked)
                    {
                        var cm = new Credential()
                        {
                            Target = serverip,
                            Type = CredentialType.DomainPassword,//windows 凭证 Generic 普通凭证
                            PersistanceType = PersistanceType.Enterprise,//永久
                            Username = prompt.Username,
                            SecurePassword = prompt.SecurePassword
                        };
                        cm.Save();
                    }
                    return credentials;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException());
            }

            return null;
        }