コード例 #1
0
        internal void FillItems(TeamCityConfigurer configurer)
        {
            if (configurer == null)
            {
                return;
            }

            using (var client = new WebClient())
            {
                client.BaseAddress = configurer.BaseUrl;
                if (!string.IsNullOrEmpty(configurer.Username))
                {
                    client.Credentials = new NetworkCredential(configurer.Username, configurer.Password);
                }

                this.Items.AddRange(XDocument
                                    .Parse(client.DownloadString("app/rest/buildTypes"))
                                    .Element("buildTypes")
                                    .Elements("buildType")
                                    .Select(e => new
                {
                    Id      = (string)e.Attribute("id"),
                    Project = (string)e.Attribute("projectName"),
                    Name    = (string)e.Attribute("name")
                })
                                    .Select(bt => new SelectListItem(bt.Project + ": " + bt.Name, bt.Id))
                                    .ToArray());
            }
        }
コード例 #2
0
        void IVariableSetter <SelectBuildConfigurationVariable> .BindToVariable(SelectBuildConfigurationVariable variable, string defaultValue)
        {
            if (variable == null)
            {
                throw new ArgumentNullException("variable");
            }

            this.FillItems(TeamCityConfigurer.GetConfigurer(variable.ConfigurationProfileName));
            this.SelectedValue = AH.CoalesceString(variable.Value, defaultValue);
        }
コード例 #3
0
        /// <summary>
        /// Creates from form.
        /// </summary>
        /// <returns></returns>
        public override ExtensionConfigurerBase CreateFromForm()
        {
            var configurer = new TeamCityConfigurer()
            {
                ServerUrl = this.txtServerUrl.Text
            };
            if (!string.IsNullOrEmpty(this.txtUsername.Text))
            {
                configurer.Username = this.txtUsername.Text;
                configurer.Password = this.txtPassword.Text;
            }

            return configurer;
        }
コード例 #4
0
        private string GetBranchName(TeamCityConfigurer configurer)
        {
            if (!string.IsNullOrEmpty(this.BranchName))
            {
                return(this.BranchName);
            }

            if (!string.IsNullOrEmpty(configurer.DefaultBranchName))
            {
                return(configurer.DefaultBranchName);
            }

            return(null);
        }
コード例 #5
0
        public override ExtensionConfigurerBase CreateFromForm()
        {
            var configurer = new TeamCityConfigurer()
            {
                ServerUrl         = this.txtServerUrl.Text,
                DefaultBranchName = this.txtDefaultBranchName.Text
            };

            if (!string.IsNullOrEmpty(this.txtUsername.Text))
            {
                configurer.Username = this.txtUsername.Text;
                configurer.Password = this.txtPassword.Text;
            }

            return(configurer);
        }
コード例 #6
0
        protected override void CreateChildControls()
        {
            this.txtArtifactName = new ValidatingTextBox {
                Required = true
            };
            this.txtBranchName = new ValidatingTextBox()
            {
                DefaultText = "Default"
            };
            this.chkArtifactNameLocked = new CheckBox {
                Text = "Allow selection at build time"
            };
            this.chkBranchNameLocked = new CheckBox {
                Text = "Allow selection at build time"
            };

            this.ddlBuildConfigurationId = new SelectBuildConfigurationPicker()
            {
                ID = "ddlBuildConfigurationId"
            };
            this.ddlBuildConfigurationId.ExternalInit =
                () =>
            {
                int?configurerId = this.TryGetConfigurerId();
                this.ddlBuildConfigurationId.FillItems(TeamCityConfigurer.GetConfigurer(configurerId: configurerId));
            };

            this.ddlBuildNumber = new SelectList();
            this.ddlBuildNumber.Items.Add(new SelectListItem("Select at build import time", ""));
            this.ddlBuildNumber.Items.Add(new SelectListItem("Always use last successful build", "lastSuccessful"));
            this.ddlBuildNumber.Items.Add(new SelectListItem("Always use last finished build", "lastFinished"));
            this.ddlBuildNumber.Items.Add(new SelectListItem("Always use last pinned build", "lastPinned"));

            this.Controls.Add(
                new SlimFormField("Build configuration:", this.ddlBuildConfigurationId),
                new SlimFormField("TeamCity build number:", this.ddlBuildNumber),
                new SlimFormField("Artifact name:", new Div(this.txtArtifactName), new Div(this.chkArtifactNameLocked))
            {
                HelpText = "The name of artifact, for example: \"ideaIC-118.SNAPSHOT.win.zip\"."
            },
                new SlimFormField("Branch name:", new Div(this.txtBranchName), new Div(this.chkBranchNameLocked))
            {
                HelpText = "The branch used to get the artifact, typically used in conjunction with predefined constant build numbers."
            }
                );
        }
