From 9f93503c8605daad611fa560a04c54de97d02f12 Mon Sep 17 00:00:00 2001 From: Serge Baltic Date: Thu, 31 Jan 2013 03:52:06 +0400 Subject: [PATCH] Add two bulk-operation methods new to 8.0: DeleteAllBuildTypeParameters, PutAllBuildTypeParameters. Bulk operations give major speedup in mass update of buildtypes. --- src/TeamCitySharp/ActionTypes/BuildConfigs.cs | 34 ++++++++++++++++++- .../ActionTypes/IBuildConfigs.cs | 15 ++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/TeamCitySharp/ActionTypes/BuildConfigs.cs b/src/TeamCitySharp/ActionTypes/BuildConfigs.cs index f0859621..37827f4e 100644 --- a/src/TeamCitySharp/ActionTypes/BuildConfigs.cs +++ b/src/TeamCitySharp/ActionTypes/BuildConfigs.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Mime; using System.Xml; using EasyHttp.Http; using TeamCitySharp.Connection; @@ -112,6 +115,35 @@ public void DeleteConfiguration(BuildTypeLocator locator) _caller.DeleteFormat("/app/rest/buildTypes/{0}", locator); } + public void DeleteAllBuildTypeParameters(BuildTypeLocator locator) + { + _caller.DeleteFormat("/app/rest/buildTypes/{0}/parameters", locator); + } + + public void PutAllBuildTypeParameters(BuildTypeLocator locator, IDictionary parameters) + { + if(locator == null) + throw new ArgumentNullException("locator"); + if(parameters == null) + throw new ArgumentNullException("parameters"); + + StringWriter sw = new StringWriter(); + using(XmlTextWriter writer = new XmlTextWriter(sw)) + { + writer.WriteStartElement("properties"); + foreach(var parameter in parameters) + { + writer.WriteStartElement("property"); + writer.WriteAttributeString("name", parameter.Key); + writer.WriteAttributeString("value", parameter.Value); + writer.WriteEndElement(); + } + writer.WriteEndElement(); + } + + _caller.PutFormat(sw.ToString(), HttpContentTypes.ApplicationXml, "/app/rest/buildTypes/{0}/parameters", locator); + } + public void PostRawAgentRequirement(BuildTypeLocator locator, string rawXml) { _caller.PostFormat(rawXml, HttpContentTypes.ApplicationXml, "/app/rest/buildTypes/{0}/agent-requirements", locator); diff --git a/src/TeamCitySharp/ActionTypes/IBuildConfigs.cs b/src/TeamCitySharp/ActionTypes/IBuildConfigs.cs index fc98ada6..32fe21e2 100644 --- a/src/TeamCitySharp/ActionTypes/IBuildConfigs.cs +++ b/src/TeamCitySharp/ActionTypes/IBuildConfigs.cs @@ -69,5 +69,20 @@ public interface IBuildConfigs BuildConfig BuildType(BuildTypeLocator locator); void DeleteConfiguration(BuildTypeLocator locator); + + /// + /// Deletes all of the parameters defined locally on this build type. + /// This spares those parameters inherited from the template, you will still get them when listing all parameters. + /// + /// 8.0 + void DeleteAllBuildTypeParameters(BuildTypeLocator locator); + + /// + /// Replaces all of the parameters defined locally on this build type with the new set supplied. + /// Same as calling and then for each entry. + /// + /// 8.0 + void PutAllBuildTypeParameters(BuildTypeLocator locator, IDictionary parameters); + } } \ No newline at end of file