给定TFS构建定义,如何获取任意流程参数的值和类型?
给定构建定义,我从中提取以下内容:给定TFS构建定义,如何获取任意流程参数的值和类型?,tfs,workflow,Tfs,Workflow,给定构建定义,我从中提取以下内容: m_template = (DynamicActivity)WorkflowHelpers.DeserializeWorkflow(buildDefinition.Process.Parameters); Properties = m_template.Properties.ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); Metadata = WorkflowHelpers.Get
m_template = (DynamicActivity)WorkflowHelpers.DeserializeWorkflow(buildDefinition.Process.Parameters);
Properties = m_template.Properties.ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase);
Metadata = WorkflowHelpers.GetCombinedMetadata(m_template).ToDictionary(m => m.ParameterName);
m_parameters = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters)
现在我想知道任意进程参数的值
我目前的代码是:
public ParameterValue GetParameterValue(string name)
{
object propValue;
var valueType = GetParameterType(name, out propValue);
object value;
if (!m_parameters.TryGetValue(name, out value))
{
value = propValue;
}
return new ParameterValue(valueType, value);
}
private Type GetParameterType(string name, out object value)
{
value = null;
if (Properties != null)
{
DynamicActivityProperty property;
if (Properties.TryGetValue(name, out property))
{
var inArgument = property.Value as InArgument;
if (inArgument != null)
{
if (inArgument.Expression != null)
{
var exprString = inArgument.Expression.ToString();
if (!exprString.StartsWith(": VisualBasicValue<"))
{
value = exprString;
}
}
return inArgument.ArgumentType;
}
if (property.Value != null)
{
value = property.Value;
return property.Value.GetType();
}
var typeName = property.Type.ToString();
if (typeName.StartsWith(IN_ARGUMENT_TYPE_NAME_PREFIX))
{
typeName = typeName.Substring(IN_ARGUMENT_TYPE_NAME_PREFIX.Length, typeName.Length - IN_ARGUMENT_TYPE_NAME_PREFIX.Length - 1);
return Type.GetType(typeName, true);
}
return property.Type;
}
}
return typeof(string);
}
public参数值GetParameterValue(字符串名称)
{
客体价值;
var valueType=GetParameterType(名称、输出值);
目标价值;
if(!m_parameters.TryGetValue(名称,输出值))
{
价值=价值;
}
返回新参数值(valueType,value);
}
私有类型GetParameterType(字符串名称,输出对象值)
{
值=空;
如果(属性!=null)
{
动态特性;
if(Properties.TryGetValue(name,out属性))
{
var inArgument=属性。值为inArgument;
if(inagrament!=null)
{
if(inagrament.Expression!=null)
{
var exprString=inagrament.Expression.ToString();
如果(!exprString.StartsWith(“:VisualBasicValue您可以使用以下代码(包含在另一个代码中)获取一个流程参数的值和类型:
TfsTeamProjectCollection tfctc = new TfsTeamProjectCollection(new Uri("http://tfsservername:8080/tfs/DefaultCollection"));
IBuildServer bs = tfctc.GetService<IBuildServer>();
IBuildDetail[] builds = bs.QueryBuilds("teamprojectname", "builddefinitionname");
foreach (var build in builds)
{
var buildefinition = build.BuildDefinition;
IDictionary<String, Object> paramValues = WorkflowHelpers.DeserializeProcessParameters(buildefinition.ProcessParameters);
string processParametersValue = paramValues["argument1"].ToString();
Console.WriteLine(processParametersValue);
}
tfstreamprojectcollection tfctc=新的tfstreamprojectcollection(新Uri(“http://tfsservername:8080/tfs/DefaultCollection"));
IBuildServer bs=tfctc.GetService();
IBuildDetail[]builds=bs.QueryBuilds(“teamprojectname”、“builddefinitionname”);
foreach(var内置版本)
{
var BuildDefinition=build.BuildDefinition;
IDictionary paramValues=WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
string processParametersValue=paramValues[“argument1”].ToString();
Console.WriteLine(processParametersValue);
}
另外,请检查此案例: