public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid) { if (_buildServerWatcher != null) { throw new InvalidOperationException("Already initialized"); } _buildServerWatcher = buildServerWatcher; _tfsServer = config.GetString("TfsServer", null); _tfsTeamCollectionName = config.GetString("TfsTeamCollectionName", null); _projectName = config.GetString("ProjectName", null); var tfsBuildDefinitionNameFilterSetting = config.GetString("TfsBuildDefinitionName", ""); if (!BuildServerSettingsHelper.IsRegexValid(tfsBuildDefinitionNameFilterSetting)) { return; } _tfsBuildDefinitionNameFilter = new Regex(tfsBuildDefinitionNameFilterSetting, RegexOptions.Compiled); if (!string.IsNullOrEmpty(_tfsServer) && !string.IsNullOrEmpty(_tfsTeamCollectionName) && !string.IsNullOrEmpty(_projectName)) { _tfsHelper = LoadAssemblyAndConnectToServer("TfsInterop.Vs2015") ?? LoadAssemblyAndConnectToServer("TfsInterop.Vs2013") ?? LoadAssemblyAndConnectToServer("TfsInterop.Vs2012"); if (_tfsHelper == null) { Trace.WriteLine("fail to load the good interop assembly :("); } } }
public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid) { if (_buildServerWatcher != null) { throw new InvalidOperationException("Already initialized"); } _buildServerWatcher = buildServerWatcher; _tfsServer = config.GetString(VstsTfsServerUrlSettingKey, null); _tfsTeamCollectionName = config.GetString(VstsTfsCollectionNameSettingKey, null); _projectName = _buildServerWatcher.ReplaceVariables(config.GetString(VstsTfsProjectNameSettingKey, null)); _restApiToken = config.GetString(VstsTfsRestApiTokenSettingKey, null); var tfsBuildDefinitionNameFilterSetting = config.GetString(VstsTfsBuildDefinitionNameFilterSettingKey, ""); if (string.IsNullOrWhiteSpace(_tfsServer) || string.IsNullOrWhiteSpace(_tfsTeamCollectionName) || string.IsNullOrWhiteSpace(_projectName) || string.IsNullOrWhiteSpace(_restApiToken) || !BuildServerSettingsHelper.IsRegexValid(tfsBuildDefinitionNameFilterSetting)) { return; } _tfsHelper = new TfsApiHelper(_httpClient); _tfsHelper.ConnectToTfsServer(_tfsServer, _tfsTeamCollectionName, _projectName, _restApiToken, tfsBuildDefinitionNameFilterSetting); }
/// <summary> /// Tries to get the token management url of the Azure DevOps / TFS instance for a given project url, without testing /// whether <paramref name="projectUrl"/> actually points to a Azure DevOps / TFS instance. /// </summary> /// <remarks> /// TryGetTokenManagementUrlFromProject will happlily convert anything that somewhat looks like a project url /// in favor of better availability for on premise installations of TFS /// </remarks> /// <param name="projectUrl"> /// The url to the home page of a Azure DevOps / TFS project. /// </param> /// <returns> /// A tuple that contains whether the token management url could be recognized from the given project url and the resulting url. /// </returns> public static (bool success, string tokenManagementUrl) TryGetTokenManagementUrlFromProject(string projectUrl) { if (projectUrl is null && !BuildServerSettingsHelper.IsUrlValid(projectUrl)) { return(false, null); } return(TryTransformString(projectUrl, ProjectToTokenManagementUrlLookup)); }
/// <summary> /// Tries to detect the Azure DevOps / TFS project home page url from a repository url of the same project. /// </summary> /// <param name="remoteUrl"> /// The url of the repository to find the Azure DevOps / TFS project url for. /// </param> /// <returns> /// A tuple that contains whether a Azure DevOps / TFS project could be recognized from the given url and the resulting home page url of the project. /// </returns> public static (bool success, string projectUrl) TryDetectProjectFromRemoteUrl(string remoteUrl) { if (remoteUrl is null && !BuildServerSettingsHelper.IsUrlValid(remoteUrl)) { return(false, null); } return(TryTransformString(remoteUrl, RemoteToProjectUrlLookup)); }
public void SaveSettings(ISettingsSource buildServerConfig) { if (BuildServerSettingsHelper.IsRegexValid(TeamCityBuildIdFilter.Text)) { buildServerConfig.SetString("BuildServerUrl", TeamCityServerUrl.Text); buildServerConfig.SetString("ProjectName", TeamCityProjectName.Text); buildServerConfig.SetString("BuildIdFilter", TeamCityBuildIdFilter.Text); buildServerConfig.SetBool("LogAsGuest", CheckBoxLogAsGuest.Checked); } }
public void SaveSettings(ISettingsSource buildServerConfig) { if (BuildServerSettingsHelper.IsRegexValid(TfsBuildDefinitionNameFilter.Text)) { buildServerConfig.SetString("TfsServer", TfsServer.Text); buildServerConfig.SetString("TfsTeamCollectionName", TfsTeamCollectionName.Text); buildServerConfig.SetString("ProjectName", TfsProjectName.Text); buildServerConfig.SetString("TfsBuildDefinitionName", TfsBuildDefinitionNameFilter.Text); } }
public void SaveSettings(ISettingsSource buildServerConfig) { if (BuildServerSettingsHelper.IsRegexValid(TfsBuildDefinitionNameFilter.Text)) { buildServerConfig.SetString(VstsAndTfsAdapter.VstsTfsServerUrlSettingKey, string.IsNullOrWhiteSpace(TfsServer.Text) ? string.Empty : TfsServer.Text); buildServerConfig.SetString(VstsAndTfsAdapter.VstsTfsCollectionNameSettingKey, TfsTeamCollectionName.Text); buildServerConfig.SetString(VstsAndTfsAdapter.VstsTfsProjectNameSettingKey, TfsProjectName.Text); buildServerConfig.SetString(VstsAndTfsAdapter.VstsTfsBuildDefinitionNameFilterSettingKey, TfsBuildDefinitionNameFilter.Text); buildServerConfig.SetString(VstsAndTfsAdapter.VstsTfsRestApiTokenSettingKey, RestApiToken.Text); } }
public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config) { if (this.buildServerWatcher != null) { throw new InvalidOperationException("Already initialized"); } this.buildServerWatcher = buildServerWatcher; ProjectNames = config.GetString("ProjectName", "").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var buildIdFilerSetting = config.GetString("BuildIdFilter", ""); if (!BuildServerSettingsHelper.IsRegexValid(buildIdFilerSetting)) { return; } BuildIdFilter = new Regex(buildIdFilerSetting, RegexOptions.Compiled); var hostName = config.GetString("BuildServerUrl", null); LogAsGuestUrlParameter = config.GetBool("LogAsGuest", false) ? "&guest=1" : string.Empty; if (!string.IsNullOrEmpty(hostName)) { httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(2), BaseAddress = hostName.Contains("://") ? new Uri(hostName, UriKind.Absolute) : new Uri(string.Format("{0}://{1}", Uri.UriSchemeHttp, hostName), UriKind.Absolute) }; httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true); UpdateHttpClientOptions(buildServerCredentials); if (ProjectNames.Length > 0) { getBuildTypesTask.Clear(); foreach (var name in ProjectNames) { getBuildTypesTask.Add( GetProjectFromNameXmlResponseAsync(name, CancellationToken.None) .ContinueWith( task => from element in task.Result.XPathSelectElements("/project/buildTypes/buildType") select element.Attribute("id").Value, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent)); } } } }
/// <summary> /// Tries to parse a url to a Azure DevOps / TFS build result and get the corresponding project and build id from. /// </summary> /// <param name="buildUrl"> /// A url that points to the build status / build results page of a build in a Azure DevOps / TFS project /// </param> /// <returns> /// A tuple that contains whether the project and build id could be detected from the given url, as well as both informations. /// </returns> public static (bool success, string projectUrl, int buildId) TryParseBuildUrl(string buildUrl) { if (buildUrl is null && !BuildServerSettingsHelper.IsUrlValid(buildUrl)) { return(false, null, -1); } var match = BuildUrlInfoRegex.Match(buildUrl); if (match.Success) { var projectUrl = match.Groups["projecturl"].Value; if (int.TryParse(match.Groups["buildid"].Value, out var buildId)) { return(true, projectUrl, buildId); } } return(false, "", -1); }
public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid) { if (_buildServerWatcher != null) { throw new InvalidOperationException("Already initialized"); } _buildServerWatcher = buildServerWatcher; ProjectNames = buildServerWatcher.ReplaceVariables(config.GetString("ProjectName", "")) .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var buildIdFilerSetting = config.GetString("BuildIdFilter", ""); if (!BuildServerSettingsHelper.IsRegexValid(buildIdFilerSetting)) { return; } BuildIdFilter = new Regex(buildIdFilerSetting, RegexOptions.Compiled); HostName = config.GetString("BuildServerUrl", null); LogAsGuestUrlParameter = config.GetBool("LogAsGuest", false) ? "&guest=1" : string.Empty; if (!string.IsNullOrEmpty(HostName)) { InitializeHttpClient(HostName); if (ProjectNames.Length > 0) { _getBuildTypesTask.Clear(); foreach (var name in ProjectNames) { _getBuildTypesTask.Add(ThreadHelper.JoinableTaskFactory.RunAsync(async() => { var response = await GetProjectFromNameXmlResponseAsync(name, CancellationToken.None).ConfigureAwait(false); return(from element in response.XPathSelectElements("/project/buildTypes/buildType") select element.Attribute("id").Value); })); } } } }
public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid) { if (this.buildServerWatcher != null) { throw new InvalidOperationException("Already initialized"); } this.buildServerWatcher = buildServerWatcher; ProjectNames = config.GetString("ProjectName", "").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var buildIdFilerSetting = config.GetString("BuildIdFilter", ""); if (!BuildServerSettingsHelper.IsRegexValid(buildIdFilerSetting)) { return; } BuildIdFilter = new Regex(buildIdFilerSetting, RegexOptions.Compiled); var hostName = config.GetString("BuildServerUrl", null); LogAsGuestUrlParameter = config.GetBool("LogAsGuest", false) ? "&guest=1" : string.Empty; if (!string.IsNullOrEmpty(hostName)) { InitializeHttpClient(hostName, () => buildServerWatcher.GetBuildServerCredentials(this, true)); if (ProjectNames.Length > 0) { getBuildTypesTask.Clear(); foreach (var name in ProjectNames) { getBuildTypesTask.Add( GetProjectFromNameXmlResponseAsync(name, CancellationToken.None) .ContinueWith( task => from element in task.Result.XPathSelectElements("/project/buildTypes/buildType") select element.Attribute("id").Value, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent)); } } } }
private void UpdateView() { if (_isUpdating) { return; } _isUpdating = true; try { TfsServer.Text = _currentSettings.ProjectUrl; TfsBuildDefinitionNameFilter.Text = _currentSettings.BuildDefinitionFilter; labelRegexError.Visible = !BuildServerSettingsHelper.IsRegexValid(TfsBuildDefinitionNameFilter.Text); RestApiToken.Text = _currentSettings.ApiToken; TokenManagementLink.Enabled = BuildServerSettingsHelper.IsUrlValid(TokenManagementUrl); } finally { _isUpdating = false; } }
private void TeamCityBuildIdFilter_TextChanged(object sender, EventArgs e) { labelRegexError.Visible = !BuildServerSettingsHelper.IsRegexValid(TeamCityBuildIdFilter.Text); }
private void TfsBuildDefinitionNameFilter_TextChanged(object sender, EventArgs e) { labelRegexError.Visible = !BuildServerSettingsHelper.IsRegexValid(TfsBuildDefinitionNameFilter.Text); }
private void EnableRestApiLink() { _tokenManagementUrl = $"{TfsServer.Text}_details/security/tokens"; RestApiTokenLink.Enabled = BuildServerSettingsHelper.IsUrlValid(_tokenManagementUrl); }
/// <summary> /// Validates if these settings are valid and good to use. /// </summary> public bool IsValid() { return(!(string.IsNullOrWhiteSpace(ProjectUrl) || string.IsNullOrWhiteSpace(ApiToken)) && BuildServerSettingsHelper.IsRegexValid(BuildDefinitionFilter)); }