コード例 #7
0
        private static object GetBuildNumbers(string buildConfigurationId, int configurerId)
        {
            TeamCityConfigurer configurer;

            if (configurerId == 0)
            {
                configurer = TeamCityConfigurer.GetConfigurer();
            }
            else
            {
                configurer = (TeamCityConfigurer)Util.ExtensionConfigurers.GetExtensionConfigurer(configurerId);
            }

            using (var client = new WebClient())
            {
                client.BaseAddress = configurer.BaseUrl;
                if (!string.IsNullOrEmpty(configurer.Username))
                {
                    client.Credentials = new NetworkCredential(configurer.Username, configurer.Password);
                }

                string buildHistoryUrl = string.Format("app/rest/buildTypes/id:{0}/builds", Uri.EscapeDataString(buildConfigurationId));

                var list = new List <object>();

                list.Add(new { text = "Last successful build", id = "lastSuccessful" });
                list.Add(new { text = "Last pinned build", id = "lastPinned" });
                list.Add(new { text = "Last finished build", id = "lastFinished" });
                list.AddRange(XDocument
                              .Parse(client.DownloadString(buildHistoryUrl))
                              .Element("builds")
                              .Elements("build")
                              .Select(e => new
                {
                    id   = (string)e.Attribute("number"),
                    text = (string)e.Attribute("number")
                }));

                return(list);
            }
        }
コード例 #8
0
        private void CreateTeamCityConnectionControls()
        {
            var defaultCfg = TeamCityConfigurer.GetConfigurer(null) ?? new TeamCityConfigurer();
            var ctlError = new InfoBox { BoxType = InfoBox.InfoBoxTypes.Error, Visible = false };

            var txtServerUrl = new ValidatingTextBox
            {
                Required = true,
                Text = defaultCfg.ServerUrl,
                Width = 350
            };

            var txtUsername = new ValidatingTextBox
            {
                Text = defaultCfg.Username,
                Width = 350
            };
            var txtPassword = new PasswordTextBox
            {
                Text = defaultCfg.Password,
                Width = 350
            };

            txtServerUrl.ServerValidate += (s, e) =>
                {
                    var configurer = new TeamCityConfigurer
                    {
                        ServerUrl = txtServerUrl.Text,
                        Username = txtUsername.Text,
                        Password = txtPassword.Text
                    };
                    try
                    {
                        using (var client = new WebClient())
                        {
                            client.BaseAddress = configurer.BaseUrl;
                            if (!string.IsNullOrEmpty(configurer.Username))
                                client.Credentials = new NetworkCredential(configurer.Username, configurer.Password);

                            client.DownloadString("app/rest/buildTypes");
                        }
                    }
                    catch (Exception _e)
                    {
                        e.IsValid = false;
                        ctlError.Visible = true;
                        ctlError.Controls.Add(new P("An error occurred while attempting to connect: " + _e.Message));
                    }
                };

            this.wizardSteps.TeamCityConnection.Controls.Add(
                ctlError,
                new FormFieldGroup(
                    "TeamCity Server URL",
                    "Enter the URL of the TeamCity server, typically: http://teamcityserver",
                    false,
                    new StandardFormField("Server URL:", txtServerUrl)
                ),
                new FormFieldGroup(
                    "Authentication",
                    "If you wish to connect to the TeamCity server with HTTP Authentication, please enter the credentials. Leaving the username field blank will connect using guest authentication.",
                    true,
                    new StandardFormField("Username:"******"Password:"******"Default",
                        Util.Persistence.SerializeToPersistedObjectXml(defaultCfg),
                        Domains.YN.Yes)
                    .Execute();
            };
        }