예제 #1
0
        /// <summary>
        /// Regenerates the contents of the services list view.
        /// </summary>
        private void RefreshList()
        {
            // Store the machine used to browse services so we can compare it with the current value in newMachine to know if we need to call RefreshList.
            ServicesListView.Tag = NewMachine;

            ServicesListView.Items.Clear();
            if (NewMachine == null || !NewMachine.IsOnline)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;
            try
            {
                string currentFilter = FilterCheckBox.Checked
          ? Settings.Default.AutoAddPattern.Trim()
          : FilterTextBox.Text.ToLower();
                ServicesListView.BeginUpdate();
                List <ManagementObject> services = new List <ManagementObject>();
                if (NewMachine != null && MachineLocationType == Machine.LocationType.Remote)
                {
                    ManagementObjectCollection machineServicesCollection = NewMachine.GetWmiServices(true);
                    if (machineServicesCollection != null)
                    {
                        services.AddRange(machineServicesCollection.Cast <ManagementObject>());
                    }
                }
                else
                {
                    services = Service.GetInstances(string.Empty);
                }

                services = services.OrderBy(x => x.Properties["DisplayName"].Value).ToList();
                if (!string.IsNullOrEmpty(currentFilter))
                {
                    services =
                        services.Where(f => f.Properties["DisplayName"].Value.ToString().ToLowerInvariant().Contains(currentFilter))
                        .ToList();
                }

                foreach (ManagementObject item in services)
                {
                    string serviceName = item.Properties["Name"].Value.ToString();
                    var    displayName = item.Properties["DisplayName"].Value;
                    var    newItem     = new ListViewItem
                    {
                        Text                     = displayName != null?displayName.ToString() : serviceName,
                                             Tag = serviceName
                    };

                    newItem.SubItems.Add(item.Properties["State"].Value.ToString());
                    ServicesListView.Items.Add(newItem);
                }
            }
            finally
            {
                ServicesListView.EndUpdate();
                Cursor = Cursors.Default;
            }
        }
예제 #2
0
        /// <summary>
        /// Performs a connection test to the remote host as well as validating the right permissions are set for the credentials provided by the user.
        /// </summary>
        /// <param name="forceTest">Indicates whether the test is performed regardless of the current status of the machine.</param>
        /// <returns>True if no problems were found during the test.</returns>
        private bool TestConnectionAndPermissionsSet(bool forceTest)
        {
            if (!EntriesAreValid)
            {
                return(false);
            }

            if (forceTest || !NewMachine.IsOnline)
            {
                NewMachine.TestConnection(true, false);
            }

            return(NewMachine.IsOnline);
        }
