Example #1
0
        private void btnCreateProfile_Click(object sender, EventArgs e)
        {
            // create new profile
            HashSet <string> existingNames      = deploymentConfig.GetExistingProfileNames();
            string           defaultProfileName = string.Format(ProfileNameFormat, projectInstance.Name);

            DeploymentProfile profile = new()
            {
                InstanceID = projectInstance.ID,
                Name       = existingNames.Contains(defaultProfileName) ? "" : defaultProfileName
            };

            profile.AgentConnectionOptions.Instance = projectInstance.Name;

            FrmProfileEdit frmProfileEdit = new(appData, profile)
            {
                ExistingProfileNames = existingNames
            };

            if (frmProfileEdit.ShowDialog() == DialogResult.OK)
            {
                AddProfileToLists(profile);
                SaveDeploymentConfig();
            }
        }

        private void btnEditProfile_Click(object sender, EventArgs e)
        {
            // edit selected profile
            DeploymentProfile profile = SelectedProfile;
            string            oldName = profile.Name;

            FrmProfileEdit frmProfileEdit = new(appData, profile)
            {
                ExistingProfileNames = deploymentConfig.GetExistingProfileNames(oldName)
            };

            if (frmProfileEdit.ShowDialog() == DialogResult.OK)
            {
                // update profile name if it changed
                if (oldName != profile.Name)
                {
                    deploymentConfig.Profiles.Remove(oldName);

                    try
                    {
                        cbProfile.BeginUpdate();
                        cbProfile.Items.RemoveAt(cbProfile.SelectedIndex);
                        AddProfileToLists(profile);
                    }
                    finally
                    {
                        cbProfile.EndUpdate();
                    }
                }

                // fix instance reference
                if (profile.InstanceID <= 0)
                {
                    profile.InstanceID = projectInstance.ID;
                }

                // save deployment settings
                SaveDeploymentConfig();
                OnProfileEdited();
            }
        }

        private void btnDeleteProfile_Click(object sender, EventArgs e)
        {
            // delete selected profile
            if (SelectedProfile is DeploymentProfile profile &&
                MessageBox.Show(AppPhrases.ConfirmDeleteProfile, CommonPhrases.QuestionCaption,
                                MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // remove from deployment configuration
                deploymentConfig.Profiles.Remove(profile.Name);

                // remove from combo box
                try
                {
                    cbProfile.BeginUpdate();
                    int selectedIndex = cbProfile.SelectedIndex;
                    cbProfile.Items.RemoveAt(selectedIndex);

                    if (cbProfile.Items.Count > 0)
                    {
                        cbProfile.SelectedIndex = selectedIndex >= cbProfile.Items.Count ?
                                                  cbProfile.Items.Count - 1 : selectedIndex;
                    }
                }
                finally
                {
                    cbProfile.EndUpdate();
                }

                // save deployment settings
                SaveDeploymentConfig();
            }
        }
    }