private void mniAgent_Edit_Click(object sender, EventArgs e) { var buildAgent = this.lvAgents.SelectedItems[0].Tag as IBuildAgent; var savedbuildAgent = new TempBuildAgent(buildAgent); IBuildAgent editedAgent = FormAgentEdit.DialogShow(buildAgent, FormActionMode.Edit); if (editedAgent != null) { TempBuildAgent.AssingTo(editedAgent, buildAgent); try { Context.BuildServer.SaveBuildAgents(new[] { buildAgent }); } catch (Exception ex) { TempBuildAgent.AssingTo(savedbuildAgent, buildAgent); MessageBox.Show(ex.Message, "Edit build agent", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { PopulateBuildAgents(true, true); SelectBuildAgent(buildAgent); } } }
public static IBuildAgent DialogShow(IBuildAgent agent, FormActionMode mode) { IBuildAgent result = null; if (form == null) { form = new FormAgentEdit(); } form.agent = agent; form.mode = mode; form.Initialize(); if (form.ShowDialog() == DialogResult.OK) { if (form.mode != FormActionMode.View) { result = new TempBuildAgent(); (result as TempBuildAgent).TeamProject = form.cmbTeamProject.SelectedItem as string; result.Name = form.edName.Text; result.Description = form.edDescription.Text; result.MachineName = form.edMachineName.Text; //result.Port = Convert.ToInt32(form.edPort.Text); result.RequireSecureChannel = form.chRequireSecureChannel.Checked; result.BuildDirectory = form.edBuildDirectory.Text; result.Status = (AgentStatus)Enum.Parse(typeof(AgentStatus), form.cmbStatus.SelectedItem as string); //result.MaxProcesses = (int) form.edMaxProcesses.Value; } } return(result); }
public AppServer(IWebServer webServer, IBuildAgent buildAgent) { BuildAgent = buildAgent; Ensure.That(() => webServer).IsNotNull(); Ensure.That(() => buildAgent).IsNotNull(); _webServer = webServer; }
private void linkAgentDetails_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { IBuildAgent editedAgent = FormAgentEdit.DialogShow(this.newBuildAgent, FormActionMode.Edit); if (editedAgent != null) { TempBuildAgent.AssingTo(editedAgent, this.newBuildAgent); } }
public static void AssingTo(IBuildAgent sourceAgent, IBuildAgent targetAgent) { targetAgent.Name = sourceAgent.Name; targetAgent.Description = sourceAgent.Description; targetAgent.MachineName = sourceAgent.MachineName; //targetAgent.Port = sourceAgent.Port; targetAgent.RequireSecureChannel = sourceAgent.RequireSecureChannel; targetAgent.BuildDirectory = sourceAgent.BuildDirectory; targetAgent.Status = sourceAgent.Status; //targetAgent.MaxProcesses = sourceAgent.MaxProcesses; }
private void Initialize() { int teamProjectIndex = -1; if (this.agent != null && this.mode != FormActionMode.Copy) { teamProjectIndex = this.cmbTeamProject.FindStringExact(this.agent.TeamProject); } this.cmbTeamProject.SelectedIndex = teamProjectIndex; this.cmbTeamProject.Enabled = (this.mode == FormActionMode.New || this.mode == FormActionMode.Copy); bool canEdit = (this.mode != FormActionMode.View); if (this.mode == FormActionMode.New) { this.agent = null; } this.edName.Text = this.agent != null ? this.agent.Name : string.Empty; this.edName.ReadOnly = !canEdit; this.edDescription.Text = this.agent != null ? this.agent.Description : string.Empty; this.edDescription.ReadOnly = !canEdit; this.edMachineName.Text = this.agent != null ? this.agent.MachineName : string.Empty; this.edMachineName.ReadOnly = !canEdit; // this.edPort.Text = this.agent != null ? this.agent.Port.ToString() : "9191"; // this.edPort.ReadOnly = !canEdit; this.chRequireSecureChannel.Checked = this.agent != null ? this.agent.RequireSecureChannel : false; this.chRequireSecureChannel.Enabled = canEdit; this.edBuildDirectory.Text = this.agent != null ? this.agent.BuildDirectory : @"$(Temp)\$(BuildDefinitionPath)"; this.edBuildDirectory.ReadOnly = !canEdit; this.cmbStatus.SelectedIndex = this.agent != null ? GetStatusIdx(this.agent.Status) : GetStatusIdx(AgentStatus.Available); this.cmbStatus.Enabled = canEdit; this.lbQueueCount.Text = string.Format("{0} builds in queue", this.agent != null ? this.agent.QueueCount : 0); /*this.edMaxProcesses.Value = this.agent != null ? this.agent.MaxProcesses : 1; * this.edMaxProcesses.ReadOnly = !canEdit; * this.edMaxProcesses.Enabled = canEdit;*/ }
public BuildAgentViewModel(IBuildAgent agent) { this.Name = "\t" + agent.Name; this.BuildDirectory = agent.BuildDirectory; this.DateCreated = agent.DateCreated; this.DateUpdated = agent.DateUpdated; this.IsReserved = agent.IsReserved ? "True" : "False"; this.Status = agent.Status.ToString(); this.Enabled = agent.Enabled; this.Tags = agent.Tags; this.StatusMessage = agent.StatusMessage; this.Agent = agent; string url = agent.Url.ToString(); url = url.Substring(url.LastIndexOf(@"/", StringComparison.OrdinalIgnoreCase) + 1, url.Length - url.LastIndexOf(@"/", StringComparison.OrdinalIgnoreCase) - 1); this.Id = Convert.ToInt32(url); }
/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> protected override void InternalExecute() { IBuildAgent buildAgent = this.BuildAgent.Get(this.ActivityContext); string tag = this.Tag.Get(this.ActivityContext); switch (this.action) { case TagAction.Add: buildAgent.Tags.Add(tag); buildAgent.Save(); break; case TagAction.Remove: buildAgent.Tags.Remove(tag); buildAgent.Save(); break; } }
public static bool IsEqual(IBuildAgent agent1, IBuildAgent agent2) { return((agent1.BuildDirectory == agent2.BuildDirectory) && (agent1.BuildServer.TeamFoundationServer == agent2.BuildServer.TeamFoundationServer) && (agent1.BuildServer.BuildServerVersion == agent2.BuildServer.BuildServerVersion) && (agent1.Description == agent2.Description || (string.IsNullOrEmpty(agent1.Description) && string.IsNullOrEmpty(agent2.Description))) && (agent1.FullPath == agent2.FullPath) && (agent1.MachineName == agent2.MachineName) && //(agent1.MaxProcesses == agent2.MaxProcesses) && (agent1.Name == agent2.Name) && //(agent1.Port == agent2.Port) && (agent1.QueueCount == agent2.QueueCount) && (agent1.RequireSecureChannel == agent2.RequireSecureChannel) && (agent1.Status == agent2.Status) && (agent1.TeamProject == agent2.TeamProject) && (agent1.Uri == agent2.Uri)); }
private void ChangeDefaultAgentTemplate_OnClick(object sender, EventArgs e) { if (lvBuildTemplates.SelectedIndices.Count == 0) { return; } ToolStripItem toolStripItem = (sender as ToolStripItem); IBuildAgent buildAgent = toolStripItem.Tag as IBuildAgent; var buildTemplates = this.lvBuildTemplates.SelectedItems.ToCollection(o => (o as ListViewItem).Tag as BuildTemplate); MakeMultipleChangesOnBuildTemplates(buildTemplates, true, delegate(BuildTemplate buildTemplate) { buildTemplate.BuildControllerName = buildAgent.Name; buildTemplate.BuildControllerUri = buildAgent.Uri.ToString(); }); // foreach (ListViewItem viewItem in this.lvBuildTemplates.SelectedItems) // { // BuildTemplate buildTemplate = viewItem.Tag as BuildTemplate; // int index = Context.BuildTemplates.Templates.FindIndex(template => template == buildTemplate); // // if (Context.BuildTemplates.Templates[index].Timestamp == 0) // { // buildTemplate.Timestamp = DateTime.Now.Ticks; // } // else // { // buildTemplate.Timestamp = Context.BuildTemplates.Templates[index].Timestamp; // } // // buildTemplate.BuildAgentName = buildAgent.Name; // buildTemplate.BuildAgentUri = buildAgent.Uri.ToString(); // // Context.BuildTemplates.Templates[index] = buildTemplate; // } // // Context.BuildTemplates.SaveToFile(Context.BuildTemplates.Filename); // PopulateBuildTemplates(true); }
private void Initialize() { this.btnCopy.Enabled = false; this.cmbTargetTeamProject.Items.Clear(); Dictionary <string, ProjectInfo> teamProjects = Context.GetSortedProjects(); string sourceTeamBuild = this.sourceBuildAgent.TeamProject.ToLower(); foreach (var teamProject in teamProjects) { if (teamProject.Key.ToLower() != sourceTeamBuild) { this.cmbTargetTeamProject.Items.Add(teamProject.Key); } } this.lbSourceTeamProject.Text = string.Format("Team project: {0}", this.sourceBuildAgent.TeamProject); this.lbSourceBuildAgent.Text = string.Format("Build agent: {0}", this.sourceBuildAgent.Name); this.newBuildAgent = new TempBuildAgent(this.sourceBuildAgent); }
public static bool DialogShow(IBuildAgent sourceBuildAgent, out IBuildAgent copiedBuildAgent) { if (form == null) { form = new FormAgentCopyTo(); } form.sourceBuildAgent = sourceBuildAgent; form.Initialize(); copiedBuildAgent = null; bool result = form.ShowDialog() == DialogResult.OK; if (result) { copiedBuildAgent = form.newBuildAgent; } return(result); }
/// <summary> /// Executes the logic for this workflow activity /// </summary> protected override void InternalExecute() { // Initialise defaults if (this.UseDefaultCredentials.Expression == null) { this.UseDefaultCredentials.Set(this.ActivityContext, true); } if (this.Format.Expression == null) { this.Format.Set(this.ActivityContext, "Text"); } if (this.Priority.Expression == null) { this.Priority.Set(this.ActivityContext, "Normal"); } this.buildDetail = this.ActivityContext.GetExtension <IBuildDetail>(); this.buildAgent = this.ActivityContext.GetExtension <IBuildAgent>(); string filePath = this.FilePath.Expression == null ? this.buildDetail.DropLocation : this.FilePath.Get(this.ActivityContext); this.reportFile = new FileInfo(Path.Combine(filePath, this.ReportFileName.Get(this.ActivityContext))); this.xmlfile = new FileInfo(Path.Combine(filePath, this.ReportFileName.Get(this.ActivityContext).Replace(".txt", ".xml"))); this.transformedReportFile = new FileInfo(Path.Combine(filePath, this.ReportFileName.Get(this.ActivityContext).Replace(".txt", ".html"))); this.associatedChangesets = this.AssociatedChangesets.Get(this.ActivityContext); switch (this.Action) { case BuildReportAction.Generate: this.GenerateReport(); break; default: throw new ArgumentException("Action not supported"); } }
public WcfServer(IBuildAgent buildAgent) { _buildAgent = buildAgent; }
public void DisableAgent(IBuildAgent agent) { agent.Enabled = false; agent.Save(); }
public void AssingTo(IBuildAgent targetAgent) { AssingTo(this, targetAgent); }
public TempBuildAgent(IBuildAgent source) { AssingTo(source, this); }
/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> protected override void InternalExecute() { IBuildAgent buildAgent = this.BuildAgent.Get(this.ActivityContext); this.AgentMachineName.Set(this.ActivityContext, buildAgent.Url.Host); }
/// <summary> /// Walks through the list of provided AssemblyInfo properties and updates those values /// </summary> /// <param name="filePath">AssemblyInfo file being modified</param> /// <param name="assemblyInfoProperties">List of properties and values to change</param> /// <param name="buildDetail"></param> /// <param name="buildDate"></param> /// <param name="projectType">Type of project (cs, vb, cpp or fs)</param> /// <param name="forceCreate">If the value isn't in the AssemblyInfo file do we insert it anyway</param> /// <param name="workspace"></param> /// <param name="buildAgent"></param> /// <param name="buildNumberPrefix"></param> /// <param name="incrementBy"></param> /// <param name="buildNumberSeed"></param> public ICollection<KeyValuePair<string, string>> UpdateAssemblyValues(string filePath, IList<KeyValuePair<string, string>> assemblyInfoProperties, IBuildDetail buildDetail, DateTime buildDate, ProjectTypes projectType, bool forceCreate, Workspace workspace, IBuildAgent buildAgent, int buildNumberPrefix, int incrementBy, int buildNumberSeed) { var convertedValues = new List<KeyValuePair<string, string>>(); var newFileData = new StringBuilder(); // make sure you can write to the file var currentFileAttributes = File.GetAttributes(filePath); File.SetAttributes(filePath, currentFileAttributes & ~FileAttributes.ReadOnly); // Get the file data var fileData = File.ReadAllText(filePath); // if working with F# files, remove the "do binding" so we can make sure that the "do" is at the end of the file if (projectType == ProjectTypes.Fs) { var regex = new Regex(@".*(\(\s*\)|do\s*\(\s*\))"); fileData = regex.Replace(fileData, ""); } foreach (KeyValuePair<string, string> property in assemblyInfoProperties) { string convertedValue = VersioningHelper.ReplacePatternsInPropertyValue(property.Value, buildDetail, buildNumberPrefix, incrementBy, buildNumberSeed, buildDate, workspace, buildAgent); convertedValues.Add(new KeyValuePair<string, string>(property.Key, convertedValue)); fileData = UpdateAssemblyValue(fileData, property.Key, convertedValue, projectType, forceCreate); } // do we need to put a NewLine char in the data from the file if (DoesLastLineContainCr(fileData)) { newFileData.Append(fileData); } else { newFileData.AppendLine(fileData); } // for F#, put the do() binding back in if (projectType == ProjectTypes.Fs) { newFileData.AppendLine("do ()"); } // Write the data out to a file File.WriteAllText(filePath, newFileData.ToString()); // restore the file's original attributes File.SetAttributes(filePath, currentFileAttributes); return convertedValues; }
public void EnableAgent(IBuildAgent agent) { agent.Enabled = true; agent.Save(); }
private void SelectBuildAgent(IBuildAgent agent) { SelectBuildAgents(new List <IBuildAgent> { agent }); }
private static string GetBuildAgentID(IBuildAgent agent) { return(string.Format("{0}-{1}", agent.Controller.Uri.AbsolutePath, agent.Uri.AbsolutePath)); }
public IBuildDetail CreateManualBuild(string buildNumber, string dropLocation, BuildStatus buildStatus, IBuildAgent agent, string requestedFor) { throw new NotImplementedException(); }
/// <summary> /// Executes the logic for this workflow activity /// </summary> protected override void InternalExecute() { // Initialise defaults if (this.UseDefaultCredentials.Expression == null) { this.UseDefaultCredentials.Set(this.ActivityContext, true); } if (this.Format.Expression == null) { this.Format.Set(this.ActivityContext, "Text"); } if (this.Priority.Expression == null) { this.Priority.Set(this.ActivityContext, "Normal"); } this.buildDetail = this.ActivityContext.GetExtension<IBuildDetail>(); this.buildAgent = this.ActivityContext.GetExtension<IBuildAgent>(); string filePath = this.FilePath.Expression == null ? this.buildDetail.DropLocation : this.FilePath.Get(this.ActivityContext); this.reportFile = new FileInfo(Path.Combine(filePath, this.ReportFileName.Get(this.ActivityContext))); this.xmlfile = new FileInfo(Path.Combine(filePath, this.ReportFileName.Get(this.ActivityContext).Replace(".txt", ".xml"))); this.transformedReportFile = new FileInfo(Path.Combine(filePath, this.ReportFileName.Get(this.ActivityContext).Replace(".txt", ".html"))); this.associatedChangesets = this.AssociatedChangesets.Get(this.ActivityContext); switch (this.Action) { case BuildReportAction.Generate: this.GenerateReport(); break; default: throw new ArgumentException("Action not supported"); } }
/// <summary> /// This method will walk through all the patterns in the property value and replace them with actual values /// </summary> /// <param name="propertyValue"></param> /// <param name="buildDetail"></param> /// <param name="buildNumberPrefix"></param> /// <param name="incrementBy"></param> /// <param name="buildNumberSeed"></param> /// <param name="date"></param> /// <returns></returns> public static string ReplacePatternsInPropertyValue(string propertyValue, IBuildDetail buildDetail, int buildNumberPrefix, int incrementBy, int buildNumberSeed, DateTime date, Workspace workspace, IBuildAgent buildAgent) { const string regExFindTokenPattern = @"\$(?<token>\w+)"; const string regExReplaceTokenPattern = @"\${0}"; var modifiedPropertyValue = propertyValue; var regex = new Regex(regExFindTokenPattern); var matches = regex.Matches(propertyValue); foreach (Match match in matches) { string token = match.Value.Remove(0, 1); string convertedValue = ReplacePatternWithValue(token, buildDetail, buildDetail.BuildNumber, buildNumberPrefix, incrementBy, buildNumberSeed, date, workspace, buildAgent); var regExReplace = new Regex(string.Format(regExReplaceTokenPattern, token)); modifiedPropertyValue = regExReplace.Replace(modifiedPropertyValue, convertedValue); } modifiedPropertyValue = modifiedPropertyValue.Replace('\\', ':'); return modifiedPropertyValue; }
private static string GetBuildAgentID(IBuildAgent agent) { return string.Format("{0}-{1}", agent.Controller.Uri.AbsolutePath, agent.Uri.AbsolutePath); }
/// <summary> /// /// </summary> /// <param name="pattern"></param> /// <param name="buildDetail"></param> /// <param name="buildNumber">The full build number - left in for versioning (backward compatibility) reasons</param> /// <param name="buildNumberPrefix"></param> /// <param name="incrementBy"></param> /// <param name="buildNumberSeed"></param> /// <param name="date"></param> /// <returns></returns> public static string ReplacePatternWithValue(string pattern, IBuildDetail buildDetail, string buildNumber, int buildNumberPrefix, int incrementBy, int buildNumberSeed, DateTime date, Workspace workspace, IBuildAgent buildAgent, int changesetMax) { var patternUpper = pattern.ToUpper(); string convertedValue; string internalBuildNumber = buildDetail == null ? buildNumber : buildDetail.BuildNumber; switch (patternUpper) { case "TPROJ": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); convertedValue = buildDetail.TeamProject; break; case "REQBY": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); convertedValue = StripDomain(buildDetail.RequestedBy); break; case "BNAME": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); convertedValue = buildDetail.BuildDefinition.Name; break; case "UTIME": convertedValue = date.ToUniversalTime().ToString(); break; case "LDATE": convertedValue = date.ToLongDateString(); break; case "LTIME": convertedValue = date.ToLongTimeString(); break; case "SDATE": convertedValue = date.ToShortDateString(); break; case "STIME": convertedValue = date.ToShortTimeString(); break; case "BNUM": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); convertedValue = internalBuildNumber; break; case "YYYY": convertedValue = date.ToString("yyyy"); break; case "YY": convertedValue = date.ToString("yy"); break; case "M": case "MM": convertedValue = date.Month.ToString(); break; case "D": case "DD": convertedValue = date.Day.ToString(); break; case "J": convertedValue = string.Format("{0}{1}", date.ToString("yy"), string.Format("{0:000}", date.DayOfYear)); break; case "C": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); if (workspace == null) throw new ArgumentNullException("workspace"); if (buildAgent == null) throw new ArgumentNullException("buildAgent"); var changeset = GetChangeset(buildDetail, workspace, buildAgent); if (changeset != null) { convertedValue = (changeset.ChangesetId % changesetMax).ToString(); } else { convertedValue = "0"; } break; case "CO": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); if (workspace == null) throw new ArgumentNullException("workspace"); if (buildAgent == null) throw new ArgumentNullException("buildAgent"); var overflowChangeset = GetChangeset(buildDetail, workspace, buildAgent); if (overflowChangeset != null) { convertedValue = (overflowChangeset.ChangesetId / changesetMax).ToString(); } else { convertedValue = "0"; } break; case "B": if (incrementBy <= 0) throw new ArgumentException("incrementBy cannot be <= 0.", "incrementBy"); var buildNum = GetBuildNumberValue(internalBuildNumber, buildNumberSeed, buildNumberPrefix); convertedValue = Math.Abs(buildNum * incrementBy).ToString(); break; case "S": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); convertedValue = buildDetail.Reason == BuildReason.ValidateShelveset ? "65535" : "0"; break; case "SN": if (buildDetail == null) throw new ArgumentNullException("buildDetail"); convertedValue = buildDetail.ShelvesetName; break; default: convertedValue = pattern; break; } return convertedValue; }
private static Changeset GetChangeset(IBuildDetail buildDetail, Workspace workspace, IBuildAgent buildAgent) { var workspaceSourcePath = Path.Combine(buildAgent.GetExpandedBuildDirectory(buildDetail.BuildDefinition), "Sources"); var versionSpec = new WorkspaceVersionSpec(workspace); var historyParams = new QueryHistoryParameters(workspaceSourcePath, RecursionType.Full) { ItemVersion = versionSpec, VersionEnd = versionSpec, MaxResults = 1 }; var changeset = workspace.VersionControlServer.QueryHistory(historyParams).FirstOrDefault(); return changeset; }
public void RemoveBuildAgent(IBuildAgent agent) { this.buildServer.DeleteBuildAgents(new[] { agent.Uri }); }