예제 #3
0
        /// <summary>
        /// Event delegate method fired when the <see cref="EditButton"/> is clicked.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void EditButton_Click(object sender, EventArgs e)
        {
            string oldUser     = NewMachine.User;
            string oldPassword = NewMachine.Password;

            using (var windowsConnectionDialog = new WindowsConnectionDialog(MachinesList, NewMachine))
            {
                if (windowsConnectionDialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                HasChanges = true;
                NewMachine.CopyMachineData(windowsConnectionDialog.NewMachine,
                                           oldUser != windowsConnectionDialog.NewMachine.User ||
                                           MySqlSecurity.DecryptPassword(oldPassword) != windowsConnectionDialog.NewMachine.UnprotectedPassword);
                MachinesList.ChangeMachine(NewMachine, ListChangeType.Updated);
                RefreshList();
            }
        }
예제 #4
0
        /// <summary>
        /// Event delegate method fired when the <see cref="ServiceToolStripMenuItem"/> context menu item is clicked.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void ServiceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dialog = new AddServiceDialog(MachinesList))
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (dialog.NewMachine != null && dialog.ServicesToAdd != null && dialog.ServicesToAdd.Count > 0)
                    {
                        NewMachine = MachinesList.GetMachineById(dialog.NewMachine.MachineId);
                        if (NewMachine == null)
                        {
                            MachinesList.ChangeMachine(dialog.NewMachine, ListChangeType.AddByUser);
                            NewMachine = dialog.NewMachine;
                        }

                        foreach (MySqlService service in dialog.ServicesToAdd)
                        {
                            if (NewMachine.ContainsService(service))
                            {
                                InfoDialog.ShowDialog(InfoDialogProperties.GetWarningDialogProperties(Resources.WarningText, Resources.ServiceAlreadyInListWarningText));
                            }
                            else
                            {
                                NewMachine.ChangeService(service, ListChangeType.AddByUser);
                                AddService(service, NewMachine, true);
                            }
                        }
                    }
                }

                if (dialog.HasChanges)
                {
                    RefreshServicesAndInstancesListViews();
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Event delegate method fired when the <see cref="MachineSelectionComboBox"/> selected index changes.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void MachineSelectionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            EditButton.Enabled   = MachineSelectionComboBox.SelectedIndex > 2;
            DeleteButton.Enabled = MachineSelectionComboBox.SelectedIndex > 2;
            switch (MachineSelectionComboBox.SelectedIndex)
            {
            case 0:
                MachineLocationType = Machine.LocationType.Local;
                if (MachineSelectionComboBox.SelectedItem is Machine)
                {
                    NewMachine = MachineSelectionComboBox.SelectedItem as Machine;
                }
                else
                {
                    NewMachine = MachinesList.LocalMachine;
                    MachineSelectionComboBox.Items[0] = NewMachine;
                }
                break;

            case 1:
                MachineLocationType = Machine.LocationType.Remote;
                using (var windowsConnectionDialog = new WindowsConnectionDialog(MachinesList, null))
                {
                    if (windowsConnectionDialog.ShowDialog() == DialogResult.Cancel)
                    {
                        MachineSelectionComboBox.SelectedIndex = 0;
                    }
                    else
                    {
                        NewMachine = windowsConnectionDialog.NewMachine;
                        NewMachine.LoadServicesParameters(false);
                        int index = -1;
                        for (int machineIndex = 3; machineIndex < MachineSelectionComboBox.Items.Count && index < 0; machineIndex++)
                        {
                            string machineName = MachineSelectionComboBox.Items[machineIndex].ToString();
                            if (machineName == NewMachine.Name)
                            {
                                index = machineIndex;
                            }
                        }

                        if (index == -1)
                        {
                            MachineSelectionComboBox.Items.Add(NewMachine);
                            MachineSelectionComboBox.SelectedIndex = MachineSelectionComboBox.Items.Count - 1;
                        }
                        else
                        {
                            MachineSelectionComboBox.SelectedIndex = index <= 0 ? 0 : index;
                        }
                    }
                }
                return;

            case 2:
                if (NewMachine.IsLocal)
                {
                    MachineSelectionComboBox.SelectedIndex = 0;
                    return;
                }

                int mIndex = -1;
                for (int machineIndex = 3; machineIndex < MachineSelectionComboBox.Items.Count; machineIndex++)
                {
                    string machineName = MachineSelectionComboBox.Items[machineIndex].ToString();
                    if (machineName == NewMachine.Name)
                    {
                        mIndex = machineIndex;
                        break;
                    }
                }

                MachineSelectionComboBox.SelectedIndex = mIndex < 0 ? 0 : mIndex;
                return;

            default:
                MachineLocationType = Machine.LocationType.Remote;
                NewMachine          = (Machine)MachineSelectionComboBox.SelectedItem;
                if (!NewMachine.IsOnline)
                {
                    var infoProperties = InfoDialogProperties.GetYesNoDialogProperties(
                        InfoDialog.InfoType.Warning,
                        Resources.MachineUnavailableTitle,
                        Resources.MachineUnavailableYesNoDetail,
                        null,
                        Resources.MachineUnavailableExtendedMessage);
                    infoProperties.CommandAreaProperties.DefaultButton        = InfoDialog.DefaultButtonType.Button2;
                    infoProperties.CommandAreaProperties.DefaultButtonTimeout = 30;
                    var infoResult = InfoDialog.ShowDialog(infoProperties);
                    if (infoResult.DialogResult == DialogResult.Yes)
                    {
                        NewMachine.TestConnection(true, false);
                    }

                    if (!NewMachine.IsOnline)
                    {
                        ServicesListView.SelectedItems.Clear();
                    }
                }
                break;
            }

            ServicesListView.Enabled = NewMachine.IsOnline;
            Machine servicesMachine = ServicesListView.Tag as Machine;

            if (servicesMachine != NewMachine)
            {
                RefreshList();
            }
        }